📄 lib.xweb
字号:
<xsl:when test="$units = 'pc'"> <xsl:value-of select="$magnitude div 6.0 * 72.0"/> </xsl:when> <xsl:when test="$units = 'px'"> <xsl:value-of select="$magnitude div $pixels.per.inch * 72.0"/> </xsl:when> <xsl:when test="$units = 'em'"> <xsl:value-of select="$magnitude * $em.size"/> </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="pi-attribute"><refnamediv><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><?foo bar="1" baz='red'?></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('')"/> <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:choose> <xsl:when test="contains($pi,concat(' ', $attribute, '='))"> <xsl:variable name="rest" select="substring-after($pi,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></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,v 1.1 2004/10/21 11:39:55 belamri Exp $ ******************************************************************** 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="count.uri.path.depth.frag"/><src:fragref linkend="trim.common.uri.paths.frag"/></xsl:stylesheet></src:fragment></appendix></book>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -