home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 October / INTERNET108.ISO / pc / software / windows / building / xmlspy / xmlspyentcomplete5.exe / Data1.cab / _D3348CD2A60846CDA81393184C37B193 < prev    next >
Encoding:
Extensible Markup Language  |  2002-09-04  |  13.0 KB  |  384 lines

  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <!-- ********************************************************************
  4.      $Id: lib.xsl,v 1.1.2.2 2002/09/04 13:51:27 jdj Exp $
  5.      ********************************************************************
  6.  
  7.      This file is part of the XSL DocBook Stylesheet distribution.
  8.      See ../README or http://nwalsh.com/docbook/xsl/ for copyright
  9.      and other information.
  10.  
  11.      This module implements DTD-independent functions
  12.  
  13.      ******************************************************************** -->
  14.  
  15. <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">
  16.  
  17.  
  18. <xsl:template name="dot.count">
  19.   <!-- Returns the number of "." characters in a string -->
  20.   <xsl:param name="string"/>
  21.   <xsl:param name="count" select="0"/>
  22.   <xsl:choose>
  23.     <xsl:when test="contains($string, '.')">
  24.       <xsl:call-template name="dot.count">
  25.         <xsl:with-param name="string" select="substring-after($string, '.')"/>
  26.         <xsl:with-param name="count" select="$count+1"/>
  27.       </xsl:call-template>
  28.     </xsl:when>
  29.     <xsl:otherwise>
  30.       <xsl:value-of select="$count"/>
  31.     </xsl:otherwise>
  32.   </xsl:choose>
  33. </xsl:template>
  34.  
  35.  
  36. <xsl:template name="copy-string">
  37.   <!-- returns 'count' copies of 'string' -->
  38.   <xsl:param name="string"/>
  39.   <xsl:param name="count" select="0"/>
  40.   <xsl:param name="result"/>
  41.  
  42.   <xsl:choose>
  43.     <xsl:when test="$count>0">
  44.       <xsl:call-template name="copy-string">
  45.         <xsl:with-param name="string" select="$string"/>
  46.         <xsl:with-param name="count" select="$count - 1"/>
  47.         <xsl:with-param name="result">
  48.           <xsl:value-of select="$result"/>
  49.           <xsl:value-of select="$string"/>
  50.         </xsl:with-param>
  51.       </xsl:call-template>
  52.     </xsl:when>
  53.     <xsl:otherwise>
  54.       <xsl:value-of select="$result"/>
  55.     </xsl:otherwise>
  56.   </xsl:choose>
  57. </xsl:template>
  58.  
  59.  
  60. <xsl:template name="string.subst">
  61.   <xsl:param name="string"/>
  62.   <xsl:param name="target"/>
  63.   <xsl:param name="replacement"/>
  64.  
  65.   <xsl:choose>
  66.     <xsl:when test="contains($string, $target)">
  67.       <xsl:variable name="rest">
  68.         <xsl:call-template name="string.subst">
  69.           <xsl:with-param name="string" select="substring-after($string, $target)"/>
  70.           <xsl:with-param name="target" select="$target"/>
  71.           <xsl:with-param name="replacement" select="$replacement"/>
  72.         </xsl:call-template>
  73.       </xsl:variable>
  74.       <xsl:value-of select="concat(substring-before($string, $target),                                    $replacement,                                    $rest)"/>
  75.     </xsl:when>
  76.     <xsl:otherwise>
  77.       <xsl:value-of select="$string"/>
  78.     </xsl:otherwise>
  79.   </xsl:choose>
  80. </xsl:template>
  81.  
  82.  
  83. <xsl:template name="xpointer.idref">
  84.   <xsl:param name="xpointer">http://...</xsl:param>
  85.   <xsl:choose>
  86.     <xsl:when test="starts-with($xpointer, '#xpointer(id(')">
  87.       <xsl:variable name="rest" select="substring-after($xpointer, '#xpointer(id(')"/>
  88.       <xsl:variable name="quote" select="substring($rest, 1, 1)"/>
  89.       <xsl:value-of select="substring-before(substring-after($xpointer, $quote), $quote)"/>
  90.     </xsl:when>
  91.     <xsl:when test="starts-with($xpointer, '#')">
  92.       <xsl:value-of select="substring-after($xpointer, '#')"/>
  93.     </xsl:when>
  94.     <!-- otherwise it's a pointer to some other document -->
  95.   </xsl:choose>
  96. </xsl:template>
  97.  
  98.  
  99. <xsl:template name="length-magnitude">
  100.   <xsl:param name="length" select="'0pt'"/>
  101.  
  102.   <xsl:choose>
  103.     <xsl:when test="string-length($length) = 0"/>
  104.     <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) = '.'">
  105.       <xsl:value-of select="substring($length,1,1)"/>
  106.       <xsl:call-template name="length-magnitude">
  107.         <xsl:with-param name="length" select="substring($length,2)"/>
  108.       </xsl:call-template>
  109.     </xsl:when>
  110.   </xsl:choose>
  111. </xsl:template>
  112.  
  113.  
  114. <xsl:template name="length-units">
  115.   <xsl:param name="length" select="'0pt'"/>
  116.   <xsl:param name="default.units" select="'px'"/>
  117.   <xsl:variable name="magnitude">
  118.     <xsl:call-template name="length-magnitude">
  119.       <xsl:with-param name="length" select="$length"/>
  120.     </xsl:call-template>
  121.   </xsl:variable>
  122.  
  123.   <xsl:variable name="units">
  124.     <xsl:value-of select="substring($length, string-length($magnitude)+1)"/>
  125.   </xsl:variable>
  126.  
  127.   <xsl:choose>
  128.     <xsl:when test="$units = ''">
  129.       <xsl:value-of select="$default.units"/>
  130.     </xsl:when>
  131.     <xsl:otherwise>
  132.       <xsl:value-of select="$units"/>
  133.     </xsl:otherwise>
  134.   </xsl:choose>
  135. </xsl:template>
  136.  
  137.  
  138. <xsl:template name="length-spec">
  139.   <xsl:param name="length" select="'0pt'"/>
  140.   <xsl:param name="default.units" select="'px'"/>
  141.  
  142.   <xsl:variable name="magnitude">
  143.     <xsl:call-template name="length-magnitude">
  144.       <xsl:with-param name="length" select="$length"/>
  145.     </xsl:call-template>
  146.   </xsl:variable>
  147.  
  148.   <xsl:variable name="units">
  149.     <xsl:value-of select="substring($length, string-length($magnitude)+1)"/>
  150.   </xsl:variable>
  151.  
  152.   <xsl:value-of select="$magnitude"/>
  153.   <xsl:choose>
  154.     <xsl:when test="$units='cm'                     or $units='mm'                     or $units='in'                     or $units='pt'                     or $units='pc'                     or $units='px'                     or $units='em'">
  155.       <xsl:value-of select="$units"/>
  156.     </xsl:when>
  157.     <xsl:when test="$units = ''">
  158.       <xsl:value-of select="$default.units"/>
  159.     </xsl:when>
  160.     <xsl:otherwise>
  161.       <xsl:message>
  162.         <xsl:text>Unrecognized unit of measure: </xsl:text>
  163.         <xsl:value-of select="$units"/>
  164.         <xsl:text>.</xsl:text>
  165.       </xsl:message>
  166.     </xsl:otherwise>
  167.   </xsl:choose>
  168. </xsl:template>
  169.  
  170.  
  171. <xsl:template name="length-in-points">
  172.   <xsl:param name="length" select="'0pt'"/>
  173.   <xsl:param name="em.size" select="10"/>
  174.   <xsl:param name="pixels.per.inch" select="90"/>
  175.  
  176.   <xsl:variable name="magnitude">
  177.     <xsl:call-template name="length-magnitude">
  178.       <xsl:with-param name="length" select="$length"/>
  179.     </xsl:call-template>
  180.   </xsl:variable>
  181.  
  182.   <xsl:variable name="units">
  183.     <xsl:value-of select="substring($length, string-length($magnitude)+1)"/>
  184.   </xsl:variable>
  185.  
  186.   <xsl:choose>
  187.     <xsl:when test="$units = 'pt'">
  188.       <xsl:value-of select="$magnitude"/>
  189.     </xsl:when>
  190.     <xsl:when test="$units = 'cm'">
  191.       <xsl:value-of select="$magnitude div 2.54 * 72.0"/>
  192.     </xsl:when>
  193.     <xsl:when test="$units = 'mm'">
  194.       <xsl:value-of select="$magnitude div 25.4 * 72.0"/>
  195.     </xsl:when>
  196.     <xsl:when test="$units = 'in'">
  197.       <xsl:value-of select="$magnitude * 72.0"/>
  198.     </xsl:when>
  199.     <xsl:when test="$units = 'pc'">
  200.       <xsl:value-of select="$magnitude div 6.0 * 72.0"/>
  201.     </xsl:when>
  202.     <xsl:when test="$units = 'px'">
  203.       <xsl:value-of select="$magnitude div $pixels.per.inch * 72.0"/>
  204.     </xsl:when>
  205.     <xsl:when test="$units = 'em'">
  206.       <xsl:value-of select="$magnitude * $em.size"/>
  207.     </xsl:when>
  208.     <xsl:otherwise>
  209.       <xsl:message>
  210.         <xsl:text>Unrecognized unit of measure: </xsl:text>
  211.         <xsl:value-of select="$units"/>
  212.         <xsl:text>.</xsl:text>
  213.       </xsl:message>
  214.     </xsl:otherwise>
  215.   </xsl:choose>
  216. </xsl:template>
  217.  
  218.  
  219. <xsl:template name="pi-attribute">
  220.   <xsl:param name="pis" select="processing-instruction('')"/>
  221.   <xsl:param name="attribute">filename</xsl:param>
  222.   <xsl:param name="count">1</xsl:param>
  223.  
  224.   <xsl:choose>
  225.     <xsl:when test="$count>count($pis)">
  226.       <!-- not found -->
  227.     </xsl:when>
  228.     <xsl:otherwise>
  229.       <xsl:variable name="pi">
  230.         <xsl:value-of select="$pis[$count]"/>
  231.       </xsl:variable>
  232.       <xsl:choose>
  233.         <xsl:when test="contains($pi,concat($attribute, '='))">
  234.           <xsl:variable name="rest" select="substring-after($pi,concat($attribute,'='))"/>
  235.           <xsl:variable name="quote" select="substring($rest,1,1)"/>
  236.           <xsl:value-of select="substring-before(substring($rest,2),$quote)"/>
  237.         </xsl:when>
  238.         <xsl:otherwise>
  239.           <xsl:call-template name="pi-attribute">
  240.             <xsl:with-param name="pis" select="$pis"/>
  241.             <xsl:with-param name="attribute" select="$attribute"/>
  242.             <xsl:with-param name="count" select="$count + 1"/>
  243.           </xsl:call-template>
  244.         </xsl:otherwise>
  245.       </xsl:choose>
  246.     </xsl:otherwise>
  247.   </xsl:choose>
  248. </xsl:template>
  249.  
  250.  
  251. <xsl:template name="lookup.key">
  252.   <xsl:param name="key" select="''"/>
  253.   <xsl:param name="table" select="''"/>
  254.  
  255.   <xsl:if test="contains($table, ' ')">
  256.     <xsl:choose>
  257.       <xsl:when test="substring-before($table, ' ') = $key">
  258.         <xsl:variable name="rest" select="substring-after($table, ' ')"/>
  259.         <xsl:choose>
  260.           <xsl:when test="contains($rest, ' ')">
  261.             <xsl:value-of select="substring-before($rest, ' ')"/>
  262.           </xsl:when>
  263.           <xsl:otherwise>
  264.             <xsl:value-of select="$rest"/>
  265.           </xsl:otherwise>
  266.         </xsl:choose>
  267.       </xsl:when>
  268.       <xsl:otherwise>
  269.         <xsl:call-template name="lookup.key">
  270.           <xsl:with-param name="key" select="$key"/>
  271.           <xsl:with-param name="table" select="substring-after(substring-after($table,' '), ' ')"/>
  272.         </xsl:call-template>
  273.       </xsl:otherwise>
  274.     </xsl:choose>
  275.   </xsl:if>
  276. </xsl:template>
  277.  
  278.  
  279. <xsl:template name="xpath.location">
  280.   <xsl:param name="node" select="."/>
  281.   <xsl:param name="path" select="''"/>
  282.  
  283.   <xsl:variable name="next.path">
  284.     <xsl:value-of select="local-name($node)"/>
  285.     <xsl:if test="$path != ''">/</xsl:if>
  286.     <xsl:value-of select="$path"/>
  287.   </xsl:variable>
  288.  
  289.   <xsl:choose>
  290.     <xsl:when test="$node/parent::*">
  291.       <xsl:call-template name="xpath.location">
  292.         <xsl:with-param name="node" select="$node/parent::*"/>
  293.         <xsl:with-param name="path" select="$next.path"/>
  294.       </xsl:call-template>
  295.     </xsl:when>
  296.     <xsl:otherwise>
  297.       <xsl:text>/</xsl:text>
  298.       <xsl:value-of select="$next.path"/>
  299.     </xsl:otherwise>
  300.   </xsl:choose>
  301. </xsl:template>
  302.  
  303.  
  304. <xsl:template name="comment-escape-string">
  305.   <xsl:param name="string" select="''"/>
  306.  
  307.   <xsl:if test="starts-with($string, '-')">
  308.     <xsl:text> </xsl:text>
  309.   </xsl:if>
  310.  
  311.   <xsl:call-template name="comment-escape-string.recursive">
  312.     <xsl:with-param name="string" select="$string"/>
  313.   </xsl:call-template>
  314.  
  315.   <xsl:if test="substring($string, string-length($string), 1) = '-'">
  316.     <xsl:text> </xsl:text>
  317.   </xsl:if>
  318. </xsl:template>
  319.  
  320.  
  321. <xsl:template name="comment-escape-string.recursive">
  322.   <xsl:param name="string" select="''"/>
  323.   <xsl:choose>
  324.     <xsl:when test="contains($string, '--')">
  325.       <xsl:value-of select="substring-before($string, '--')"/>
  326.       <xsl:value-of select="'- -'"/>
  327.       <xsl:call-template name="comment-escape-string.recursive">
  328.         <xsl:with-param name="string" select="substring-after($string, '--')"/>
  329.       </xsl:call-template>
  330.     </xsl:when>
  331.     <xsl:otherwise>
  332.       <xsl:value-of select="$string"/>
  333.     </xsl:otherwise>
  334.   </xsl:choose>
  335. </xsl:template>
  336.  
  337.  
  338. <xsl:template name="count.uri.path.depth">
  339.   <xsl:param name="filename" select="''"/>
  340.   <xsl:param name="count" select="0"/>
  341.  
  342.   <xsl:choose>
  343.     <xsl:when test="contains($filename, '/')">
  344.       <xsl:call-template name="count.uri.path.depth">
  345.         <xsl:with-param name="filename" select="substring-after($filename, '/')"/>
  346.         <xsl:with-param name="count" select="$count + 1"/>
  347.       </xsl:call-template>
  348.     </xsl:when>
  349.     <xsl:otherwise>
  350.       <xsl:value-of select="$count"/>
  351.     </xsl:otherwise>
  352.   </xsl:choose>
  353. </xsl:template>
  354.  
  355.  
  356. <xsl:template name="trim.common.uri.paths">
  357.   <xsl:param name="uriA" select="''"/>
  358.   <xsl:param name="uriB" select="''"/>
  359.   <xsl:param name="return" select="'A'"/>
  360.  
  361.   <xsl:choose>
  362.     <xsl:when test="contains($uriA, '/') and contains($uriB, '/')                     and substring-before($uriA, '/') = substring-before($uriB, '/')">
  363.       <xsl:call-template name="trim.common.uri.paths">
  364.         <xsl:with-param name="uriA" select="substring-after($uriA, '/')"/>
  365.         <xsl:with-param name="uriB" select="substring-after($uriB, '/')"/>
  366.         <xsl:with-param name="return" select="$return"/>
  367.       </xsl:call-template>
  368.     </xsl:when>
  369.     <xsl:otherwise>
  370.       <xsl:choose>
  371.         <xsl:when test="$return = 'A'">
  372.           <xsl:value-of select="$uriA"/>
  373.         </xsl:when>
  374.         <xsl:otherwise>
  375.           <xsl:value-of select="$uriB"/>
  376.         </xsl:otherwise>
  377.       </xsl:choose>
  378.     </xsl:otherwise>
  379.   </xsl:choose>
  380. </xsl:template>
  381.  
  382.  
  383. </xsl:stylesheet>
  384.