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

📄 lib.xweb

📁 数据仓库工具
💻 XWEB
📖 第 1 页 / 共 2 页
字号:
<book xmlns:src="http://nwalsh.com/xmlns/litprog/fragment"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<bookinfo>
<title>XSL Library Template Reference</title>
<releaseinfo role="cvs">$Id: lib.xweb,v 1.1 2003/05/22 13:35:05 sinisa Exp $
</releaseinfo>
<corpauthor>DocBook Open Repository Team</corpauthor>
<copyright>
  <year>1999</year>
  <year>2000</year>
  <year>2001</year>
  <year>2002</year>
  <holder>Norman Walsh</holder>
</copyright>
</bookinfo>

<preface><title>Introduction</title>

<para>This is technical reference documentation for the DocBook XSL
Stylesheets; it documents (some of) the parameters, templates, and
other elements of the stylesheets.</para>

<para>This is not intended to be <quote>user</quote> documentation.
It is provided for developers writing customization layers for the
stylesheets, and for anyone who's interested in <quote>how it
works</quote>.</para>

<para>Although I am trying to be thorough, this documentation is known
to be incomplete. Don't forget to read the source, too :-)</para>

</preface>

<reference>
<title>General Library Templates</title>

<refentry id="dot.count">
<refnamediv>
<refname>dot.count</refname>
<refpurpose>Returns the number of <quote>.</quote> characters in a string</refpurpose>
</refnamediv>

<refsect1><title>Description</title>

<programlisting><src:fragment id='dot.count.frag'>
<xsl:template name="dot.count">
  <!-- Returns the number of "." characters in a string -->
  <xsl:param name="string"></xsl:param>
  <xsl:param name="count" select="0"/>
  <xsl:choose>
    <xsl:when test="contains($string, '.')">
      <xsl:call-template name="dot.count">
        <xsl:with-param name="string" select="substring-after($string, '.')"/>
        <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="copy-string">
<refnamediv>
<refname>copy-string</refname>
<refpurpose>Returns <quote>count</quote> copies of a string</refpurpose>
</refnamediv>

<refsect1><title>Description</title>

<programlisting><src:fragment id='copy-string.frag'>
<xsl:template name="copy-string">
  <!-- returns 'count' copies of 'string' -->
  <xsl:param name="string"></xsl:param>
  <xsl:param name="count" select="0"/>
  <xsl:param name="result"></xsl:param>

  <xsl:choose>
    <xsl:when test="$count>0">
      <xsl:call-template name="copy-string">
        <xsl:with-param name="string" select="$string"/>
        <xsl:with-param name="count" select="$count - 1"/>
        <xsl:with-param name="result">
          <xsl:value-of select="$result"/>
          <xsl:value-of select="$string"/>
        </xsl:with-param>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$result"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>
</src:fragment></programlisting>

</refsect1>
</refentry>

<!-- ====================================================================== -->

<refentry id="string.subst">
<refnamediv>
<refname>string.subst</refname>
<refpurpose>Substitute one text string for another in a string</refpurpose>
</refnamediv>

<refsect1><title>Description</title>

<para>The <function>string.subst</function> template replaces all
occurances of <parameter>target</parameter> in <parameter>string</parameter>
with <parameter>replacement</parameter> and returns the result.
</para>

<programlisting><src:fragment id='string.subst.frag'>
<xsl:template name="string.subst">
  <xsl:param name="string"></xsl:param>
  <xsl:param name="target"></xsl:param>
  <xsl:param name="replacement"></xsl:param>

  <xsl:choose>
    <xsl:when test="contains($string, $target)">
      <xsl:variable name="rest">
        <xsl:call-template name="string.subst">
          <xsl:with-param name="string"
                          select="substring-after($string, $target)"/>
          <xsl:with-param name="target" select="$target"/>
          <xsl:with-param name="replacement" select="$replacement"/>
        </xsl:call-template>
      </xsl:variable>
      <xsl:value-of select="concat(substring-before($string, $target),
                                   $replacement,
                                   $rest)"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$string"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>
</src:fragment></programlisting>

</refsect1>
</refentry>

<!-- ================================================================== -->

<refentry id="xpointer.idref">
<refnamediv>
<refname>xpointer.idref</refname>
<refpurpose>Extract IDREF from an XPointer</refpurpose>
</refnamediv>

<refsect1><title>Description</title>

<para>The <function>xpointer.idref</function> template returns the
ID portion of an XPointer which is a pointer to an ID within the current
document, or the empty string if it is not.</para>
<para>In other words, <function>xpointer.idref</function> returns
<quote>foo</quote> when passed either <literal>#foo</literal>
or <literal>#xpointer(id('foo'))</literal>, otherwise it returns
the empty string.</para>

<programlisting><src:fragment id='xpointer.idref.frag'>
<xsl:template name="xpointer.idref">
  <xsl:param name="xpointer">http://...</xsl:param>
  <xsl:choose>
    <xsl:when test="starts-with($xpointer, '#xpointer(id(')">
      <xsl:variable name="rest" select="substring-after($xpointer, '#xpointer(id(')"/>
      <xsl:variable name="quote" select="substring($rest, 1, 1)"/>
      <xsl:value-of select="substring-before(substring-after($xpointer, $quote), $quote)"/>
    </xsl:when>
    <xsl:when test="starts-with($xpointer, '#')">
      <xsl:value-of select="substring-after($xpointer, '#')"/>
    </xsl:when>
    <!-- otherwise it's a pointer to some other document -->
  </xsl:choose>
</xsl:template>
</src:fragment></programlisting>

</refsect1>
</refentry>


<!-- ================================================================== -->

<refentry id="length-magnitude">
<refnamediv>
<refname>length-magnitude</refname>
<refpurpose>Return the unqualified dimension from a length specification</refpurpose>
</refnamediv>

<refsect1><title>Description</title>

<para>The <function>length-magnitude</function> template returns the
unqualified length ("20" for "20pt") from a dimension.
</para>

<programlisting><src:fragment id='length-magnitude.frag'>
<xsl:template name="length-magnitude">
  <xsl:param name="length" select="'0pt'"/>

  <xsl:choose>
    <xsl:when test="string-length($length) = 0"/>
    <xsl:when test="substring($length,1,1) = '0'
                    or substring($length,1,1) = '1'
                    or substring($length,1,1) = '2'
                    or substring($length,1,1) = '3'
                    or substring($length,1,1) = '4'
                    or substring($length,1,1) = '5'
                    or substring($length,1,1) = '6'
                    or substring($length,1,1) = '7'
                    or substring($length,1,1) = '8'
                    or substring($length,1,1) = '9'
                    or substring($length,1,1) = '.'">
      <xsl:value-of select="substring($length,1,1)"/>
      <xsl:call-template name="length-magnitude">
        <xsl:with-param name="length" select="substring($length,2)"/>
      </xsl:call-template>
    </xsl:when>
  </xsl:choose>
</xsl:template>
</src:fragment></programlisting>

</refsect1>
</refentry>

<!-- ================================================================== -->

<refentry id="length-units">
<refnamediv>
<refname>length-units</refname>
<refpurpose>Return the units from a length specification</refpurpose>
</refnamediv>

<refsect1><title>Description</title>

<para>The <function>length-units</function> template returns the
units ("pt" for "20pt") from a length. If no units are supplied on the
length, the <parameter>defauilt.units</parameter> are returned.</para>

<programlisting><src:fragment id='length-units.frag'>
<xsl:template name="length-units">
  <xsl:param name="length" select="'0pt'"/>
  <xsl:param name="default.units" select="'px'"/>
  <xsl:variable name="magnitude">
    <xsl:call-template name="length-magnitude">
      <xsl:with-param name="length" select="$length"/>
    </xsl:call-template>
  </xsl:variable>

  <xsl:variable name="units">
    <xsl:value-of select="substring($length, string-length($magnitude)+1)"/>
  </xsl:variable>

  <xsl:choose>
    <xsl:when test="$units = ''">
      <xsl:value-of select="$default.units"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$units"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>
</src:fragment></programlisting>

</refsect1>
</refentry>

<!-- ================================================================== -->

<refentry id="length-spec">
<refnamediv>
<refname>length-spec</refname>
<refpurpose>Return a fully qualified length specification</refpurpose>
</refnamediv>

<refsect1><title>Description</title>

<para>The <function>length-spec</function> template returns the
qualified length from a dimension. If an unqualified length is given,
the <parameter>default.units</parameter> will be added to it.
</para>

<programlisting><src:fragment id='length-spec.frag'>
<xsl:template name="length-spec">
  <xsl:param name="length" select="'0pt'"/>
  <xsl:param name="default.units" select="'px'"/>

  <xsl:variable name="magnitude">
    <xsl:call-template name="length-magnitude">
      <xsl:with-param name="length" select="$length"/>
    </xsl:call-template>
  </xsl:variable>

  <xsl:variable name="units">
    <xsl:value-of select="substring($length, string-length($magnitude)+1)"/>
  </xsl:variable>

  <xsl:value-of select="$magnitude"/>
  <xsl:choose>
    <xsl:when test="$units='cm'
                    or $units='mm'
                    or $units='in'
                    or $units='pt'
                    or $units='pc'
                    or $units='px'
                    or $units='em'">
      <xsl:value-of select="$units"/>
    </xsl:when>
    <xsl:when test="$units = ''">
      <xsl:value-of select="$default.units"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:message>
        <xsl:text>Unrecognized unit of measure: </xsl:text>
        <xsl:value-of select="$units"/>
        <xsl:text>.</xsl:text>
      </xsl:message>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>
</src:fragment></programlisting>

</refsect1>
</refentry>

<!-- ================================================================== -->

<refentry id="length-in-points">
<refnamediv>
<refname>length-in-points</refname>
<refpurpose>Returns the size, in points, of a specified length</refpurpose>
</refnamediv>

<refsect1><title>Description</title>

<para>The <function>length-in-points</function> template converts a length
specification to points and returns that value as an unqualified
number.
</para>

<caution>
<para>There is no way for the template to infer the size of an
<literal>em</literal>. It relies on the default <parameter>em.size</parameter>
which is initially <literal>10</literal> (for 10pt).</para>

<para>Similarly, converting pixesl to points relies on the
<parameter>pixels.per.inch</parameter> parameter which is initially
<literal>90</literal>.
</para>
</caution>

<programlisting><src:fragment id='length-in-points.frag'>
<xsl:template name="length-in-points">
  <xsl:param name="length" select="'0pt'"/>
  <xsl:param name="em.size" select="10"/>
  <xsl:param name="pixels.per.inch" select="90"/>

  <xsl:variable name="magnitude">
    <xsl:call-template name="length-magnitude">
      <xsl:with-param name="length" select="$length"/>
    </xsl:call-template>
  </xsl:variable>

  <xsl:variable name="units">
    <xsl:value-of select="substring($length, string-length($magnitude)+1)"/>
  </xsl:variable>

  <xsl:choose>
    <xsl:when test="$units = 'pt'">
      <xsl:value-of select="$magnitude"/>
    </xsl:when>
    <xsl:when test="$units = 'cm'">
      <xsl:value-of select="$magnitude div 2.54 * 72.0"/>
    </xsl:when>
    <xsl:when test="$units = 'mm'">
      <xsl:value-of select="$magnitude div 25.4 * 72.0"/>
    </xsl:when>
    <xsl:when test="$units = 'in'">
      <xsl:value-of select="$magnitude * 72.0"/>
    </xsl:when>

⌨️ 快捷键说明

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