📄 lib.xweb
字号:
<xsl:with-param name="delimiters" select="$delimiters" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:call-template name="str.tokenize.keep.delimiters-delimiters"> <xsl:with-param name="string" select="$string" /> <xsl:with-param name="delimiters" select="substring($delimiters, 2)" /> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template></src:fragment></programlisting></refsect1></refentry><!-- ================================================================== --><refentry id="apply-string-subst-map"> <refnamediv> <refname>apply-string-subst-map</refname> <refpurpose>Apply a string-substitution map</refpurpose> </refnamediv> <refsect1><title>Description</title> <para>This function applies a "string substitution" map. Use it when you want to do multiple string substitutions on the same target content. It reads in two things: <parameter>content</parameter>, the content on which to perform the substitution, and <parameter>map.contents</parameter>, a node set of elements (the names of the elements don't matter), with each element having the following attributes: <itemizedlist> <listitem> <simpara><tag class="attribute">oldstring</tag>, a string to be replaced</simpara> </listitem> <listitem> <simpara><tag class="attribute">newstring</tag>, a string with which to replace <tag class="attribute">oldstring</tag></simpara> </listitem> </itemizedlist> The function uses <parameter>map.contents</parameter> to do substitution on <parameter>content</parameter>, and then returns the modified contents.</para> <note> <para>This function is a very slightly modified version of Jeni Tennison's <function>replace_strings</function> function in the <ulink url="http://www.dpawson.co.uk/xsl/sect2/StringReplace.html#d9351e13" >multiple string replacements</ulink> section of Dave Pawson's <ulink url="http://www.dpawson.co.uk/xsl/index.html" >XSLT FAQ</ulink>.</para> <para>The <function>apply-string-subst-map</function> function is essentially the same function as the <function>apply-character-map</function> function; the only difference is that in the map that <function>apply-string-subst-map</function> expects, <tag class="attribute">oldstring</tag> and <tag class="attribute">newstring</tag> attributes are used instead of <tag class="attribute">character</tag> and <tag class="attribute">string</tag> attributes.</para> </note> <programlisting><src:fragment id='apply-string-subst-map.frag'> <xsl:template name="apply-string-subst-map"> <xsl:param name="content"/> <xsl:param name="map.contents"/> <xsl:variable name="replaced_text"> <xsl:call-template name="string.subst"> <xsl:with-param name="string" select="$content" /> <xsl:with-param name="target" select="$map.contents[1]/@oldstring" /> <xsl:with-param name="replacement" select="$map.contents[1]/@newstring" /> </xsl:call-template> </xsl:variable> <xsl:choose> <xsl:when test="$map.contents[2]"> <xsl:call-template name="apply-string-subst-map"> <xsl:with-param name="content" select="$replaced_text" /> <xsl:with-param name="map.contents" select="$map.contents[position() > 1]" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$replaced_text" /> </xsl:otherwise> </xsl:choose> </xsl:template> </src:fragment></programlisting> </refsect1></refentry><!-- ================================================================== --><refentry id="apply-character-map"> <refnamediv> <refname>apply-character-map</refname> <refpurpose>Apply an XSLT character map</refpurpose> </refnamediv> <refsect1><title>Description</title> <para>This function applies an <ulink url="http://www.w3.org/TR/xslt20/#character-maps">XSLT character map</ulink>; that is, it cause certain individual characters to be substituted with strings of one or more characters. It is useful mainly for replacing multiple "special" chararacters or symbols in the same target content. It reads in two things: <parameter>content</parameter>, the content on which to perform the substitution, and <parameter>map.contents</parameter>, a node set of elements (the names of the elements don't matter), with each element having the following attributes: <itemizedlist> <listitem> <simpara><tag class="attribute">character</tag>, a character to be replaced</simpara> </listitem> <listitem> <simpara><tag class="attribute">string</tag>, a string with which to replace <tag class="attribute">character</tag></simpara> </listitem> </itemizedlist> This function uses <parameter>map.contents</parameter> to do substitution on <parameter>content</parameter>, and then returns the modified contents.</para> <note> <para>This function is a very slightly modified version of Jeni Tennison's <function>replace_strings</function> function in the <ulink url="http://www.dpawson.co.uk/xsl/sect2/StringReplace.html#d9351e13" >multiple string replacements</ulink> section of Dave Pawson's <ulink url="http://www.dpawson.co.uk/xsl/index.html" >XSLT FAQ</ulink>.</para> <para>The <function>apply-string-subst-map</function> function is essentially the same function as the <function>apply-character-map</function> function; the only difference is that in the map that <function>apply-string-subst-map</function> expects, <tag class="attribute">oldstring</tag> and <tag class="attribute">newstring</tag> attributes are used instead of <tag class="attribute">character</tag> and <tag class="attribute">string</tag> attributes.</para> </note> <programlisting><src:fragment id='apply-character-map.frag'> <xsl:template name="apply-character-map"> <xsl:param name="content"/> <xsl:param name="map.contents"/> <xsl:variable name="replaced_text"> <xsl:call-template name="string.subst"> <xsl:with-param name="string" select="$content" /> <xsl:with-param name="target" select="$map.contents[1]/@character" /> <xsl:with-param name="replacement" select="$map.contents[1]/@string" /> </xsl:call-template> </xsl:variable> <xsl:choose> <xsl:when test="$map.contents[2]"> <xsl:call-template name="apply-character-map"> <xsl:with-param name="content" select="$replaced_text" /> <xsl:with-param name="map.contents" select="$map.contents[position() > 1]" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$replaced_text" /> </xsl:otherwise> </xsl:choose> </xsl:template> </src:fragment></programlisting> </refsect1></refentry><!-- ================================================================== --><refentry id="read-character-map"><refnamediv><refname>read-character-map</refname><refpurpose>Read in all or part of an XSLT character map</refpurpose></refnamediv><refsect1><title>Description</title><para>The XSLT 2.0 specification describes <ulinkurl="http://www.w3.org/TR/xslt20/#character-maps">charactermaps</ulink> and explains how they may be used to allow a specificcharacter appearing in a text or attribute node in a final resultstree to be substituted by a specified string of characters duringserialization. The <function>read-character-map</function> functionprovides a means for reading and using character maps with XSLT1.0-based tools.</para><para>It reads the character-map contents from<parameter>uri</parameter> (in full or in part, depending on the valueof the <parameter>use.subset</parameter> parameter), then passes thosecontents to the <function>apply-character-map</function> function,along with <parameter>content</parameter>, the data on which toperform the character substition.</para><para>Using the character map "in part" means that it uses only those<tag>output-character</tag> elements that match the XPATH expressiongiven in the value of the <parameter>subset.profile</parameter>parameter. The current implementation of that capability here relieson the <function>evaluate</function> extension XSLT function.</para><programlisting><src:fragment id='read-character-map.frag'> <xsl:template name="read-character-map"> <xsl:param name="use.subset"/> <xsl:param name="subset.profile"/> <xsl:param name="uri"/> <xsl:choose> <xsl:when test="$use.subset != 0"> <!-- use a subset of the character map instead of the full map --> <xsl:choose> <!-- xsltproc and Xalan both support dyn:evaluate() --> <xsl:when test="function-available('dyn:evaluate')"> <xsl:copy-of select="document($uri)//*[local-name()='output-character'] [dyn:evaluate($subset.profile)]"/> </xsl:when> <!-- Saxon has its own evaluate() & doesn't support dyn:evaluate() --> <xsl:when test="function-available('saxon:evaluate')"> <xsl:copy-of select="document($uri)//*[local-name()='output-character'] [saxon:evaluate($subset.profile)]"/> </xsl:when> <xsl:otherwise> <xsl:message terminate="yes">Error: To process character-map subsets, you must use an XSLT enginethat supports the evaluate() XSLT extension function. Your XSLT enginedoes not support it.</xsl:message> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <!-- value of $use.subset is non-zero, so use the full map --> <xsl:copy-of select="document($uri)//*[local-name()='output-character']"/> </xsl:otherwise> </xsl:choose> </xsl:template></src:fragment></programlisting></refsect1></refentry></reference><!-- ================================================================== --><reference><title>Relative URI Functions</title><partintro><title>Introduction</title><para>These functions manipulate relative URI references.</para><para>The following assumptions must hold true:</para><orderedlist><listitem><para>All URIs are relative.</para></listitem><listitem><para>No URI contains the <quote><literal>../</literal></quote> sequencewhich would effectively move <quote>up</quote> the hierarchy.</para></listitem></orderedlist><para>If these assumptions do not hold, the results are unpredictable.</para></partintro><!-- ================================================================== --><refentry id="count.uri.path.depth"><refnamediv><refname>count.uri.path.depth</refname><refpurpose>Count the number of path components in a relative URI</refpurpose></refnamediv><refsect1><title>Description</title><para>This function counts the number of path components in a relative URI.</para><programlisting><src:fragment id='count.uri.path.depth.frag'><xsl:template name="count.uri.path.depth"> <xsl:param name="filename" select="''"/> <xsl:param name="count" select="0"/> <xsl:choose> <xsl:when test="contains($filename, '/')"> <xsl:call-template name="count.uri.path.depth"> <xsl:with-param name="filename" select="substring-after($filename, '/')"/> <xsl:with-param name="count" select="$count + 1"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$count"/> </xsl:otherwise> </xsl:choose></xsl:template></src:fragment></programlisting></refsect1></refentry><!-- ================================================================== --><refentry id="trim.common.uri.paths"><refnamediv><refname>trim.common.uri.paths</refname><refpurpose>Trim common leading path components from a relative URI</refpurpose></refnamediv><refsect1><title>Description</title><para>This function trims common leading path components from a relative URI.</para><programlisting><src:fragment id='trim.common.uri.paths.frag'><xsl:template name="trim.common.uri.paths"> <xsl:param name="uriA" select="''"/> <xsl:param name="uriB" select="''"/> <xsl:param name="return" select="'A'"/> <xsl:choose> <xsl:when test="contains($uriA, '/') and contains($uriB, '/') and substring-before($uriA, '/') = substring-before($uriB, '/')"> <xsl:call-template name="trim.common.uri.paths"> <xsl:with-param name="uriA" select="substring-after($uriA, '/')"/> <xsl:with-param name="uriB" select="substring-after($uriB, '/')"/> <xsl:with-param name="return" select="$return"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:choose> <xsl:when test="$return = 'A'"> <xsl:value-of select="$uriA"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$uriB"/> </xsl:otherwise> </xsl:choose> </xsl:otherwise> </xsl:choose></xsl:template></src:fragment></programlisting></refsect1></refentry></reference><!-- ================================================================== --><appendix><title>The Stylesheet</title><para>The <filename>lib.xsl</filename> stylesheet is just a wrapperaround these functions.</para><src:fragment id="top" mundane-result-prefixes="xsl"><!-- ******************************************************************** $Id: lib.xweb 5338 2005-10-24 06:39:31Z xmldoc $ ******************************************************************** This file is part of the XSL DocBook Stylesheet distribution. See ../README or http://nwalsh.com/docbook/xsl/ for copyright and other information. This module implements DTD-independent functions ******************************************************************** --><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:src="http://nwalsh.com/xmlns/litprog/fragment" exclude-result-prefixes="src" version='1.0'><src:fragref linkend="dot.count.frag"/><src:fragref linkend="copy-string.frag"/><src:fragref linkend="string.subst.frag"/><src:fragref linkend="xpointer.idref.frag"/><src:fragref linkend="length-magnitude.frag"/><src:fragref linkend="length-units.frag"/><src:fragref linkend="length-spec.frag"/><src:fragref linkend="length-in-points.frag"/><src:fragref linkend="pi-attribute.frag"/><src:fragref linkend="lookup.key.frag"/><src:fragref linkend="xpath.location.frag"/><src:fragref linkend="comment-escape-string"/><src:fragref linkend="comment-escape-string.recursive"/><src:fragref linkend="prepend-pad.frag"/><src:fragref linkend="str.tokenize.keep.delimiters.frag"/><src:fragref linkend="apply-string-subst-map.frag"/><src:fragref linkend="apply-character-map.frag"/><src:fragref linkend="read-character-map.frag"/><src:fragref linkend="count.uri.path.depth.frag"/><src:fragref linkend="trim.common.uri.paths.frag"/><src:fragref linkend="trim.text.frag"/></xsl:stylesheet></src:fragment></appendix></book>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -