source: trunk/Distribution/XSL/lib/lib.xml@ 2

Last change on this file since 2 was 2, checked in by jkacer, 18 years ago

Added all DocBook Framework stuff:

  • DocBook DTD
  • Transformation software FOP 0.20.5 and Saxon 6
  • XSL styles
  • Rexx scripts

Also added some WarpIN-related stuff for creation of WarpIN installation packages.
This state corresponds to version 1.0.0 from November 2005, just slightly modified to carry versioning information (Rexx scripts).

File size: 45.5 KB
Line 
1<?xml version="1.0" encoding="utf-8"?>
2<!DOCTYPE book
3 PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4<book>
5<bookinfo>
6<title>XSL Library Template Reference</title>
7<releaseinfo role="cvs">$Id: lib.xweb,v 1.13 2005/07/08 10:35:55 xmldoc Exp $
8</releaseinfo>
9<corpauthor>DocBook Open Repository Team</corpauthor>
10<copyright>
11 <year>1999</year>
12 <year>2000</year>
13 <year>2001</year>
14 <year>2002</year>
15 <year>2005</year>
16 <holder>Norman Walsh</holder>
17</copyright>
18</bookinfo>
19
20<preface><title>Introduction</title>
21
22<para>This is technical reference documentation for the DocBook XSL
23Stylesheets; it documents (some of) the parameters, templates, and
24other elements of the stylesheets.</para>
25
26<para>This is not intended to be <quote>user</quote> documentation.
27It is provided for developers writing customization layers for the
28stylesheets, and for anyone who's interested in <quote>how it
29works</quote>.</para>
30
31<para>Although I am trying to be thorough, this documentation is known
32to be incomplete. Don't forget to read the source, too :-)</para>
33
34</preface>
35
36<reference>
37<title>General Library Templates</title>
38
39<refentry id="dot.count">
40<refnamediv>
41<refname>dot.count</refname>
42<refpurpose>Returns the number of <quote>.</quote> characters in a string</refpurpose>
43</refnamediv>
44
45<refsect1><title>Description</title>
46
47<programlisting format="linespecific"><programlisting id="dot.count.frag">
48&lt;xsl:template name="dot.count"&gt;
49 &lt;!-- Returns the number of "." characters in a string --&gt;
50 &lt;xsl:param name="string"&gt;&lt;/xsl:param&gt;
51 &lt;xsl:param name="count" select="0"&gt;&lt;/xsl:param&gt;
52 &lt;xsl:choose&gt;
53 &lt;xsl:when test="contains($string, '.')"&gt;
54 &lt;xsl:call-template name="dot.count"&gt;
55 &lt;xsl:with-param name="string" select="substring-after($string, '.')"&gt;&lt;/xsl:with-param&gt;
56 &lt;xsl:with-param name="count" select="$count+1"&gt;&lt;/xsl:with-param&gt;
57 &lt;/xsl:call-template&gt;
58 &lt;/xsl:when&gt;
59 &lt;xsl:otherwise&gt;
60 &lt;xsl:value-of select="$count"&gt;&lt;/xsl:value-of&gt;
61 &lt;/xsl:otherwise&gt;
62 &lt;/xsl:choose&gt;
63&lt;/xsl:template&gt;
64</programlisting></programlisting>
65
66</refsect1>
67</refentry>
68
69
70
71<refentry id="copy-string">
72<refnamediv>
73<refname>copy-string</refname>
74<refpurpose>Returns <quote>count</quote> copies of a string</refpurpose>
75</refnamediv>
76
77<refsect1><title>Description</title>
78
79<programlisting format="linespecific"><programlisting id="copy-string.frag">
80&lt;xsl:template name="copy-string"&gt;
81 &lt;!-- returns 'count' copies of 'string' --&gt;
82 &lt;xsl:param name="string"&gt;&lt;/xsl:param&gt;
83 &lt;xsl:param name="count" select="0"&gt;&lt;/xsl:param&gt;
84 &lt;xsl:param name="result"&gt;&lt;/xsl:param&gt;
85
86 &lt;xsl:choose&gt;
87 &lt;xsl:when test="$count&gt;0"&gt;
88 &lt;xsl:call-template name="copy-string"&gt;
89 &lt;xsl:with-param name="string" select="$string"&gt;&lt;/xsl:with-param&gt;
90 &lt;xsl:with-param name="count" select="$count - 1"&gt;&lt;/xsl:with-param&gt;
91 &lt;xsl:with-param name="result"&gt;
92 &lt;xsl:value-of select="$result"&gt;&lt;/xsl:value-of&gt;
93 &lt;xsl:value-of select="$string"&gt;&lt;/xsl:value-of&gt;
94 &lt;/xsl:with-param&gt;
95 &lt;/xsl:call-template&gt;
96 &lt;/xsl:when&gt;
97 &lt;xsl:otherwise&gt;
98 &lt;xsl:value-of select="$result"&gt;&lt;/xsl:value-of&gt;
99 &lt;/xsl:otherwise&gt;
100 &lt;/xsl:choose&gt;
101&lt;/xsl:template&gt;
102</programlisting></programlisting>
103
104</refsect1>
105</refentry>
106
107
108
109<refentry id="string.subst">
110<refnamediv>
111<refname>string.subst</refname>
112<refpurpose>Substitute one text string for another in a string</refpurpose>
113</refnamediv>
114
115<refsect1><title>Description</title>
116
117<para>The <function moreinfo="none">string.subst</function> template replaces all
118occurances of <parameter moreinfo="none">target</parameter> in <parameter moreinfo="none">string</parameter>
119with <parameter moreinfo="none">replacement</parameter> and returns the result.
120</para>
121
122<programlisting format="linespecific"><programlisting id="string.subst.frag">
123&lt;xsl:template name="string.subst"&gt;
124 &lt;xsl:param name="string"&gt;&lt;/xsl:param&gt;
125 &lt;xsl:param name="target"&gt;&lt;/xsl:param&gt;
126 &lt;xsl:param name="replacement"&gt;&lt;/xsl:param&gt;
127
128 &lt;xsl:choose&gt;
129 &lt;xsl:when test="contains($string, $target)"&gt;
130 &lt;xsl:variable name="rest"&gt;
131 &lt;xsl:call-template name="string.subst"&gt;
132 &lt;xsl:with-param name="string" select="substring-after($string, $target)"&gt;&lt;/xsl:with-param&gt;
133 &lt;xsl:with-param name="target" select="$target"&gt;&lt;/xsl:with-param&gt;
134 &lt;xsl:with-param name="replacement" select="$replacement"&gt;&lt;/xsl:with-param&gt;
135 &lt;/xsl:call-template&gt;
136 &lt;/xsl:variable&gt;
137 &lt;xsl:value-of select="concat(substring-before($string, $target), $replacement, $rest)"&gt;&lt;/xsl:value-of&gt;
138 &lt;/xsl:when&gt;
139 &lt;xsl:otherwise&gt;
140 &lt;xsl:value-of select="$string"&gt;&lt;/xsl:value-of&gt;
141 &lt;/xsl:otherwise&gt;
142 &lt;/xsl:choose&gt;
143&lt;/xsl:template&gt;
144</programlisting></programlisting>
145
146</refsect1>
147</refentry>
148
149
150
151<refentry id="xpointer.idref">
152<refnamediv>
153<refname>xpointer.idref</refname>
154<refpurpose>Extract IDREF from an XPointer</refpurpose>
155</refnamediv>
156
157<refsect1><title>Description</title>
158
159<para>The <function moreinfo="none">xpointer.idref</function> template returns the
160ID portion of an XPointer which is a pointer to an ID within the current
161document, or the empty string if it is not.</para>
162<para>In other words, <function moreinfo="none">xpointer.idref</function> returns
163<quote>foo</quote> when passed either <literal moreinfo="none">#foo</literal>
164or <literal moreinfo="none">#xpointer(id('foo'))</literal>, otherwise it returns
165the empty string.</para>
166
167<programlisting format="linespecific"><programlisting id="xpointer.idref.frag">
168&lt;xsl:template name="xpointer.idref"&gt;
169 &lt;xsl:param name="xpointer"&gt;http://...&lt;/xsl:param&gt;
170 &lt;xsl:choose&gt;
171 &lt;xsl:when test="starts-with($xpointer, '#xpointer(id(')"&gt;
172 &lt;xsl:variable name="rest" select="substring-after($xpointer, '#xpointer(id(')"&gt;&lt;/xsl:variable&gt;
173 &lt;xsl:variable name="quote" select="substring($rest, 1, 1)"&gt;&lt;/xsl:variable&gt;
174 &lt;xsl:value-of select="substring-before(substring-after($xpointer, $quote), $quote)"&gt;&lt;/xsl:value-of&gt;
175 &lt;/xsl:when&gt;
176 &lt;xsl:when test="starts-with($xpointer, '#')"&gt;
177 &lt;xsl:value-of select="substring-after($xpointer, '#')"&gt;&lt;/xsl:value-of&gt;
178 &lt;/xsl:when&gt;
179 &lt;!-- otherwise it's a pointer to some other document --&gt;
180 &lt;/xsl:choose&gt;
181&lt;/xsl:template&gt;
182</programlisting></programlisting>
183
184</refsect1>
185</refentry>
186
187
188
189
190<refentry id="length-magnitude">
191<refnamediv>
192<refname>length-magnitude</refname>
193<refpurpose>Return the unqualified dimension from a length specification</refpurpose>
194</refnamediv>
195
196<refsect1><title>Description</title>
197
198<para>The <function moreinfo="none">length-magnitude</function> template returns the
199unqualified length ("20" for "20pt") from a dimension.
200</para>
201
202<programlisting format="linespecific"><programlisting id="length-magnitude.frag">
203&lt;xsl:template name="length-magnitude"&gt;
204 &lt;xsl:param name="length" select="'0pt'"&gt;&lt;/xsl:param&gt;
205
206 &lt;xsl:choose&gt;
207 &lt;xsl:when test="string-length($length) = 0"&gt;&lt;/xsl:when&gt;
208 &lt;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) = '.'"&gt;
209 &lt;xsl:value-of select="substring($length,1,1)"&gt;&lt;/xsl:value-of&gt;
210 &lt;xsl:call-template name="length-magnitude"&gt;
211 &lt;xsl:with-param name="length" select="substring($length,2)"&gt;&lt;/xsl:with-param&gt;
212 &lt;/xsl:call-template&gt;
213 &lt;/xsl:when&gt;
214 &lt;/xsl:choose&gt;
215&lt;/xsl:template&gt;
216</programlisting></programlisting>
217
218</refsect1>
219</refentry>
220
221
222
223<refentry id="length-units">
224<refnamediv>
225<refname>length-units</refname>
226<refpurpose>Return the units from a length specification</refpurpose>
227</refnamediv>
228
229<refsect1><title>Description</title>
230
231<para>The <function moreinfo="none">length-units</function> template returns the
232units ("pt" for "20pt") from a length. If no units are supplied on the
233length, the <parameter moreinfo="none">defauilt.units</parameter> are returned.</para>
234
235<programlisting format="linespecific"><programlisting id="length-units.frag">
236&lt;xsl:template name="length-units"&gt;
237 &lt;xsl:param name="length" select="'0pt'"&gt;&lt;/xsl:param&gt;
238 &lt;xsl:param name="default.units" select="'px'"&gt;&lt;/xsl:param&gt;
239 &lt;xsl:variable name="magnitude"&gt;
240 &lt;xsl:call-template name="length-magnitude"&gt;
241 &lt;xsl:with-param name="length" select="$length"&gt;&lt;/xsl:with-param&gt;
242 &lt;/xsl:call-template&gt;
243 &lt;/xsl:variable&gt;
244
245 &lt;xsl:variable name="units"&gt;
246 &lt;xsl:value-of select="substring($length, string-length($magnitude)+1)"&gt;&lt;/xsl:value-of&gt;
247 &lt;/xsl:variable&gt;
248
249 &lt;xsl:choose&gt;
250 &lt;xsl:when test="$units = ''"&gt;
251 &lt;xsl:value-of select="$default.units"&gt;&lt;/xsl:value-of&gt;
252 &lt;/xsl:when&gt;
253 &lt;xsl:otherwise&gt;
254 &lt;xsl:value-of select="$units"&gt;&lt;/xsl:value-of&gt;
255 &lt;/xsl:otherwise&gt;
256 &lt;/xsl:choose&gt;
257&lt;/xsl:template&gt;
258</programlisting></programlisting>
259
260</refsect1>
261</refentry>
262
263
264
265<refentry id="length-spec">
266<refnamediv>
267<refname>length-spec</refname>
268<refpurpose>Return a fully qualified length specification</refpurpose>
269</refnamediv>
270
271<refsect1><title>Description</title>
272
273<para>The <function moreinfo="none">length-spec</function> template returns the
274qualified length from a dimension. If an unqualified length is given,
275the <parameter moreinfo="none">default.units</parameter> will be added to it.
276</para>
277
278<programlisting format="linespecific"><programlisting id="length-spec.frag">
279&lt;xsl:template name="length-spec"&gt;
280 &lt;xsl:param name="length" select="'0pt'"&gt;&lt;/xsl:param&gt;
281 &lt;xsl:param name="default.units" select="'px'"&gt;&lt;/xsl:param&gt;
282
283 &lt;xsl:variable name="magnitude"&gt;
284 &lt;xsl:call-template name="length-magnitude"&gt;
285 &lt;xsl:with-param name="length" select="$length"&gt;&lt;/xsl:with-param&gt;
286 &lt;/xsl:call-template&gt;
287 &lt;/xsl:variable&gt;
288
289 &lt;xsl:variable name="units"&gt;
290 &lt;xsl:value-of select="substring($length, string-length($magnitude)+1)"&gt;&lt;/xsl:value-of&gt;
291 &lt;/xsl:variable&gt;
292
293 &lt;xsl:value-of select="$magnitude"&gt;&lt;/xsl:value-of&gt;
294 &lt;xsl:choose&gt;
295 &lt;xsl:when test="$units='cm' or $units='mm' or $units='in' or $units='pt' or $units='pc' or $units='px' or $units='em'"&gt;
296 &lt;xsl:value-of select="$units"&gt;&lt;/xsl:value-of&gt;
297 &lt;/xsl:when&gt;
298 &lt;xsl:when test="$units = ''"&gt;
299 &lt;xsl:value-of select="$default.units"&gt;&lt;/xsl:value-of&gt;
300 &lt;/xsl:when&gt;
301 &lt;xsl:otherwise&gt;
302 &lt;xsl:message&gt;
303 &lt;xsl:text&gt;Unrecognized unit of measure: &lt;/xsl:text&gt;
304 &lt;xsl:value-of select="$units"&gt;&lt;/xsl:value-of&gt;
305 &lt;xsl:text&gt;.&lt;/xsl:text&gt;
306 &lt;/xsl:message&gt;
307 &lt;/xsl:otherwise&gt;
308 &lt;/xsl:choose&gt;
309&lt;/xsl:template&gt;
310</programlisting></programlisting>
311
312</refsect1>
313</refentry>
314
315
316
317<refentry id="length-in-points">
318<refnamediv>
319<refname>length-in-points</refname>
320<refpurpose>Returns the size, in points, of a specified length</refpurpose>
321</refnamediv>
322
323<refsect1><title>Description</title>
324
325<para>The <function moreinfo="none">length-in-points</function> template converts a length
326specification to points and returns that value as an unqualified
327number.
328</para>
329
330<caution>
331<para>There is no way for the template to infer the size of an
332<literal moreinfo="none">em</literal>. It relies on the default <parameter moreinfo="none">em.size</parameter>
333which is initially <literal moreinfo="none">10</literal> (for 10pt).</para>
334
335<para>Similarly, converting pixels to points relies on the
336<parameter moreinfo="none">pixels.per.inch</parameter> parameter which is initially
337<literal moreinfo="none">90</literal>.
338</para>
339</caution>
340
341<programlisting format="linespecific"><programlisting id="length-in-points.frag">
342&lt;xsl:template name="length-in-points"&gt;
343 &lt;xsl:param name="length" select="'0pt'"&gt;&lt;/xsl:param&gt;
344 &lt;xsl:param name="em.size" select="10"&gt;&lt;/xsl:param&gt;
345 &lt;xsl:param name="pixels.per.inch" select="90"&gt;&lt;/xsl:param&gt;
346
347 &lt;xsl:variable name="magnitude"&gt;
348 &lt;xsl:call-template name="length-magnitude"&gt;
349 &lt;xsl:with-param name="length" select="$length"&gt;&lt;/xsl:with-param&gt;
350 &lt;/xsl:call-template&gt;
351 &lt;/xsl:variable&gt;
352
353 &lt;xsl:variable name="units"&gt;
354 &lt;xsl:value-of select="substring($length, string-length($magnitude)+1)"&gt;&lt;/xsl:value-of&gt;
355 &lt;/xsl:variable&gt;
356
357 &lt;xsl:choose&gt;
358 &lt;xsl:when test="$units = 'pt'"&gt;
359 &lt;xsl:value-of select="$magnitude"&gt;&lt;/xsl:value-of&gt;
360 &lt;/xsl:when&gt;
361 &lt;xsl:when test="$units = 'cm'"&gt;
362 &lt;xsl:value-of select="$magnitude div 2.54 * 72.0"&gt;&lt;/xsl:value-of&gt;
363 &lt;/xsl:when&gt;
364 &lt;xsl:when test="$units = 'mm'"&gt;
365 &lt;xsl:value-of select="$magnitude div 25.4 * 72.0"&gt;&lt;/xsl:value-of&gt;
366 &lt;/xsl:when&gt;
367 &lt;xsl:when test="$units = 'in'"&gt;
368 &lt;xsl:value-of select="$magnitude * 72.0"&gt;&lt;/xsl:value-of&gt;
369 &lt;/xsl:when&gt;
370 &lt;xsl:when test="$units = 'pc'"&gt;
371 &lt;xsl:value-of select="$magnitude * 12.0"&gt;&lt;/xsl:value-of&gt;
372 &lt;/xsl:when&gt;
373 &lt;xsl:when test="$units = 'px'"&gt;
374 &lt;xsl:value-of select="$magnitude div $pixels.per.inch * 72.0"&gt;&lt;/xsl:value-of&gt;
375 &lt;/xsl:when&gt;
376 &lt;xsl:when test="$units = 'em'"&gt;
377 &lt;xsl:value-of select="$magnitude * $em.size"&gt;&lt;/xsl:value-of&gt;
378 &lt;/xsl:when&gt;
379 &lt;xsl:otherwise&gt;
380 &lt;xsl:message&gt;
381 &lt;xsl:text&gt;Unrecognized unit of measure: &lt;/xsl:text&gt;
382 &lt;xsl:value-of select="$units"&gt;&lt;/xsl:value-of&gt;
383 &lt;xsl:text&gt;.&lt;/xsl:text&gt;
384 &lt;/xsl:message&gt;
385 &lt;/xsl:otherwise&gt;
386 &lt;/xsl:choose&gt;
387&lt;/xsl:template&gt;
388</programlisting></programlisting>
389
390</refsect1>
391</refentry>
392
393
394
395<refentry id="pi-attribute">
396<refnamediv>
397<refname>pi-attribute</refname>
398<refpurpose>Extract a pseudo-attribute from a PI</refpurpose>
399</refnamediv>
400
401<refsect1><title>Description</title>
402
403<para>The <function moreinfo="none">pi-attribute</function> template extracts a pseudo-attribute
404from a processing instruction. For example, given the PI
405<quote><literal moreinfo="none">&lt;?foo bar="1" baz='red'?&gt;</literal></quote>,</para>
406<programlisting format="linespecific">&lt;xsl:call-template name="pi-attribute"&gt;
407 &lt;xsl:with-param name="pis" select="processing-instruction('foo')"/&gt;
408 &lt;xsl:with-param name="attribute" select="'baz'"/&gt;
409&lt;/xsl:call-template&gt;</programlisting>
410<para>will return <quote>red</quote>. This template returns the first matching
411attribute that it finds. Presented with processing instructions that
412contain badly formed pseudo-attributes (missing or unbalanced quotes,
413for example), the template may silently return erroneous results.</para>
414
415<programlisting format="linespecific"><programlisting id="pi-attribute.frag">
416&lt;xsl:template name="pi-attribute"&gt;
417 &lt;xsl:param name="pis" select="processing-instruction('BOGUS_PI')"&gt;&lt;/xsl:param&gt;
418 &lt;xsl:param name="attribute"&gt;filename&lt;/xsl:param&gt;
419 &lt;xsl:param name="count"&gt;1&lt;/xsl:param&gt;
420
421 &lt;xsl:choose&gt;
422 &lt;xsl:when test="$count&gt;count($pis)"&gt;
423 &lt;!-- not found --&gt;
424 &lt;/xsl:when&gt;
425 &lt;xsl:otherwise&gt;
426 &lt;xsl:variable name="pi"&gt;
427 &lt;xsl:value-of select="$pis[$count]"&gt;&lt;/xsl:value-of&gt;
428 &lt;/xsl:variable&gt;
429 &lt;xsl:variable name="pivalue"&gt;
430 &lt;xsl:value-of select="concat(' ', normalize-space($pi))"&gt;&lt;/xsl:value-of&gt;
431 &lt;/xsl:variable&gt;
432 &lt;xsl:choose&gt;
433 &lt;xsl:when test="contains($pivalue,concat(' ', $attribute, '='))"&gt;
434 &lt;xsl:variable name="rest" select="substring-after($pivalue,concat(' ', $attribute,'='))"&gt;&lt;/xsl:variable&gt;
435 &lt;xsl:variable name="quote" select="substring($rest,1,1)"&gt;&lt;/xsl:variable&gt;
436 &lt;xsl:value-of select="substring-before(substring($rest,2),$quote)"&gt;&lt;/xsl:value-of&gt;
437 &lt;/xsl:when&gt;
438 &lt;xsl:otherwise&gt;
439 &lt;xsl:call-template name="pi-attribute"&gt;
440 &lt;xsl:with-param name="pis" select="$pis"&gt;&lt;/xsl:with-param&gt;
441 &lt;xsl:with-param name="attribute" select="$attribute"&gt;&lt;/xsl:with-param&gt;
442 &lt;xsl:with-param name="count" select="$count + 1"&gt;&lt;/xsl:with-param&gt;
443 &lt;/xsl:call-template&gt;
444 &lt;/xsl:otherwise&gt;
445 &lt;/xsl:choose&gt;
446 &lt;/xsl:otherwise&gt;
447 &lt;/xsl:choose&gt;
448&lt;/xsl:template&gt;
449</programlisting></programlisting>
450
451</refsect1>
452</refentry>
453
454
455
456<refentry id="lookup.key">
457<refnamediv>
458<refname>lookup.key</refname>
459<refpurpose>Retrieve the value associated with a particular key in a table</refpurpose>
460</refnamediv>
461
462<refsect1><title>Description</title>
463
464<para>Given a table of space-delimited key/value pairs,
465the <function moreinfo="none">lookup.key</function> template extracts the value associated
466with a particular key.</para>
467
468<programlisting format="linespecific"><programlisting id="lookup.key.frag">
469&lt;xsl:template name="lookup.key"&gt;
470 &lt;xsl:param name="key" select="''"&gt;&lt;/xsl:param&gt;
471 &lt;xsl:param name="table" select="''"&gt;&lt;/xsl:param&gt;
472
473 &lt;xsl:if test="contains($table, ' ')"&gt;
474 &lt;xsl:choose&gt;
475 &lt;xsl:when test="substring-before($table, ' ') = $key"&gt;
476 &lt;xsl:variable name="rest" select="substring-after($table, ' ')"&gt;&lt;/xsl:variable&gt;
477 &lt;xsl:choose&gt;
478 &lt;xsl:when test="contains($rest, ' ')"&gt;
479 &lt;xsl:value-of select="substring-before($rest, ' ')"&gt;&lt;/xsl:value-of&gt;
480 &lt;/xsl:when&gt;
481 &lt;xsl:otherwise&gt;
482 &lt;xsl:value-of select="$rest"&gt;&lt;/xsl:value-of&gt;
483 &lt;/xsl:otherwise&gt;
484 &lt;/xsl:choose&gt;
485 &lt;/xsl:when&gt;
486 &lt;xsl:otherwise&gt;
487 &lt;xsl:call-template name="lookup.key"&gt;
488 &lt;xsl:with-param name="key" select="$key"&gt;&lt;/xsl:with-param&gt;
489 &lt;xsl:with-param name="table" select="substring-after(substring-after($table,' '), ' ')"&gt;&lt;/xsl:with-param&gt;
490 &lt;/xsl:call-template&gt;
491 &lt;/xsl:otherwise&gt;
492 &lt;/xsl:choose&gt;
493 &lt;/xsl:if&gt;
494&lt;/xsl:template&gt;
495</programlisting></programlisting>
496
497</refsect1>
498</refentry>
499
500
501
502<refentry id="xpath.location">
503<refnamediv>
504<refname>xpath.location</refname>
505<refpurpose>Calculate the XPath child-sequence to the current node</refpurpose>
506</refnamediv>
507
508<refsect1><title>Description</title>
509
510<para>The <function moreinfo="none">xpath.location</function> template calculates the
511absolute path from the root of the tree to the current element node.
512</para>
513
514<programlisting format="linespecific"><programlisting id="xpath.location.frag">
515&lt;xsl:template name="xpath.location"&gt;
516 &lt;xsl:param name="node" select="."&gt;&lt;/xsl:param&gt;
517 &lt;xsl:param name="path" select="''"&gt;&lt;/xsl:param&gt;
518
519 &lt;xsl:variable name="next.path"&gt;
520 &lt;xsl:value-of select="local-name($node)"&gt;&lt;/xsl:value-of&gt;
521 &lt;xsl:if test="$path != ''"&gt;/&lt;/xsl:if&gt;
522 &lt;xsl:value-of select="$path"&gt;&lt;/xsl:value-of&gt;
523 &lt;/xsl:variable&gt;
524
525 &lt;xsl:choose&gt;
526 &lt;xsl:when test="$node/parent::*"&gt;
527 &lt;xsl:call-template name="xpath.location"&gt;
528 &lt;xsl:with-param name="node" select="$node/parent::*"&gt;&lt;/xsl:with-param&gt;
529 &lt;xsl:with-param name="path" select="$next.path"&gt;&lt;/xsl:with-param&gt;
530 &lt;/xsl:call-template&gt;
531 &lt;/xsl:when&gt;
532 &lt;xsl:otherwise&gt;
533 &lt;xsl:text&gt;/&lt;/xsl:text&gt;
534 &lt;xsl:value-of select="$next.path"&gt;&lt;/xsl:value-of&gt;
535 &lt;/xsl:otherwise&gt;
536 &lt;/xsl:choose&gt;
537&lt;/xsl:template&gt;
538</programlisting></programlisting>
539
540</refsect1>
541</refentry>
542
543
544
545<refentry id="comment-escape-string">
546<refnamediv>
547<refname>comment-escape-string</refname>
548<refpurpose>Prepare a string for inclusion in an XML comment</refpurpose>
549</refnamediv>
550
551<refsect1><title>Description</title>
552
553<para>The <function moreinfo="none">comment-escape-string</function> template returns a string
554that has been transformed so that it can safely be output as an XML comment.
555Internal occurrences of "--" will be replaced with "- -" and a leading and/or
556trailing space will be added to the string, if necessary.</para>
557
558<programlisting format="linespecific"><programlisting id="comment-escape-string">
559&lt;xsl:template name="comment-escape-string"&gt;
560 &lt;xsl:param name="string" select="''"&gt;&lt;/xsl:param&gt;
561
562 &lt;xsl:if test="starts-with($string, '-')"&gt;
563 &lt;xsl:text&gt; &lt;/xsl:text&gt;
564 &lt;/xsl:if&gt;
565
566 &lt;xsl:call-template name="comment-escape-string.recursive"&gt;
567 &lt;xsl:with-param name="string" select="$string"&gt;&lt;/xsl:with-param&gt;
568 &lt;/xsl:call-template&gt;
569
570 &lt;xsl:if test="substring($string, string-length($string), 1) = '-'"&gt;
571 &lt;xsl:text&gt; &lt;/xsl:text&gt;
572 &lt;/xsl:if&gt;
573&lt;/xsl:template&gt;
574</programlisting></programlisting>
575
576</refsect1>
577</refentry>
578
579
580
581<refentry id="comment-escape-string.recursive">
582<refnamediv>
583<refname>comment-escape-string.recursive</refname>
584<refpurpose>Internal function used by comment-escape-string</refpurpose>
585</refnamediv>
586
587<refsect1><title>Description</title>
588
589<para>The <function moreinfo="none">comment-escape-string.recursive</function> template is used
590by <function moreinfo="none">comment-escape-string</function>.</para>
591
592<programlisting format="linespecific"><programlisting id="comment-escape-string.recursive">
593&lt;xsl:template name="comment-escape-string.recursive"&gt;
594 &lt;xsl:param name="string" select="''"&gt;&lt;/xsl:param&gt;
595 &lt;xsl:choose&gt;
596 &lt;xsl:when test="contains($string, '--')"&gt;
597 &lt;xsl:value-of select="substring-before($string, '--')"&gt;&lt;/xsl:value-of&gt;
598 &lt;xsl:value-of select="'- -'"&gt;&lt;/xsl:value-of&gt;
599 &lt;xsl:call-template name="comment-escape-string.recursive"&gt;
600 &lt;xsl:with-param name="string" select="substring-after($string, '--')"&gt;&lt;/xsl:with-param&gt;
601 &lt;/xsl:call-template&gt;
602 &lt;/xsl:when&gt;
603 &lt;xsl:otherwise&gt;
604 &lt;xsl:value-of select="$string"&gt;&lt;/xsl:value-of&gt;
605 &lt;/xsl:otherwise&gt;
606 &lt;/xsl:choose&gt;
607&lt;/xsl:template&gt;
608</programlisting></programlisting>
609</refsect1>
610</refentry>
611
612
613
614<refentry id="prepend-pad">
615<refnamediv>
616<refname>prepend-pad</refname>
617<refpurpose>Right-pad a string out to a certain length</refpurpose>
618</refnamediv>
619
620<refsect1><title>Description</title>
621
622<para>This function takes string <parameter moreinfo="none">padVar</parameter> and
623pads it out to the string-length <parameter moreinfo="none">length</parameter>, using
624string <parameter moreinfo="none">padChar</parameter> (a space character by default)
625as the padding string (note that <parameter moreinfo="none">padChar</parameter> can be
626a string; it is not limited to just being a single character).</para>
627
628 <note>
629 <para>This function is a copy of Nate Austin's
630 <function moreinfo="none">prepend-pad</function> function in the <ulink url="http://www.dpawson.co.uk/xsl/sect2/padding.html">Padding
631 Content</ulink> section of Dave Pawson's <ulink url="http://www.dpawson.co.uk/xsl/index.html">XSLT
632 FAQ</ulink>.</para>
633 </note>
634
635<programlisting format="linespecific"><programlisting id="prepend-pad.frag">
636 &lt;xsl:template name="prepend-pad"&gt;
637 &lt;!-- recursive template to right justify and prepend--&gt;
638 &lt;!-- the value with whatever padChar is passed in --&gt;
639 &lt;xsl:param name="padChar" select="' '"&gt;&lt;/xsl:param&gt;
640 &lt;xsl:param name="padVar"&gt;&lt;/xsl:param&gt;
641 &lt;xsl:param name="length"&gt;&lt;/xsl:param&gt;
642 &lt;xsl:choose&gt;
643 &lt;xsl:when test="string-length($padVar) &lt; $length"&gt;
644 &lt;xsl:call-template name="prepend-pad"&gt;
645 &lt;xsl:with-param name="padChar" select="$padChar"&gt;&lt;/xsl:with-param&gt;
646 &lt;xsl:with-param name="padVar" select="concat($padChar,$padVar)"&gt;&lt;/xsl:with-param&gt;
647 &lt;xsl:with-param name="length" select="$length"&gt;&lt;/xsl:with-param&gt;
648 &lt;/xsl:call-template&gt;
649 &lt;/xsl:when&gt;
650 &lt;xsl:otherwise&gt;
651 &lt;xsl:value-of select="substring($padVar,string-length($padVar) - $length + 1)"&gt;&lt;/xsl:value-of&gt;
652 &lt;/xsl:otherwise&gt;
653 &lt;/xsl:choose&gt;
654 &lt;/xsl:template&gt;
655</programlisting></programlisting>
656
657</refsect1>
658</refentry>
659
660
661
662<refentry id="str.tokenize.keep.delimiters">
663<refnamediv>
664<refname>str.tokenize.keep.delimiters</refname>
665<refpurpose>Tokenize a string while preserving any delimiters</refpurpose>
666</refnamediv>
667
668<refsect1><title>Description</title>
669
670<para>Based on the occurrence of one or more delimiter characters,
671this function breaks a string into a list of tokens and delimiters,
672marking up each of the tokens with a <sgmltag>token</sgmltag> element
673and preserving the delimiters as text nodes between the tokens.</para>
674
675<note>
676 <para>This function is a very slightly modified version of a
677 function from the <ulink url="http://www.exslt.org/">EXSLT
678 site</ulink>. The original is available at:
679
680 <blockquote><para><ulink url="http://www.exslt.org/str/functions/tokenize/str.tokenize.template.xsl"/></para></blockquote>
681
682 The <function moreinfo="none">str.tokenize.keep.delimiters</function> function
683 differs only in that it preserves the delimiters instead of
684 discarding them.</para>
685</note>
686
687<programlisting format="linespecific"><programlisting id="str.tokenize.keep.delimiters.frag">
688
689 &lt;xsl:template name="str.tokenize.keep.delimiters"&gt;
690 &lt;xsl:param name="string" select="''"&gt;&lt;/xsl:param&gt;
691 &lt;xsl:param name="delimiters" select="' '"&gt;&lt;/xsl:param&gt;
692 &lt;xsl:choose&gt;
693 &lt;xsl:when test="not($string)"&gt;&lt;/xsl:when&gt;
694 &lt;xsl:when test="not($delimiters)"&gt;
695 &lt;xsl:call-template name="str.tokenize.keep.delimiters-characters"&gt;
696 &lt;xsl:with-param name="string" select="$string"&gt;&lt;/xsl:with-param&gt;
697 &lt;/xsl:call-template&gt;
698 &lt;/xsl:when&gt;
699 &lt;xsl:otherwise&gt;
700 &lt;xsl:call-template name="str.tokenize.keep.delimiters-delimiters"&gt;
701 &lt;xsl:with-param name="string" select="$string"&gt;&lt;/xsl:with-param&gt;
702 &lt;xsl:with-param name="delimiters" select="$delimiters"&gt;&lt;/xsl:with-param&gt;
703 &lt;/xsl:call-template&gt;
704 &lt;/xsl:otherwise&gt;
705 &lt;/xsl:choose&gt;
706 &lt;/xsl:template&gt;
707
708 &lt;xsl:template name="str.tokenize.keep.delimiters-characters"&gt;
709 &lt;xsl:param name="string"&gt;&lt;/xsl:param&gt;
710 &lt;xsl:if test="$string"&gt;
711 &lt;token&gt;&lt;xsl:value-of select="substring($string, 1, 1)"&gt;&lt;/xsl:value-of&gt;&lt;/token&gt;
712 &lt;xsl:call-template name="str.tokenize.keep.delimiters-characters"&gt;
713 &lt;xsl:with-param name="string" select="substring($string, 2)"&gt;&lt;/xsl:with-param&gt;
714 &lt;/xsl:call-template&gt;
715 &lt;/xsl:if&gt;
716 &lt;/xsl:template&gt;
717
718 &lt;xsl:template name="str.tokenize.keep.delimiters-delimiters"&gt;
719 &lt;xsl:param name="string"&gt;&lt;/xsl:param&gt;
720 &lt;xsl:param name="delimiters"&gt;&lt;/xsl:param&gt;
721 &lt;xsl:variable name="delimiter" select="substring($delimiters, 1, 1)"&gt;&lt;/xsl:variable&gt;
722 &lt;xsl:choose&gt;
723 &lt;xsl:when test="not($delimiter)"&gt;
724 &lt;token&gt;&lt;xsl:value-of select="$string"&gt;&lt;/xsl:value-of&gt;&lt;/token&gt;
725 &lt;/xsl:when&gt;
726 &lt;xsl:when test="contains($string, $delimiter)"&gt;
727 &lt;xsl:if test="not(starts-with($string, $delimiter))"&gt;
728 &lt;xsl:call-template name="str.tokenize.keep.delimiters-delimiters"&gt;
729 &lt;xsl:with-param name="string" select="substring-before($string, $delimiter)"&gt;&lt;/xsl:with-param&gt;
730 &lt;xsl:with-param name="delimiters" select="substring($delimiters, 2)"&gt;&lt;/xsl:with-param&gt;
731 &lt;/xsl:call-template&gt;
732 &lt;/xsl:if&gt;
733 &lt;!-- output each delimiter --&gt;
734 &lt;xsl:value-of select="$delimiter"&gt;&lt;/xsl:value-of&gt;
735 &lt;xsl:call-template name="str.tokenize.keep.delimiters-delimiters"&gt;
736 &lt;xsl:with-param name="string" select="substring-after($string, $delimiter)"&gt;&lt;/xsl:with-param&gt;
737 &lt;xsl:with-param name="delimiters" select="$delimiters"&gt;&lt;/xsl:with-param&gt;
738 &lt;/xsl:call-template&gt;
739 &lt;/xsl:when&gt;
740 &lt;xsl:otherwise&gt;
741 &lt;xsl:call-template name="str.tokenize.keep.delimiters-delimiters"&gt;
742 &lt;xsl:with-param name="string" select="$string"&gt;&lt;/xsl:with-param&gt;
743 &lt;xsl:with-param name="delimiters" select="substring($delimiters, 2)"&gt;&lt;/xsl:with-param&gt;
744 &lt;/xsl:call-template&gt;
745 &lt;/xsl:otherwise&gt;
746 &lt;/xsl:choose&gt;
747 &lt;/xsl:template&gt;
748</programlisting></programlisting>
749
750</refsect1>
751</refentry>
752
753
754
755<refentry id="apply-string-subst-map">
756 <refnamediv>
757 <refname>apply-string-subst-map</refname>
758 <refpurpose>Apply a string-substitution map</refpurpose>
759 </refnamediv>
760
761 <refsect1><title>Description</title>
762
763 <para>This function applies a "string substitution" map. Use it when
764 you want to do multiple string substitutions on the same target
765 content. It reads in two things: <parameter moreinfo="none">content</parameter>, the
766 content on which to perform the substitution, and
767 <parameter moreinfo="none">map.contents</parameter>, a node set of
768 elements (the names of the elements don't matter), with each element
769 having the following attributes:
770 <itemizedlist>
771 <listitem>
772 <simpara><tag class="attribute">oldstring</tag>, a string to
773 be replaced</simpara>
774 </listitem>
775 <listitem>
776 <simpara><tag class="attribute">newstring</tag>, a string with
777 which to replace <tag class="attribute">oldstring</tag></simpara>
778 </listitem>
779 </itemizedlist>
780 The function uses <parameter moreinfo="none">map.contents</parameter> to
781 do substitution on <parameter moreinfo="none">content</parameter>, and then
782 returns the modified contents.</para>
783
784 <note>
785 <para>This function is a very slightly modified version of Jeni
786 Tennison's <function moreinfo="none">replace_strings</function> function in the
787 <ulink url="http://www.dpawson.co.uk/xsl/sect2/StringReplace.html#d9351e13">multiple string replacements</ulink> section of Dave Pawson's
788 <ulink url="http://www.dpawson.co.uk/xsl/index.html">XSLT
789 FAQ</ulink>.</para>
790
791 <para>The <function moreinfo="none">apply-string-subst-map</function> function is
792 essentially the same function as the
793 <function moreinfo="none">apply-character-map</function> function; the only
794 difference is that in the map that
795 <function moreinfo="none">apply-string-subst-map</function> expects, <tag class="attribute">oldstring</tag> and <tag class="attribute">newstring</tag> attributes are used instead of
796 <tag class="attribute">character</tag> and <tag class="attribute">string</tag> attributes.</para>
797 </note>
798
799 <programlisting format="linespecific"><programlisting id="apply-string-subst-map.frag">
800 &lt;xsl:template name="apply-string-subst-map"&gt;
801 &lt;xsl:param name="content"&gt;&lt;/xsl:param&gt;
802 &lt;xsl:param name="map.contents"&gt;&lt;/xsl:param&gt;
803 &lt;xsl:variable name="replaced_text"&gt;
804 &lt;xsl:call-template name="string.subst"&gt;
805 &lt;xsl:with-param name="string" select="$content"&gt;&lt;/xsl:with-param&gt;
806 &lt;xsl:with-param name="target" select="$map.contents[1]/@oldstring"&gt;&lt;/xsl:with-param&gt;
807 &lt;xsl:with-param name="replacement" select="$map.contents[1]/@newstring"&gt;&lt;/xsl:with-param&gt;
808 &lt;/xsl:call-template&gt;
809 &lt;/xsl:variable&gt;
810 &lt;xsl:choose&gt;
811 &lt;xsl:when test="$map.contents[2]"&gt;
812 &lt;xsl:call-template name="apply-string-subst-map"&gt;
813 &lt;xsl:with-param name="content" select="$replaced_text"&gt;&lt;/xsl:with-param&gt;
814 &lt;xsl:with-param name="map.contents" select="$map.contents[position() &gt; 1]"&gt;&lt;/xsl:with-param&gt;
815 &lt;/xsl:call-template&gt;
816 &lt;/xsl:when&gt;
817 &lt;xsl:otherwise&gt;
818 &lt;xsl:value-of select="$replaced_text"&gt;&lt;/xsl:value-of&gt;
819 &lt;/xsl:otherwise&gt;
820 &lt;/xsl:choose&gt;
821 &lt;/xsl:template&gt;
822
823 </programlisting></programlisting>
824 </refsect1>
825</refentry>
826
827
828
829<refentry id="apply-character-map">
830 <refnamediv>
831 <refname>apply-character-map</refname>
832 <refpurpose>Apply an XSLT character map</refpurpose>
833 </refnamediv>
834
835 <refsect1><title>Description</title>
836
837 <para>This function applies an <ulink url="http://www.w3.org/TR/xslt20/#character-maps">XSLT character
838 map</ulink>; that is, it cause certain individual characters to be
839 substituted with strings of one or more characters. It is useful
840 mainly for replacing multiple "special" chararacters or symbols in
841 the same target content. It reads in two things:
842 <parameter moreinfo="none">content</parameter>, the content on which to perform the
843 substitution, and <parameter moreinfo="none">map.contents</parameter>, a
844 node set of elements (the names of the elements don't matter), with
845 each element having the following attributes:
846 <itemizedlist>
847 <listitem>
848 <simpara><tag class="attribute">character</tag>, a character to
849 be replaced</simpara>
850 </listitem>
851 <listitem>
852 <simpara><tag class="attribute">string</tag>, a string with
853 which to replace <tag class="attribute">character</tag></simpara>
854 </listitem>
855 </itemizedlist>
856 This function uses <parameter moreinfo="none">map.contents</parameter> to
857 do substitution on <parameter moreinfo="none">content</parameter>, and then returns
858 the modified contents.</para>
859
860 <note>
861 <para>This function is a very slightly modified version of Jeni
862 Tennison's <function moreinfo="none">replace_strings</function> function in the
863 <ulink url="http://www.dpawson.co.uk/xsl/sect2/StringReplace.html#d9351e13">multiple string replacements</ulink> section of Dave Pawson's
864 <ulink url="http://www.dpawson.co.uk/xsl/index.html">XSLT
865 FAQ</ulink>.</para>
866
867 <para>The <function moreinfo="none">apply-string-subst-map</function> function is
868 essentially the same function as the
869 <function moreinfo="none">apply-character-map</function> function; the only
870 difference is that in the map that
871 <function moreinfo="none">apply-string-subst-map</function> expects, <tag class="attribute">oldstring</tag> and <tag class="attribute">newstring</tag> attributes are used instead of
872 <tag class="attribute">character</tag> and <tag class="attribute">string</tag> attributes.</para>
873 </note>
874
875 <programlisting format="linespecific"><programlisting id="apply-character-map.frag">
876 &lt;xsl:template name="apply-character-map"&gt;
877 &lt;xsl:param name="content"&gt;&lt;/xsl:param&gt;
878 &lt;xsl:param name="map.contents"&gt;&lt;/xsl:param&gt;
879 &lt;xsl:variable name="replaced_text"&gt;
880 &lt;xsl:call-template name="string.subst"&gt;
881 &lt;xsl:with-param name="string" select="$content"&gt;&lt;/xsl:with-param&gt;
882 &lt;xsl:with-param name="target" select="$map.contents[1]/@character"&gt;&lt;/xsl:with-param&gt;
883 &lt;xsl:with-param name="replacement" select="$map.contents[1]/@string"&gt;&lt;/xsl:with-param&gt;
884 &lt;/xsl:call-template&gt;
885 &lt;/xsl:variable&gt;
886 &lt;xsl:choose&gt;
887 &lt;xsl:when test="$map.contents[2]"&gt;
888 &lt;xsl:call-template name="apply-character-map"&gt;
889 &lt;xsl:with-param name="content" select="$replaced_text"&gt;&lt;/xsl:with-param&gt;
890 &lt;xsl:with-param name="map.contents" select="$map.contents[position() &gt; 1]"&gt;&lt;/xsl:with-param&gt;
891 &lt;/xsl:call-template&gt;
892 &lt;/xsl:when&gt;
893 &lt;xsl:otherwise&gt;
894 &lt;xsl:value-of select="$replaced_text"&gt;&lt;/xsl:value-of&gt;
895 &lt;/xsl:otherwise&gt;
896 &lt;/xsl:choose&gt;
897 &lt;/xsl:template&gt;
898
899 </programlisting></programlisting>
900 </refsect1>
901</refentry>
902
903
904
905<refentry id="read-character-map">
906<refnamediv>
907<refname>read-character-map</refname>
908<refpurpose>Read in all or part of an XSLT character map</refpurpose>
909</refnamediv>
910
911<refsect1><title>Description</title>
912
913<para>The XSLT 2.0 specification describes <ulink url="http://www.w3.org/TR/xslt20/#character-maps">character
914maps</ulink> and explains how they may be used to allow a specific
915character appearing in a text or attribute node in a final results
916tree to be substituted by a specified string of characters during
917serialization. The <function moreinfo="none">read-character-map</function> function
918provides a means for reading and using character maps with XSLT
9191.0-based tools.</para>
920
921<para>It reads the character-map contents from
922<parameter moreinfo="none">uri</parameter> (in full or in part, depending on the value
923of the <parameter moreinfo="none">use.subset</parameter> parameter), then passes those
924contents to the <function moreinfo="none">apply-character-map</function> function,
925along with <parameter moreinfo="none">content</parameter>, the data on which to
926perform the character substition.</para>
927
928<para>Using the character map "in part" means that it uses only those
929<tag>output-character</tag> elements that match the XPATH expression
930given in the value of the <parameter moreinfo="none">subset.profile</parameter>
931parameter. The current implementation of that capability here relies
932on the <function moreinfo="none">evaluate</function> extension XSLT function.</para>
933
934<programlisting format="linespecific"><programlisting id="read-character-map.frag">
935 &lt;xsl:template name="read-character-map"&gt;
936 &lt;xsl:param name="use.subset"&gt;&lt;/xsl:param&gt;
937 &lt;xsl:param name="subset.profile"&gt;&lt;/xsl:param&gt;
938 &lt;xsl:param name="uri"&gt;&lt;/xsl:param&gt;
939 &lt;xsl:choose&gt;
940 &lt;xsl:when test="$use.subset != 0"&gt;
941 &lt;!-- use a subset of the character map instead of the full map --&gt;
942 &lt;xsl:choose&gt;
943 &lt;!-- xsltproc and Xalan both support dyn:evaluate() --&gt;
944 &lt;xsl:when test="function-available('dyn:evaluate')"&gt;
945 &lt;xsl:copy-of select="document($uri)//*[local-name()='output-character'] [dyn:evaluate($subset.profile)]"&gt;&lt;/xsl:copy-of&gt;
946 &lt;/xsl:when&gt;
947 &lt;!-- Saxon has its own evaluate() &amp; doesn't support dyn:evaluate() --&gt;
948 &lt;xsl:when test="function-available('saxon:evaluate')"&gt;
949 &lt;xsl:copy-of select="document($uri)//*[local-name()='output-character'] [saxon:evaluate($subset.profile)]"&gt;&lt;/xsl:copy-of&gt;
950 &lt;/xsl:when&gt;
951 &lt;xsl:otherwise&gt;
952 &lt;xsl:message terminate="yes"&gt;
953Error: To process character-map subsets, you must use an XSLT engine
954that supports the evaluate() XSLT extension function. Your XSLT engine
955does not support it.
956&lt;/xsl:message&gt;
957 &lt;/xsl:otherwise&gt;
958 &lt;/xsl:choose&gt;
959 &lt;/xsl:when&gt;
960 &lt;xsl:otherwise&gt;
961 &lt;!-- value of $use.subet is non-zero, so use the full map --&gt;
962 &lt;xsl:copy-of select="document($uri)//*[local-name()='output-character']"&gt;&lt;/xsl:copy-of&gt;
963 &lt;/xsl:otherwise&gt;
964 &lt;/xsl:choose&gt;
965 &lt;/xsl:template&gt;
966</programlisting></programlisting>
967</refsect1>
968</refentry>
969
970</reference>
971
972
973
974<reference>
975<title>Relative URI Functions</title>
976
977<partintro><title>Introduction</title>
978
979<para>These functions manipulate relative URI references.</para>
980
981<para>The following assumptions must hold true:</para>
982
983<orderedlist inheritnum="ignore" continuation="restarts">
984<listitem>
985<para>All URIs are relative.</para>
986</listitem>
987<listitem>
988<para>No URI contains the <quote><literal moreinfo="none">../</literal></quote> sequence
989which would effectively move <quote>up</quote> the hierarchy.</para>
990</listitem>
991</orderedlist>
992
993<para>If these assumptions do not hold, the results are unpredictable.</para>
994
995</partintro>
996
997
998
999<refentry id="count.uri.path.depth">
1000<refnamediv>
1001<refname>count.uri.path.depth</refname>
1002<refpurpose>Count the number of path components in a relative URI</refpurpose>
1003</refnamediv>
1004
1005<refsect1><title>Description</title>
1006
1007<para>This function counts the number of path components in a relative URI.</para>
1008
1009<programlisting format="linespecific"><programlisting id="count.uri.path.depth.frag">
1010&lt;xsl:template name="count.uri.path.depth"&gt;
1011 &lt;xsl:param name="filename" select="''"&gt;&lt;/xsl:param&gt;
1012 &lt;xsl:param name="count" select="0"&gt;&lt;/xsl:param&gt;
1013
1014 &lt;xsl:choose&gt;
1015 &lt;xsl:when test="contains($filename, '/')"&gt;
1016 &lt;xsl:call-template name="count.uri.path.depth"&gt;
1017 &lt;xsl:with-param name="filename" select="substring-after($filename, '/')"&gt;&lt;/xsl:with-param&gt;
1018 &lt;xsl:with-param name="count" select="$count + 1"&gt;&lt;/xsl:with-param&gt;
1019 &lt;/xsl:call-template&gt;
1020 &lt;/xsl:when&gt;
1021 &lt;xsl:otherwise&gt;
1022 &lt;xsl:value-of select="$count"&gt;&lt;/xsl:value-of&gt;
1023 &lt;/xsl:otherwise&gt;
1024 &lt;/xsl:choose&gt;
1025&lt;/xsl:template&gt;
1026</programlisting></programlisting>
1027
1028</refsect1>
1029</refentry>
1030
1031
1032
1033<refentry id="trim.common.uri.paths">
1034<refnamediv>
1035<refname>trim.common.uri.paths</refname>
1036<refpurpose>Trim common leading path components from a relative URI</refpurpose>
1037</refnamediv>
1038
1039<refsect1><title>Description</title>
1040
1041<para>This function trims common leading path components from a relative URI.</para>
1042
1043<programlisting format="linespecific"><programlisting id="trim.common.uri.paths.frag">
1044&lt;xsl:template name="trim.common.uri.paths"&gt;
1045 &lt;xsl:param name="uriA" select="''"&gt;&lt;/xsl:param&gt;
1046 &lt;xsl:param name="uriB" select="''"&gt;&lt;/xsl:param&gt;
1047 &lt;xsl:param name="return" select="'A'"&gt;&lt;/xsl:param&gt;
1048
1049 &lt;xsl:choose&gt;
1050 &lt;xsl:when test="contains($uriA, '/') and contains($uriB, '/') and substring-before($uriA, '/') = substring-before($uriB, '/')"&gt;
1051 &lt;xsl:call-template name="trim.common.uri.paths"&gt;
1052 &lt;xsl:with-param name="uriA" select="substring-after($uriA, '/')"&gt;&lt;/xsl:with-param&gt;
1053 &lt;xsl:with-param name="uriB" select="substring-after($uriB, '/')"&gt;&lt;/xsl:with-param&gt;
1054 &lt;xsl:with-param name="return" select="$return"&gt;&lt;/xsl:with-param&gt;
1055 &lt;/xsl:call-template&gt;
1056 &lt;/xsl:when&gt;
1057 &lt;xsl:otherwise&gt;
1058 &lt;xsl:choose&gt;
1059 &lt;xsl:when test="$return = 'A'"&gt;
1060 &lt;xsl:value-of select="$uriA"&gt;&lt;/xsl:value-of&gt;
1061 &lt;/xsl:when&gt;
1062 &lt;xsl:otherwise&gt;
1063 &lt;xsl:value-of select="$uriB"&gt;&lt;/xsl:value-of&gt;
1064 &lt;/xsl:otherwise&gt;
1065 &lt;/xsl:choose&gt;
1066 &lt;/xsl:otherwise&gt;
1067 &lt;/xsl:choose&gt;
1068&lt;/xsl:template&gt;
1069</programlisting></programlisting>
1070
1071</refsect1>
1072</refentry>
1073
1074</reference>
1075
1076
1077
1078<appendix><title>The Stylesheet</title>
1079
1080<para>The <filename moreinfo="none">lib.xsl</filename> stylesheet is just a wrapper
1081around these functions.</para>
1082
1083<programlisting id="top">
1084
1085&lt;!-- ********************************************************************
1086 $Id: lib.xweb,v 1.13 2005/07/08 10:35:55 xmldoc Exp $
1087 ********************************************************************
1088
1089 This file is part of the XSL DocBook Stylesheet distribution.
1090 See ../README or http://nwalsh.com/docbook/xsl/ for copyright
1091 and other information.
1092
1093 This module implements DTD-independent functions
1094
1095 ******************************************************************** --&gt;
1096
1097&lt;xsl:stylesheet exclude-result-prefixes="src" version="1.0"&gt;
1098
1099&lt;src:fragref linkend="dot.count.frag"&gt;&lt;/src:fragref&gt;
1100&lt;src:fragref linkend="copy-string.frag"&gt;&lt;/src:fragref&gt;
1101&lt;src:fragref linkend="string.subst.frag"&gt;&lt;/src:fragref&gt;
1102&lt;src:fragref linkend="xpointer.idref.frag"&gt;&lt;/src:fragref&gt;
1103&lt;src:fragref linkend="length-magnitude.frag"&gt;&lt;/src:fragref&gt;
1104&lt;src:fragref linkend="length-units.frag"&gt;&lt;/src:fragref&gt;
1105&lt;src:fragref linkend="length-spec.frag"&gt;&lt;/src:fragref&gt;
1106&lt;src:fragref linkend="length-in-points.frag"&gt;&lt;/src:fragref&gt;
1107&lt;src:fragref linkend="pi-attribute.frag"&gt;&lt;/src:fragref&gt;
1108&lt;src:fragref linkend="lookup.key.frag"&gt;&lt;/src:fragref&gt;
1109&lt;src:fragref linkend="xpath.location.frag"&gt;&lt;/src:fragref&gt;
1110&lt;src:fragref linkend="comment-escape-string"&gt;&lt;/src:fragref&gt;
1111&lt;src:fragref linkend="comment-escape-string.recursive"&gt;&lt;/src:fragref&gt;
1112&lt;src:fragref linkend="prepend-pad.frag"&gt;&lt;/src:fragref&gt;
1113&lt;src:fragref linkend="str.tokenize.keep.delimiters.frag"&gt;&lt;/src:fragref&gt;
1114&lt;src:fragref linkend="apply-string-subst-map.frag"&gt;&lt;/src:fragref&gt;
1115&lt;src:fragref linkend="apply-character-map.frag"&gt;&lt;/src:fragref&gt;
1116&lt;src:fragref linkend="read-character-map.frag"&gt;&lt;/src:fragref&gt;
1117&lt;src:fragref linkend="count.uri.path.depth.frag"&gt;&lt;/src:fragref&gt;
1118&lt;src:fragref linkend="trim.common.uri.paths.frag"&gt;&lt;/src:fragref&gt;
1119
1120&lt;/xsl:stylesheet&gt;
1121</programlisting>
1122
1123</appendix>
1124</book>
Note: See TracBrowser for help on using the repository browser.