⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lib.xweb

📁 jboss规则引擎
💻 XWEB
📖 第 1 页 / 共 3 页
字号:
<refname>pi-attribute</refname><refpurpose>Extract a pseudo-attribute from a PI</refpurpose></refnamediv><refsect1><title>Description</title><para>The <function>pi-attribute</function> template extracts a pseudo-attributefrom a processing instruction. For example, given the PI<quote><literal>&lt;?foo bar="1" baz='red'?&gt;</literal></quote>,</para><programlisting><![CDATA[<xsl:call-template name="pi-attribute">  <xsl:with-param name="pis" select="processing-instruction('foo')"/>  <xsl:with-param name="attribute" select="'baz'"/></xsl:call-template>]]></programlisting><para>will return <quote>red</quote>. This template returns the first matchingattribute that it finds. Presented with processing instructions thatcontain badly formed pseudo-attributes (missing or unbalanced quotes,for example), the template may silently return erroneous results.</para><programlisting><src:fragment id='pi-attribute.frag'><xsl:template name="pi-attribute">  <xsl:param name="pis" select="processing-instruction('BOGUS_PI')"/>  <xsl:param name="attribute">filename</xsl:param>  <xsl:param name="count">1</xsl:param>  <xsl:choose>    <xsl:when test="$count>count($pis)">      <!-- not found -->    </xsl:when>    <xsl:otherwise>      <xsl:variable name="pi">        <xsl:value-of select="$pis[$count]"/>      </xsl:variable>      <xsl:variable name="pivalue">        <xsl:value-of select="concat(' ', normalize-space($pi))"/>      </xsl:variable>      <xsl:choose>        <xsl:when test="contains($pivalue,concat(' ', $attribute, '='))">          <xsl:variable name="rest" select="substring-after($pivalue,concat(' ', $attribute,'='))"/>          <xsl:variable name="quote" select="substring($rest,1,1)"/>          <xsl:value-of select="substring-before(substring($rest,2),$quote)"/>        </xsl:when>        <xsl:otherwise>          <xsl:call-template name="pi-attribute">            <xsl:with-param name="pis" select="$pis"/>            <xsl:with-param name="attribute" select="$attribute"/>            <xsl:with-param name="count" select="$count + 1"/>          </xsl:call-template>        </xsl:otherwise>      </xsl:choose>    </xsl:otherwise>  </xsl:choose></xsl:template></src:fragment></programlisting></refsect1></refentry><!-- ================================================================== --><refentry id="lookup.key"><refnamediv><refname>lookup.key</refname><refpurpose>Retrieve the value associated with a particular key in a table</refpurpose></refnamediv><refsect1><title>Description</title><para>Given a table of space-delimited key/value pairs,the <function>lookup.key</function> template extracts the value associatedwith a particular key.</para><programlisting><src:fragment id='lookup.key.frag'><xsl:template name="lookup.key">  <xsl:param name="key" select="''"/>  <xsl:param name="table" select="''"/>  <xsl:if test="contains($table, ' ')">    <xsl:choose>      <xsl:when test="substring-before($table, ' ') = $key">        <xsl:variable name="rest" select="substring-after($table, ' ')"/>        <xsl:choose>          <xsl:when test="contains($rest, ' ')">            <xsl:value-of select="substring-before($rest, ' ')"/>          </xsl:when>          <xsl:otherwise>            <xsl:value-of select="$rest"/>          </xsl:otherwise>        </xsl:choose>      </xsl:when>      <xsl:otherwise>        <xsl:call-template name="lookup.key">          <xsl:with-param name="key" select="$key"/>          <xsl:with-param name="table"                            select="substring-after(substring-after($table,' '), ' ')"/>        </xsl:call-template>      </xsl:otherwise>    </xsl:choose>  </xsl:if></xsl:template></src:fragment></programlisting></refsect1></refentry><!-- ================================================================== --><refentry id="xpath.location"><refnamediv><refname>xpath.location</refname><refpurpose>Calculate the XPath child-sequence to the current node</refpurpose></refnamediv><refsect1><title>Description</title><para>The <function>xpath.location</function> template calculates theabsolute path from the root of the tree to the current element node.</para><programlisting><src:fragment id='xpath.location.frag'><xsl:template name="xpath.location">  <xsl:param name="node" select="."/>  <xsl:param name="path" select="''"/>  <xsl:variable name="next.path">    <xsl:value-of select="local-name($node)"/>    <xsl:if test="$path != ''">/</xsl:if>    <xsl:value-of select="$path"/>  </xsl:variable>  <xsl:choose>    <xsl:when test="$node/parent::*">      <xsl:call-template name="xpath.location">        <xsl:with-param name="node" select="$node/parent::*"/>        <xsl:with-param name="path" select="$next.path"/>      </xsl:call-template>    </xsl:when>    <xsl:otherwise>      <xsl:text>/</xsl:text>      <xsl:value-of select="$next.path"/>    </xsl:otherwise>  </xsl:choose></xsl:template></src:fragment></programlisting></refsect1></refentry><!-- ================================================================== --><refentry id="comment-escape-string"><refnamediv><refname>comment-escape-string</refname><refpurpose>Prepare a string for inclusion in an XML comment</refpurpose></refnamediv><refsect1><title>Description</title><para>The <function>comment-escape-string</function> template returns a stringthat has been transformed so that it can safely be output as an XML comment.Internal occurrences of "--" will be replaced with "- -" and a leading and/ortrailing space will be added to the string, if necessary.</para><programlisting><src:fragment id='comment-escape-string'><xsl:template name="comment-escape-string">  <xsl:param name="string" select="''"/>  <xsl:if test="starts-with($string, '-')">    <xsl:text> </xsl:text>  </xsl:if>  <xsl:call-template name="comment-escape-string.recursive">    <xsl:with-param name="string" select="$string"/>  </xsl:call-template>  <xsl:if test="substring($string, string-length($string), 1) = '-'">    <xsl:text> </xsl:text>  </xsl:if></xsl:template></src:fragment></programlisting></refsect1></refentry><!-- ================================================================== --><refentry id="comment-escape-string.recursive"><refnamediv><refname>comment-escape-string.recursive</refname><refpurpose>Internal function used by comment-escape-string</refpurpose></refnamediv><refsect1><title>Description</title><para>The <function>comment-escape-string.recursive</function> template is usedby <function>comment-escape-string</function>.</para><programlisting><src:fragment id="comment-escape-string.recursive"><xsl:template name="comment-escape-string.recursive">  <xsl:param name="string" select="''"/>  <xsl:choose>    <xsl:when test="contains($string, '--')">      <xsl:value-of select="substring-before($string, '--')"/>      <xsl:value-of select="'- -'"/>      <xsl:call-template name="comment-escape-string.recursive">        <xsl:with-param name="string" select="substring-after($string, '--')"/>      </xsl:call-template>    </xsl:when>    <xsl:otherwise>      <xsl:value-of select="$string"/>    </xsl:otherwise>  </xsl:choose></xsl:template></src:fragment></programlisting></refsect1></refentry><!-- ================================================================== --><refentry id="prepend-pad"><refnamediv><refname>prepend-pad</refname><refpurpose>Right-pad a string out to a certain length</refpurpose></refnamediv><refsect1><title>Description</title><para>This function takes string <parameter>padVar</parameter> andpads it out to the string-length <parameter>length</parameter>, usingstring <parameter>padChar</parameter> (a space character by default)as the padding string (note that <parameter>padChar</parameter> can bea string; it is not limited to just being a single character).</para>  <note>    <para>This function is a copy of Nate Austin's    <function>prepend-pad</function> function in the <ulink    url="http://www.dpawson.co.uk/xsl/sect2/padding.html" >Padding    Content</ulink> section of Dave Pawson's <ulink    url="http://www.dpawson.co.uk/xsl/index.html" >XSLT    FAQ</ulink>.</para>  </note><programlisting><src:fragment id='prepend-pad.frag'>  <xsl:template name="prepend-pad">      <!-- recursive template to right justify and prepend-->  <!-- the value with whatever padChar is passed in   -->    <xsl:param name="padChar" select="' '"/>    <xsl:param name="padVar"/>    <xsl:param name="length"/>    <xsl:choose>      <xsl:when test="string-length($padVar) &lt; $length">        <xsl:call-template name="prepend-pad">          <xsl:with-param name="padChar" select="$padChar"/>          <xsl:with-param name="padVar" select="concat($padChar,$padVar)"/>          <xsl:with-param name="length" select="$length"/>        </xsl:call-template>      </xsl:when>      <xsl:otherwise>        <xsl:value-of 	  select="substring($padVar,string-length($padVar) - $length + 1)"/>      </xsl:otherwise>    </xsl:choose>  </xsl:template></src:fragment></programlisting></refsect1></refentry><!-- ================================================================== --><refentry id="trim.text"><refnamediv><refname>trim.text</refname><refpurpose>Trim leading and trailing whitespace from a text node</refpurpose></refnamediv><refsect1><title>Description</title><para>Given a text node, this function trims leading and trailingwhitespace from it and returns the trimmed contents.</para><programlisting><src:fragment id='trim.text.frag'>  <xsl:template name="trim.text">    <xsl:param name="contents" select="."/>    <xsl:variable name="contents-left-trimmed">      <xsl:call-template name="trim-left">        <xsl:with-param name="contents" select="$contents"/>      </xsl:call-template>    </xsl:variable>    <xsl:variable name="contents-trimmed">      <xsl:call-template name="trim-right">        <xsl:with-param name="contents" select="$contents-left-trimmed"/>      </xsl:call-template>    </xsl:variable>    <xsl:value-of select="$contents-trimmed"/>  </xsl:template>  <xsl:template name="trim-left">    <xsl:param name="contents"/>    <xsl:choose>      <xsl:when test="starts-with($contents,'&#xA;') or                      starts-with($contents,'&#xA;') or                      starts-with($contents,'&#x20;') or                      starts-with($contents,'&#x9;')">        <xsl:call-template name="trim-left">          <xsl:with-param name="contents" select="substring($contents, 2)"/>        </xsl:call-template>      </xsl:when>      <xsl:otherwise>        <xsl:value-of select="$contents"/>      </xsl:otherwise>    </xsl:choose>  </xsl:template>  <xsl:template name="trim-right">    <xsl:param name="contents"/>    <xsl:variable name="last-char">      <xsl:value-of select="substring($contents, string-length($contents), 1)"/>    </xsl:variable>    <xsl:choose>      <xsl:when test="($last-char = '&#xA;') or                      ($last-char = '&#xD;') or                      ($last-char = '&#x20;') or                      ($last-char = '&#x9;')">        <xsl:call-template name="trim-right">          <xsl:with-param name="contents"                          select="substring($contents, 1, string-length($contents) - 1)"/>        </xsl:call-template>      </xsl:when>      <xsl:otherwise>        <xsl:value-of select="$contents"/>      </xsl:otherwise>    </xsl:choose>  </xsl:template></src:fragment></programlisting></refsect1></refentry><!-- ================================================================== --><refentry id="str.tokenize.keep.delimiters"><refnamediv><refname>str.tokenize.keep.delimiters</refname><refpurpose>Tokenize a string while preserving any delimiters</refpurpose></refnamediv><refsect1><title>Description</title><para>Based on the occurrence of one or more delimiter characters,this function breaks a string into a list of tokens and delimiters,marking up each of the tokens with a <sgmltag>token</sgmltag> elementand preserving the delimiters as text nodes between the tokens.</para><note>  <para>This function is a very slightly modified version of a  function from the <ulink url="http://www.exslt.org/">EXSLT  site</ulink>. The original is available at:  <blockquote><para><ulink url="http://www.exslt.org/str/functions/tokenize/str.tokenize.template.xsl"/></para></blockquote>  The <function>str.tokenize.keep.delimiters</function> function  differs only in that it preserves the delimiters instead of  discarding them.</para></note><programlisting><src:fragment id='str.tokenize.keep.delimiters.frag'>  <xsl:template name="str.tokenize.keep.delimiters">    <xsl:param name="string" select="''" />    <xsl:param name="delimiters" select="' '" />    <xsl:choose>      <xsl:when test="not($string)" />      <xsl:when test="not($delimiters)">	<xsl:call-template name="str.tokenize.keep.delimiters-characters">	  <xsl:with-param name="string" select="$string" />	</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="$delimiters" />	</xsl:call-template>      </xsl:otherwise>    </xsl:choose>  </xsl:template>    <xsl:template name="str.tokenize.keep.delimiters-characters">    <xsl:param name="string" />    <xsl:if test="$string">      <token><xsl:value-of select="substring($string, 1, 1)" /></token>      <xsl:call-template name="str.tokenize.keep.delimiters-characters">	<xsl:with-param name="string" select="substring($string, 2)" />      </xsl:call-template>    </xsl:if>  </xsl:template>    <xsl:template name="str.tokenize.keep.delimiters-delimiters">    <xsl:param name="string" />    <xsl:param name="delimiters" />    <xsl:variable name="delimiter" select="substring($delimiters, 1, 1)" />    <xsl:choose>      <xsl:when test="not($delimiter)">	<token><xsl:value-of select="$string" /></token>      </xsl:when>      <xsl:when test="contains($string, $delimiter)">	<xsl:if test="not(starts-with($string, $delimiter))">	  <xsl:call-template name="str.tokenize.keep.delimiters-delimiters">	    <xsl:with-param name="string" select="substring-before($string, $delimiter)" />	    <xsl:with-param name="delimiters" select="substring($delimiters, 2)" />	  </xsl:call-template>	</xsl:if>	<!-- output each delimiter -->	<xsl:value-of select="$delimiter"/>	<xsl:call-template name="str.tokenize.keep.delimiters-delimiters">	  <xsl:with-param name="string" select="substring-after($string, $delimiter)" />

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -