| 1 |
<?xml version="1.0" encoding="ASCII"?> |
| 2 |
<!-- ******************************************************************** |
| 3 |
$Id |
| 4 |
******************************************************************** |
| 5 |
|
| 6 |
This file is part of the XSL DocBook Stylesheet distribution. |
| 7 |
See ../README or http://docbook.sf.net/release/xsl/current/ for |
| 8 |
copyright and other information. |
| 9 |
|
| 10 |
This module implements DTD-independent functions |
| 11 |
|
| 12 |
******************************************************************** --> |
| 13 |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> |
| 14 |
|
| 15 |
<!-- Only an excerpt of the original file --> |
| 16 |
|
| 17 |
<xsl:template name="dot.count"> |
| 18 |
<!-- Returns the number of "." characters in a string --> |
| 19 |
<xsl:param name="string"/> |
| 20 |
<xsl:param name="count" select="0"/> |
| 21 |
<xsl:choose> |
| 22 |
<xsl:when test="contains($string, '.')"> |
| 23 |
<xsl:call-template name="dot.count"> |
| 24 |
<xsl:with-param name="string" select="substring-after($string, '.')"/> |
| 25 |
<xsl:with-param name="count" select="$count+1"/> |
| 26 |
</xsl:call-template> |
| 27 |
</xsl:when> |
| 28 |
<xsl:otherwise> |
| 29 |
<xsl:value-of select="$count"/> |
| 30 |
</xsl:otherwise> |
| 31 |
</xsl:choose> |
| 32 |
</xsl:template> |
| 33 |
|
| 34 |
<xsl:template name="pi-attribute"> |
| 35 |
<xsl:param name="pis" select="processing-instruction('BOGUS_PI')"/> |
| 36 |
<xsl:param name="attribute">filename</xsl:param> |
| 37 |
<xsl:param name="count">1</xsl:param> |
| 38 |
|
| 39 |
<xsl:choose> |
| 40 |
<xsl:when test="$count>count($pis)"> |
| 41 |
<!-- not found --> |
| 42 |
</xsl:when> |
| 43 |
<xsl:otherwise> |
| 44 |
<xsl:variable name="pi"> |
| 45 |
<xsl:value-of select="$pis[$count]"/> |
| 46 |
</xsl:variable> |
| 47 |
<xsl:variable name="pivalue"> |
| 48 |
<xsl:value-of select="concat(' ', normalize-space($pi))"/> |
| 49 |
</xsl:variable> |
| 50 |
<xsl:choose> |
| 51 |
<xsl:when test="contains($pivalue,concat(' ', $attribute, '='))"> |
| 52 |
<xsl:variable name="rest" |
| 53 |
select="substring-after($pivalue,concat(' ', $attribute,'='))"/> |
| 54 |
<xsl:variable name="quote" select="substring($rest,1,1)"/> |
| 55 |
<xsl:value-of select="substring-before(substring($rest,2),$quote)"/> |
| 56 |
</xsl:when> |
| 57 |
<xsl:otherwise> |
| 58 |
<xsl:call-template name="pi-attribute"> |
| 59 |
<xsl:with-param name="pis" select="$pis"/> |
| 60 |
<xsl:with-param name="attribute" select="$attribute"/> |
| 61 |
<xsl:with-param name="count" select="$count + 1"/> |
| 62 |
</xsl:call-template> |
| 63 |
</xsl:otherwise> |
| 64 |
</xsl:choose> |
| 65 |
</xsl:otherwise> |
| 66 |
</xsl:choose> |
| 67 |
</xsl:template> |
| 68 |
|
| 69 |
<xsl:template name="xpath.location"> |
| 70 |
<xsl:param name="node" select="."/> |
| 71 |
<xsl:param name="path" select="''"/> |
| 72 |
|
| 73 |
<xsl:variable name="next.path"> |
| 74 |
<xsl:value-of select="local-name($node)"/> |
| 75 |
<xsl:if test="$path != ''">/</xsl:if> |
| 76 |
<xsl:value-of select="$path"/> |
| 77 |
</xsl:variable> |
| 78 |
|
| 79 |
<xsl:choose> |
| 80 |
<xsl:when test="$node/parent::*"> |
| 81 |
<xsl:call-template name="xpath.location"> |
| 82 |
<xsl:with-param name="node" select="$node/parent::*"/> |
| 83 |
<xsl:with-param name="path" select="$next.path"/> |
| 84 |
</xsl:call-template> |
| 85 |
</xsl:when> |
| 86 |
<xsl:otherwise> |
| 87 |
<xsl:text>/</xsl:text> |
| 88 |
<xsl:value-of select="$next.path"/> |
| 89 |
</xsl:otherwise> |
| 90 |
</xsl:choose> |
| 91 |
</xsl:template> |
| 92 |
|
| 93 |
<xsl:template name="count.uri.path.depth"> |
| 94 |
<xsl:param name="filename" select="''"/> |
| 95 |
<xsl:param name="count" select="0"/> |
| 96 |
|
| 97 |
<xsl:choose> |
| 98 |
<xsl:when test="contains($filename, '/')"> |
| 99 |
<xsl:call-template name="count.uri.path.depth"> |
| 100 |
<xsl:with-param name="filename" |
| 101 |
select="substring-after($filename, '/')"/> |
| 102 |
<xsl:with-param name="count" select="$count + 1"/> |
| 103 |
</xsl:call-template> |
| 104 |
</xsl:when> |
| 105 |
<xsl:otherwise> |
| 106 |
<xsl:value-of select="$count"/> |
| 107 |
</xsl:otherwise> |
| 108 |
</xsl:choose> |
| 109 |
</xsl:template> |
| 110 |
|
| 111 |
<xsl:template name="trim.common.uri.paths"> |
| 112 |
<xsl:param name="uriA" select="''"/> |
| 113 |
<xsl:param name="uriB" select="''"/> |
| 114 |
<xsl:param name="return" select="'A'"/> |
| 115 |
|
| 116 |
<xsl:choose> |
| 117 |
<xsl:when test="contains($uriA, '/') and contains($uriB, '/') and substring-before($uriA, '/') = substring-before($uriB, '/')"> |
| 118 |
<xsl:call-template name="trim.common.uri.paths"> |
| 119 |
<xsl:with-param name="uriA" select="substring-after($uriA, '/')"/> |
| 120 |
<xsl:with-param name="uriB" select="substring-after($uriB, '/')"/> |
| 121 |
<xsl:with-param name="return" select="$return"/> |
| 122 |
</xsl:call-template> |
| 123 |
</xsl:when> |
| 124 |
<xsl:otherwise> |
| 125 |
<xsl:choose> |
| 126 |
<xsl:when test="$return = 'A'"> |
| 127 |
<xsl:value-of select="$uriA"/> |
| 128 |
</xsl:when> |
| 129 |
<xsl:otherwise> |
| 130 |
<xsl:value-of select="$uriB"/> |
| 131 |
</xsl:otherwise> |
| 132 |
</xsl:choose> |
| 133 |
</xsl:otherwise> |
| 134 |
</xsl:choose> |
| 135 |
</xsl:template> |
| 136 |
|
| 137 |
<xsl:template name="copy-string"> |
| 138 |
<!-- returns 'count' copies of 'string' --> |
| 139 |
<xsl:param name="string"/> |
| 140 |
<xsl:param name="count" select="0"/> |
| 141 |
<xsl:param name="result"/> |
| 142 |
|
| 143 |
<xsl:choose> |
| 144 |
<xsl:when test="$count>0"> |
| 145 |
<xsl:call-template name="copy-string"> |
| 146 |
<xsl:with-param name="string" select="$string"/> |
| 147 |
<xsl:with-param name="count" select="$count - 1"/> |
| 148 |
<xsl:with-param name="result"> |
| 149 |
<xsl:value-of select="$result"/> |
| 150 |
<xsl:value-of select="$string"/> |
| 151 |
</xsl:with-param> |
| 152 |
</xsl:call-template> |
| 153 |
</xsl:when> |
| 154 |
<xsl:otherwise> |
| 155 |
<xsl:value-of select="$result"/> |
| 156 |
</xsl:otherwise> |
| 157 |
</xsl:choose> |
| 158 |
</xsl:template> |
| 159 |
|
| 160 |
</xsl:stylesheet> |