Browse Source

Import the texml-related XSL files into this repository

This helps against build failures due to sourceforge being
unavailable.
Jonas Wielicki 1 year ago
parent
commit
b9a410551e
12 changed files with 5647 additions and 1 deletions
  1. 1
    0
      Dockerfile
  2. 318
    0
      texml-xsl/cmp.xsl
  3. 1447
    0
      texml-xsl/date-time.xsl
  4. 90
    0
      texml-xsl/example.xsl
  5. 789
    0
      texml-xsl/markup.xsl
  6. 618
    0
      texml-xsl/math.xsl
  7. 229
    0
      texml-xsl/node.xsl
  8. 340
    0
      texml-xsl/stdlib.xsl
  9. 1233
    0
      texml-xsl/string.xsl
  10. 1
    0
      texml-xsl/svg.xsl
  11. 580
    0
      texml-xsl/uri.xsl
  12. 1
    1
      xep2texml.xsl

+ 1
- 0
Dockerfile View File

@@ -10,6 +10,7 @@ COPY *.xml xep.* *.css *.xsl *.js *.xsl Makefile /src/
10 10
 COPY resources/*.pdf /src/resources/
11 11
 COPY tools/*.py /src/tools/
12 12
 COPY inbox/*.xml inbox/*.ent inbox/*.dtd /src/inbox/
13
+COPY texml-xsl/*.xsl /src/texml-xsl/
13 14
 
14 15
 WORKDIR /src
15 16
 RUN OUTDIR=/var/www/html/extensions/ make -j$NCORES $TARGETS

+ 318
- 0
texml-xsl/cmp.xsl View File

@@ -0,0 +1,318 @@
1
+<?xml version="1.0"?>
2
+
3
+<xsl:stylesheet
4
+  version="1.0"
5
+  extension-element-prefixes="doc"
6
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
7
+  xmlns:doc="http://xsltsl.org/xsl/documentation/1.0"
8
+  xmlns:str="http://xsltsl.org/string"
9
+  xmlns:cmp="http://xsltsl.org/cmp"
10
+  exclude-result-prefixes="cmp str doc"
11
+>
12
+
13
+  <doc:reference xmlns="">
14
+    <referenceinfo>
15
+      <releaseinfo role="meta">
16
+        $Id$
17
+      </releaseinfo>
18
+      <author>
19
+        <surname>Hummel</surname>
20
+        <firstname>Mark</firstname>
21
+      </author>
22
+      <copyright>
23
+        <year>2003</year>
24
+        <holder>Mark Hummel</holder>
25
+      </copyright>
26
+    </referenceinfo>
27
+
28
+    <title>XML Compare</title>
29
+
30
+    <partintro>
31
+      <section>
32
+        <title>Introduction</title>
33
+
34
+        <para>This module provides a template for comparing two xml documents. </para>
35
+
36
+      </section>
37
+    </partintro>
38
+
39
+  </doc:reference>
40
+
41
+
42
+  <doc:template name="cmp:diff">
43
+    <refpurpose>Compare</refpurpose>
44
+
45
+    <refdescription>
46
+      <para>Compare two xml documents and display differences. Two xml documents are defined to be the same if: They have the matching elements and attributes, and that the data in the elements also match. The comparison is order sensitive. </para>
47
+
48
+      <para>The element names from the documents at the current depth are compared, followed by their values, then any attribute names and values are compared. The process is applied then to the subtrees of the documents.</para>
49
+
50
+      <para>Notes: If there are leaf nodes in one nodeset which don't exist in the other, the value of those 'extra' elements won't appear as a difference.
51
+      </para>
52
+    </refdescription>
53
+
54
+    <refparameter>
55
+      <variablelist>
56
+        <varlistentry>
57
+          <term>ns1</term>
58
+          <term>ns2</term>
59
+          <listitem>
60
+            <para>The two nodesets which are to be compared. </para>
61
+          </listitem>
62
+        </varlistentry>
63
+      </variablelist>
64
+    </refparameter>
65
+
66
+    <refreturn>
67
+      <para>Returns the difference between the documents. </para>
68
+
69
+      <para>The format of the output is an xml document. A node is added to the result tree for every difference. The node contains the type of difference (e.g element name difference, attribute value difference, etc), the value in the first nodeset and the value in the second nodeset, and the parent node. The indentation level is the depth at which the difference was found relative to the first document. </para>
70
+
71
+    </refreturn>
72
+  </doc:template>
73
+
74
+  <!-- pass in a nodeset and compare. Is order sensitive. Output attribute, element and textual differences. -->
75
+
76
+  <xsl:template name="cmp:diff">
77
+    <xsl:param name="ns1"/>
78
+    <xsl:param name="ns2"/>
79
+
80
+    <!-- attribute compare -->
81
+	<!-- Optimisation attempt 
82
+
83
+	Can probaby change this into one loop ie -
84
+	<xsl:for-each 
85
+	  i = position
86
+	 if node1[i] = node2[i]...
87
+
88
+	  -->
89
+
90
+	<!-- Need to check if there are two sets of attributes -->
91
+	<xsl:choose>
92
+	  <xsl:when test='count($ns1/attribute::*) = count($ns2/attribute::*)'>
93
+	    <xsl:for-each select="$ns1/attribute::*">
94
+	      <xsl:variable name="name1" select="name()"/>
95
+	      <xsl:variable name="value1" select="."/>
96
+	      <xsl:variable name="i" select="position()"/>
97
+	      
98
+	      <xsl:for-each select="$ns2/attribute::*">
99
+		
100
+		<xsl:variable name="j" select="position()"/>
101
+		<xsl:variable name="name2" select="name()"/>
102
+		<xsl:variable name="value2" select="."/>
103
+		
104
+		<xsl:if test="$i = $j">
105
+		  <xsl:if test="$name1 != $name2">
106
+		    <attributeNameDifference>
107
+	              <parentElement><xsl:value-of select="name(..)"/></parentElement>
108
+                      <before><xsl:value-of select="$name1"/></before>
109
+	              <after><xsl:value-of select="$name2"/></after>
110
+		    </attributeNameDifference>
111
+		  </xsl:if>
112
+		  
113
+		  <xsl:if test="$name1 = $name2 and $value1 != $value2">
114
+		    <attributeValueDifference>
115
+		      <parentElement><xsl:value-of select="name(..)"/></parentElement>
116
+		      <before><xsl:value-of select="$value1"/></before>
117
+		      <after><xsl:value-of select="$value2"/></after>
118
+		    </attributeValueDifference>
119
+		  </xsl:if>
120
+	      
121
+		</xsl:if>
122
+	      </xsl:for-each>
123
+	    </xsl:for-each>
124
+	    </xsl:when>
125
+	  <xsl:otherwise>
126
+	    <attributeNameDifference>
127
+	      <parentElement>
128
+		<xsl:value-of select="name(..)"/>
129
+	      </parentElement>
130
+	      <before><xsl:value-of select='$ns1/attribute::*'/></before>
131
+	      <after><xsl:value-of select='$ns2/attribute::*'/></after>
132
+	    </attributeNameDifference>
133
+	  </xsl:otherwise>
134
+	</xsl:choose>
135
+	
136
+
137
+  <!-- Find element differences by comparing the element names from the same position in both documents. Iterate over all the nodes in the nodeset with the largest number of elements, so the extra elements will appear as differences. -->
138
+
139
+    <xsl:choose>
140
+      <!-- Define loop direction based on which tree has more nodes
141
+	   FIXME: Replacing this with one for-each and a test for the case 
142
+	          of the second tree having more nodes would be more elegant 
143
+
144
+	   Solution: Add variable for direction and assign the 'larger' nodeset to that
145
+	             variable. Then do one for-each. 
146
+	   
147
+	   FIXME: The solution is a bit too iterative. Make it more functional
148
+
149
+      -->
150
+     <xsl:when test="count($ns1) &gt; count($ns2)">
151
+       <xsl:for-each select="$ns1">
152
+          <xsl:variable name="i" select="position()"/> 
153
+	  
154
+	  <xsl:message>node[<xsl:value-of select='$i'/>]:
155
+	    <xsl:value-of select='$ns1[$i]'/>
156
+	  </xsl:message>
157
+
158
+	<!-- Element name compare -->
159
+	  <xsl:if test="name($ns1[$i]) != name($ns2[$i])">
160
+        	<elementNameDifference>
161
+		  <parentElement><xsl:value-of select="name(..)"/></parentElement>
162
+		  <before><xsl:value-of select="name($ns1[$i])"/></before>
163
+		  <after><xsl:value-of select="name($ns2[$i])"/></after>
164
+  	        </elementNameDifference>
165
+	  </xsl:if>
166
+	
167
+	  <!-- Element Value compare -->
168
+	
169
+	  <xsl:if test="count($ns1/*) = 0">
170
+            <xsl:if test="$ns1[$i] != $ns2[$i]">
171
+	         <elementValueDifference>
172
+	           <parentElement><xsl:value-of select="name(..)"/></parentElement>
173
+		   <before><xsl:value-of select="$ns1[$i]"/></before>
174
+ 		   <after><xsl:value-of select="$ns2[$i]"/></after>
175
+	         </elementValueDifference>
176
+	    </xsl:if>
177
+	 </xsl:if>
178
+	
179
+       </xsl:for-each>
180
+      </xsl:when>
181
+      <xsl:otherwise>
182
+        <xsl:for-each select="$ns2">
183
+          <xsl:variable name="i" select="position()"/> 
184
+
185
+	  <!-- Element Name compare -->
186
+	
187
+	  <xsl:if test="name($ns1[$i]) != name($ns2[$i])">
188
+	       <elementNameDifference>
189
+		  <parentElement><xsl:value-of select="name(..)"/></parentElement>
190
+		  <before><xsl:value-of select="name($ns1[$i])"/></before>
191
+		  <after><xsl:value-of select="name($ns2[$i])"/></after>
192
+	       </elementNameDifference>
193
+
194
+	  </xsl:if>
195
+	
196
+	  <!-- value compare -->
197
+	
198
+	  <xsl:if test="count($ns2/*) = 0">
199
+	     <xsl:if test="$ns2[$i] != $ns1[$i]">
200
+		 <elementValueDifference>
201
+		   <parentElement><xsl:value-of select="name(..)"/></parentElement>
202
+		   <after><xsl:value-of select="$ns2[$i]"/></after>
203
+                   <before><xsl:value-of select="$ns1[$i]"/></before>
204
+		 </elementValueDifference>
205
+	     </xsl:if>
206
+	  </xsl:if>
207
+	
208
+        </xsl:for-each>
209
+      </xsl:otherwise>
210
+    </xsl:choose>
211
+	
212
+  <!-- stop processing when leaf node is reached. -->
213
+
214
+    <xsl:if test="count($ns1/*) &gt; 0 and count($ns2/*) &gt; 0">
215
+      <xsl:call-template name="cmp:diff">
216
+            <xsl:with-param name="ns1" select="$ns1/*"/>
217
+            <xsl:with-param name="ns2" select="$ns2/*"/>
218
+        </xsl:call-template>
219
+    </xsl:if>
220
+
221
+  </xsl:template>
222
+
223
+  <!-- Return false if the two nodesets are not identical
224
+  -->
225
+
226
+  <xsl:template name="cmp:cmp">
227
+   <xsl:param name="ns1"/>     	
228
+   <xsl:param name="ns2"/>     	
229
+   <xsl:param name="depth"/>
230
+
231
+   <xsl:choose>
232
+     <xsl:when test='count($ns1) != count($ns2)'>
233
+       <xsl:value-of select='"countDiff"'/>
234
+     </xsl:when>
235
+     <xsl:when test='count($ns1/attribute::*) != count($ns2/attribute::*)'>
236
+       <xsl:value-of select='"countDiff"'/>
237
+     </xsl:when>
238
+     <xsl:when test='$ns1 and $ns2'>
239
+
240
+       <xsl:variable name='result'>
241
+	<xsl:call-template name='cmp:cmp'>
242
+	  <xsl:with-param name='ns1' select='$ns1/*'/>
243
+	  <xsl:with-param name='ns2' select='$ns2/*'/>
244
+	  <xsl:with-param name='depth' select='$depth+1'/>
245
+	</xsl:call-template>
246
+	</xsl:variable>	
247
+
248
+       <xsl:choose>
249
+	  <xsl:when test='$result = "countDiff"'>
250
+	    <xsl:value-of select='$result'/>
251
+	  </xsl:when>
252
+	  <xsl:when test='$result = "textDiff"'>
253
+	    <xsl:value-of select='$result'/>
254
+	  </xsl:when>	  
255
+	  <xsl:when test='$result = ""'>
256
+
257
+	    <xsl:variable name='keyText1' select='name($ns1)'/>
258
+	    <xsl:variable name='keyText2' select='name($ns2)'/>
259
+	    	    
260
+	    <xsl:choose>
261
+	      <!-- Check if the text of the nodesets are the same and the attributes-->
262
+	      <xsl:when test='$ns1 = $ns2 and $keyText1 = $keyText2'>
263
+
264
+		<!-- Check the attribute names are the same -->
265
+		<!-- Number of attributes being different is caught higher up -->
266
+		<xsl:if test='count($ns1/attribute::*)'>
267
+		  <xsl:for-each select='$ns1/attribute::*'>
268
+		    <xsl:variable name='i' select='position()'/>
269
+		    <xsl:variable name='name1' select='name(.)'/>
270
+                    <xsl:variable name='value1' select='.'/>
271
+		    
272
+		    <xsl:for-each select='$ns2/attribute::*'>
273
+		      <xsl:variable name='j' select='position()'/>
274
+		      <xsl:variable name='name2' select='name(.)'/>
275
+                      <xsl:variable name='value2' select='.'/>
276
+
277
+                      <xsl:if test='$i = $j and ($name1 != $name2 or 
278
+                                    $value1 != $value2)'>
279
+			<xsl:value-of select='"textDiff"'/>
280
+		      </xsl:if>
281
+		      
282
+		    </xsl:for-each>
283
+		  </xsl:for-each>
284
+		</xsl:if>
285
+		<!--
286
+		<xsl:variable name='diffResult'>
287
+		  <xsl:call-template name='cmp:diff'>
288
+		    <xsl:with-param name='ns1' select='$ns1'/>
289
+		    <xsl:with-param name='ns2' select='$ns2'/>
290
+		  </xsl:call-template>
291
+		</xsl:variable>
292
+		
293
+		<xsl:if test='not($diffResult = "")'>
294
+		  <xsl:value-of select='"textDiff"'/>
295
+		</xsl:if>
296
+		-->
297
+
298
+	      </xsl:when>
299
+	      <xsl:otherwise>
300
+		<xsl:value-of select='"textDiff"'/>
301
+	      </xsl:otherwise>
302
+	    </xsl:choose>
303
+	  </xsl:when>
304
+	</xsl:choose>
305
+	  
306
+     </xsl:when>
307
+     <xsl:when test='$ns1 and not($ns2)'>
308
+       <xsl:value-of select='"structDiff"'/>
309
+     </xsl:when>
310
+     <xsl:when test='$ns2 and not($ns1)'>
311
+       <xsl:value-of select='"structDiff"'/>
312
+     </xsl:when>
313
+   </xsl:choose>
314
+
315
+  </xsl:template>
316
+
317
+</xsl:stylesheet>
318
+

+ 1447
- 0
texml-xsl/date-time.xsl
File diff suppressed because it is too large
View File


+ 90
- 0
texml-xsl/example.xsl View File

@@ -0,0 +1,90 @@
1
+<?xml version="1.0"?>
2
+
3
+<xsl:stylesheet
4
+  version="1.0"
5
+  extension-element-prefixes="doc"
6
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
7
+  xmlns:doc="http://xsltsl.org/xsl/documentation/1.0"
8
+  xmlns:eg="http://xsltsl.org/example"
9
+>
10
+
11
+  <doc:reference xmlns="">
12
+    <referenceinfo>
13
+      <releaseinfo role="meta">
14
+        $Id$
15
+      </releaseinfo>
16
+      <author>
17
+        <surname>Ball</surname>
18
+        <firstname>Steve</firstname>
19
+      </author>
20
+      <copyright>
21
+        <year>2001</year>
22
+        <holder>Steve Ball</holder>
23
+      </copyright>
24
+    </referenceinfo>
25
+
26
+    <title>Example Stylesheet</title>
27
+
28
+    <partintro>
29
+      <section>
30
+        <title>Introduction</title>
31
+
32
+        <para>This module provides a template for adding stylesheet modules to the XSLT Standard Library.</para>
33
+        <para>To add a new module to the library, follow these easy steps:</para>
34
+        <orderedlist>
35
+          <listitem>
36
+            <para>Copy this file and replace its contents with the new module templates and documentation.</para>
37
+          </listitem>
38
+          <listitem>
39
+            <para>Copy the corresponding test file in the <filename>test</filename> directory.  Replace its contents with tests for the new module.</para>
40
+          </listitem>
41
+          <listitem>
42
+            <para>Add an include element in the <filename>stdlib.xsl</filename> stylesheet.</para>
43
+          </listitem>
44
+          <listitem>
45
+            <para>Add an entry in the <filename>test/test.xml</filename> file.</para>
46
+          </listitem>
47
+          <listitem>
48
+            <para>Add entries in the <filename>test/test.xsl</filename> stylesheet.</para>
49
+          </listitem>
50
+          <listitem>
51
+            <para>Add an entry in the <filename>doc/build.xml</filename> file.</para>
52
+          </listitem>
53
+        </orderedlist>
54
+
55
+        <para>The <filename>example.xsl</filename> stylesheet provides a more extensive example.</para>
56
+
57
+      </section>
58
+    </partintro>
59
+
60
+  </doc:reference>
61
+
62
+  <doc:template name="eg:example" xmlns="">
63
+    <refpurpose>Template Example</refpurpose>
64
+
65
+    <refdescription>
66
+      <para>Provides a template for writing templates.  Replace this paragraph with a description of your template</para>
67
+    </refdescription>
68
+
69
+    <refparameter>
70
+      <variablelist>
71
+        <varlistentry>
72
+          <term>text</term>
73
+          <listitem>
74
+            <para>The example string</para>
75
+          </listitem>
76
+        </varlistentry>
77
+      </variablelist>
78
+    </refparameter>
79
+
80
+    <refreturn>
81
+      <para>Returns nothing.</para>
82
+    </refreturn>
83
+  </doc:template>
84
+
85
+  <xsl:template name="eg:example">
86
+    <xsl:param name="text"/>
87
+  </xsl:template>
88
+
89
+</xsl:stylesheet>
90
+

+ 789
- 0
texml-xsl/markup.xsl View File

@@ -0,0 +1,789 @@
1
+<xsl:stylesheet version='1.0'
2
+  xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
3
+  xmlns:doc='http://xsltsl.org/xsl/documentation/1.0'
4
+  xmlns:markup='http://xsltsl.org/markup'
5
+  xmlns:str='http://xsltsl.org/string'
6
+  extension-element-prefixes='doc markup str'>
7
+
8
+  <doc:reference xmlns=''>
9
+    <referenceinfo>
10
+      <releaseinfo role="meta">
11
+	$Id$
12
+      </releaseinfo>
13
+      <author>
14
+	<surname>Ball</surname>
15
+	<firstname>Steve</firstname>
16
+      </author>
17
+      <copyright>
18
+	<year>2003</year>
19
+	<year>2001</year>
20
+	<holder>Steve Ball</holder>
21
+      </copyright>
22
+    </referenceinfo>
23
+
24
+    <title>XML Markup Templates</title>
25
+
26
+    <partintro>
27
+      <section>
28
+	<title>Introduction</title>
29
+
30
+	<para>This stylesheet module provides functions for generating literal XML markup.</para>
31
+
32
+      </section>
33
+    </partintro>
34
+
35
+  </doc:reference>
36
+
37
+  <doc:template name="markup:xml-declaration" xmlns="">
38
+    <refpurpose>Create an XML Declaration</refpurpose>
39
+
40
+    <refdescription>
41
+      <para>This template returns an XML Declaration.  Although the XSLT standard provides control over the generation of the XML Declaration, this template may be useful in circumstances where the values must be computed at runtime.</para>
42
+    </refdescription>
43
+
44
+    <refparameter>
45
+      <variablelist>
46
+	<varlistentry>
47
+	  <term>version</term>
48
+	  <listitem>
49
+	    <para>Version number.</para>
50
+	  </listitem>
51
+	</varlistentry>
52
+	<varlistentry>
53
+	  <term>standalone</term>
54
+	  <listitem>
55
+	    <para>Standalone indication.  Must be value "yes" or "no".</para>
56
+	  </listitem>
57
+	</varlistentry>
58
+	<varlistentry>
59
+	  <term>encoding</term>
60
+	  <listitem>
61
+	    <para>Character encoding.</para>
62
+	  </listitem>
63
+	</varlistentry>
64
+      </variablelist>
65
+    </refparameter>
66
+
67
+    <refreturn>
68
+      <para>Returns an XML Declaration as a string.</para>
69
+    </refreturn>
70
+  </doc:template>
71
+
72
+  <xsl:template name='markup:xml-declaration'>
73
+    <xsl:param name='version' select="'1.0'"/>
74
+    <xsl:param name='standalone'/>
75
+    <xsl:param name='encoding'/>
76
+
77
+    <xsl:text disable-output-escaping='yes'>&lt;?xml version="</xsl:text>
78
+    <xsl:copy-of select="$version"/>
79
+    <xsl:text>"</xsl:text>
80
+
81
+    <xsl:choose>
82
+      <xsl:when test="string-length($standalone) = 0"/>
83
+      <xsl:when test='$standalone = "yes" or $standalone = "no"'>
84
+        <xsl:text> standalone="</xsl:text>
85
+        <xsl:copy-of select="$standalone"/>
86
+        <xsl:text>"</xsl:text>
87
+      </xsl:when>
88
+      <xsl:otherwise>
89
+        <xsl:message terminate="yes">invalid value "<xsl:value-of select="$standalone"/>" for standalone attribute</xsl:message>
90
+      </xsl:otherwise>
91
+    </xsl:choose>
92
+
93
+    <xsl:if test='string-length($encoding) &gt; 0'>
94
+      <xsl:text> encoding="</xsl:text>
95
+      <xsl:copy-of select='$encoding'/>
96
+      <xsl:text>"</xsl:text>
97
+    </xsl:if>
98
+
99
+    <xsl:text disable-output-escaping='yes'>?&gt;
100
+</xsl:text>
101
+  </xsl:template>
102
+
103
+  <doc:template name="markup:doctype-declaration" xmlns="">
104
+    <refpurpose>Create a Document Type Declaration</refpurpose>
105
+
106
+    <refdescription>
107
+      <para>This template returns a Document Type Declaration.  Although the XSLT standard provides control over the generation of a Document Type Declaration, this template may be useful in circumstances where the values for the identifiers or the internal subset must be computed at runtime.</para>
108
+    </refdescription>
109
+
110
+    <refparameter>
111
+      <variablelist>
112
+	<varlistentry>
113
+	  <term>docel</term>
114
+	  <listitem>
115
+	    <para>The name of the document element.</para>
116
+	  </listitem>
117
+	</varlistentry>
118
+	<varlistentry>
119
+	  <term>publicid</term>
120
+	  <listitem>
121
+	    <para>The public identifier for the external DTD subset.</para>
122
+	  </listitem>
123
+	</varlistentry>
124
+	<varlistentry>
125
+	  <term>systemid</term>
126
+	  <listitem>
127
+	    <para>The system identifier for the external DTD subset.</para>
128
+	  </listitem>
129
+	</varlistentry>
130
+	<varlistentry>
131
+	  <term>internaldtd</term>
132
+	  <listitem>
133
+	    <para>The internal DTD subset.</para>
134
+	  </listitem>
135
+	</varlistentry>
136
+      </variablelist>
137
+    </refparameter>
138
+
139
+    <refreturn>
140
+      <para>Returns a Document Type Declaration as a string.</para>
141
+    </refreturn>
142
+  </doc:template>
143
+
144
+  <xsl:template name='markup:doctype-declaration'>
145
+    <xsl:param name='docel'/>
146
+    <xsl:param name='publicid'/>
147
+    <xsl:param name='systemid'/>
148
+    <xsl:param name='internaldtd'/>
149
+
150
+    <xsl:if test='string-length($docel) = 0'>
151
+      <xsl:message terminate='yes'>No document element specified</xsl:message>
152
+    </xsl:if>
153
+
154
+    <xsl:text disable-output-escaping='yes'>&lt;!DOCTYPE </xsl:text>
155
+    <xsl:copy-of select="$docel"/>
156
+
157
+    <xsl:call-template name='markup:external-identifier'>
158
+      <xsl:with-param name='publicid' select='$publicid'/>
159
+      <xsl:with-param name='systemid' select='$systemid'/>
160
+      <xsl:with-param name='leading-space' select='true()'/>
161
+    </xsl:call-template>
162
+
163
+    <xsl:if test='string-length($internaldtd) &gt; 0'>
164
+      <xsl:text> [</xsl:text>
165
+      <xsl:copy-of select='$internaldtd'/>
166
+      <xsl:text>]</xsl:text>
167
+    </xsl:if>
168
+
169
+    <xsl:text disable-output-escaping='yes'>&gt;
170
+</xsl:text>
171
+  </xsl:template>
172
+
173
+  <doc:template name="markup:element-declaration" xmlns="">
174
+    <refpurpose>Create an Element Declaration</refpurpose>
175
+
176
+    <refdescription>
177
+      <para>This template returns an element declaration..</para>
178
+    </refdescription>
179
+
180
+    <refparameter>
181
+      <variablelist>
182
+	<varlistentry>
183
+	  <term>type</term>
184
+	  <listitem>
185
+	    <para>The element type.</para>
186
+	  </listitem>
187
+	</varlistentry>
188
+	<varlistentry>
189
+	  <term>content-spec</term>
190
+	  <listitem>
191
+	    <para>The content specification.</para>
192
+	  </listitem>
193
+	</varlistentry>
194
+      </variablelist>
195
+    </refparameter>
196
+
197
+    <refreturn>
198
+      <para>Returns an element declaration as a string.</para>
199
+    </refreturn>
200
+  </doc:template>
201
+
202
+  <xsl:template name='markup:element-declaration'>
203
+    <xsl:param name='type'/>
204
+    <xsl:param name='content-spec' select="'ANY'"/>
205
+
206
+    <xsl:if test='string-length($type) = 0'>
207
+      <xsl:message terminate='yes'>element type must be specified</xsl:message>
208
+    </xsl:if>
209
+    <xsl:if test='string-length($content-spec) = 0'>
210
+      <xsl:message terminate='yes'>content specification must be specified</xsl:message>
211
+    </xsl:if>
212
+
213
+    <xsl:text disable-output-escaping='yes'>&lt;!ELEMENT </xsl:text>
214
+    <xsl:copy-of select='$type'/>
215
+    <xsl:text> </xsl:text>
216
+    <xsl:copy-of select='$content-spec'/>
217
+    <xsl:text disable-output-escaping='yes'>&gt;</xsl:text>
218
+  </xsl:template>
219
+
220
+  <doc:template name="markup:attlist-declaration" xmlns="">
221
+    <refpurpose>Create an Attribute List Declaration</refpurpose>
222
+
223
+    <refdescription>
224
+      <para>This template returns an attribute list declaration.</para>
225
+    </refdescription>
226
+
227
+    <refparameter>
228
+      <variablelist>
229
+	<varlistentry>
230
+	  <term>type</term>
231
+	  <listitem>
232
+	    <para>The element type.</para>
233
+	  </listitem>
234
+	</varlistentry>
235
+	<varlistentry>
236
+	  <term>attr-defns</term>
237
+	  <listitem>
238
+	    <para>Attribute definitions.</para>
239
+	  </listitem>
240
+	</varlistentry>
241
+      </variablelist>
242
+    </refparameter>
243
+
244
+    <refreturn>
245
+      <para>Returns an attribute list declaration as a string.</para>
246
+    </refreturn>
247
+  </doc:template>
248
+
249
+  <xsl:template name='markup:attlist-declaration'>
250
+    <xsl:param name='type'/>
251
+    <xsl:param name='attr-defns'/>
252
+
253
+    <xsl:if test='string-length($type) = 0'>
254
+      <xsl:message terminate='yes'>element type must be specified</xsl:message>
255
+    </xsl:if>
256
+
257
+    <xsl:text disable-output-escaping='yes'>&lt;!ATTLIST </xsl:text>
258
+    <xsl:copy-of select='$type'/>
259
+    <xsl:text> </xsl:text>
260
+    <xsl:copy-of select='$attr-defns'/>
261
+    <xsl:text disable-output-escaping='yes'>&gt;</xsl:text>
262
+  </xsl:template>
263
+
264
+  <doc:template name="markup:attribute-definition" xmlns="">
265
+    <refpurpose>Create an Attribute Definition</refpurpose>
266
+
267
+    <refdescription>
268
+      <para>This template returns an attribute definition.</para>
269
+    </refdescription>
270
+
271
+    <refparameter>
272
+      <variablelist>
273
+	<varlistentry>
274
+	  <term>name</term>
275
+	  <listitem>
276
+	    <para>The attribute name.</para>
277
+	  </listitem>
278
+	</varlistentry>
279
+	<varlistentry>
280
+	  <term>type</term>
281
+	  <listitem>
282
+	    <para>The attribute type.</para>
283
+	  </listitem>
284
+	</varlistentry>
285
+	<varlistentry>
286
+	  <term>default</term>
287
+	  <listitem>
288
+	    <para>The attribute default.</para>
289
+	  </listitem>
290
+	</varlistentry>
291
+      </variablelist>
292
+    </refparameter>
293
+
294
+    <refreturn>
295
+      <para>Returns an attribute definition as a string.</para>
296
+    </refreturn>
297
+  </doc:template>
298
+
299
+  <xsl:template name='markup:attribute-definition'>
300
+    <xsl:param name='name'/>
301
+    <xsl:param name='type'/>
302
+    <xsl:param name='default'/>
303
+
304
+    <xsl:if test='string-length($name) = 0'>
305
+      <xsl:message terminate='yes'>attribute name must be specified</xsl:message>
306
+    </xsl:if>
307
+    <xsl:if test='string-length($type) = 0'>
308
+      <xsl:message terminate='yes'>attribute type must be specified</xsl:message>
309
+    </xsl:if>
310
+    <xsl:if test='string-length($default) = 0'>
311
+      <xsl:message terminate='yes'>attribute default must be specified</xsl:message>
312
+    </xsl:if>
313
+
314
+    <xsl:text> </xsl:text>
315
+    <xsl:copy-of select='$name'/>
316
+    <xsl:text> </xsl:text>
317
+    <xsl:copy-of select='$type'/>
318
+    <xsl:text> </xsl:text>
319
+    <xsl:copy-of select='$default'/>
320
+  </xsl:template>
321
+
322
+  <doc:template name="markup:entity-declaration" xmlns="">
323
+    <refpurpose>Create an Entity Declaration</refpurpose>
324
+
325
+    <refdescription>
326
+      <para>This template returns an entity declaration.</para>
327
+      <para>If the 'text' parameter is given a value, then an internal entity is created.  If either the 'publicid' or 'systemid' parameters are given a value then an external entity is created.  It is an error for the 'text' parameter to have value as well as the 'publicid', 'systemid' or 'notation' parameters.</para>
328
+    </refdescription>
329
+
330
+    <refparameter>
331
+      <variablelist>
332
+	<varlistentry>
333
+	  <term>name</term>
334
+	  <listitem>
335
+	    <para>The entity name.</para>
336
+	  </listitem>
337
+	</varlistentry>
338
+	<varlistentry>
339
+	  <term>parameter</term>
340
+	  <listitem>
341
+	    <para>Boolean value to determine whether a parameter entity is created.  Default is 'false()'.</para>
342
+	  </listitem>
343
+	</varlistentry>
344
+	<varlistentry>
345
+	  <term>text</term>
346
+	  <listitem>
347
+	    <para>The replacement text.  Must be a string.</para>
348
+	  </listitem>
349
+	</varlistentry>
350
+	<varlistentry>
351
+	  <term>nodes</term>
352
+	  <listitem>
353
+	    <para>The replacement text as a nodeset.  The nodeset is formatted as XML using the as-xml template.  If both text and nodes are specified then nodes takes precedence.</para>
354
+	  </listitem>
355
+	</varlistentry>
356
+	<varlistentry>
357
+	  <term>publicid</term>
358
+	  <listitem>
359
+	    <para>The public identifier for an external entity.</para>
360
+	  </listitem>
361
+	</varlistentry>
362
+	<varlistentry>
363
+	  <term>systemid</term>
364
+	  <listitem>
365
+	    <para>The system identifier for an external entity.</para>
366
+	  </listitem>
367
+	</varlistentry>
368
+ 	<varlistentry>
369
+	  <term>notation</term>
370
+	  <listitem>
371
+	    <para>The notation for an external entity.</para>
372
+	  </listitem>
373
+	</varlistentry>
374
+      </variablelist>
375
+    </refparameter>
376
+
377
+    <refreturn>
378
+      <para>Returns an entity declaration as a string.</para>
379
+    </refreturn>
380
+  </doc:template>
381
+
382
+  <xsl:template name='markup:entity-declaration'>
383
+    <xsl:param name='name'/>
384
+    <xsl:param name='parameter' select='false()'/>
385
+    <xsl:param name='text'/>
386
+    <xsl:param name='nodes'/>
387
+    <xsl:param name='publicid'/>
388
+    <xsl:param name='systemid'/>
389
+    <xsl:param name='notation'/>
390
+
391
+    <xsl:if test='string-length($name) = 0'>
392
+      <xsl:message terminate='yes'>entity name must be specified</xsl:message>
393
+    </xsl:if>
394
+    <xsl:if test='string-length($text) &gt; 0 and 
395
+                  (string-length($publicid) &gt; 0 or
396
+                   string-length($systemid) &gt; 0 or
397
+                   string-length($notation) &gt; 0)'>
398
+      <xsl:message terminate='yes'>both replacement text and external identifier specified</xsl:message>
399
+    </xsl:if>
400
+
401
+    <xsl:text disable-output-escaping='yes'>&lt;!ENTITY </xsl:text>
402
+    <xsl:copy-of select='$name'/>
403
+    <xsl:text> </xsl:text>
404
+    <xsl:if test="$parameter">
405
+      <xsl:text>% </xsl:text>
406
+    </xsl:if>
407
+
408
+    <xsl:choose>
409
+      <xsl:when test="$nodes">
410
+        <xsl:call-template name='markup:quote-value'>
411
+          <xsl:with-param name='value'>
412
+            <xsl:call-template name="markup:as-xml">
413
+              <xsl:with-param name="nodes" select="$nodes"/>
414
+            </xsl:call-template>
415
+          </xsl:with-param>
416
+        </xsl:call-template>
417
+      </xsl:when>
418
+      <xsl:when test='$text'>
419
+        <xsl:call-template name='markup:quote-value'>
420
+          <xsl:with-param name='value' select='$text'/>
421
+        </xsl:call-template>
422
+      </xsl:when>
423
+      <xsl:otherwise>
424
+        <xsl:call-template name='markup:external-identifier'>
425
+          <xsl:with-param name='publicid' select='$publicid'/>
426
+          <xsl:with-param name='systemid' select='$systemid'/>
427
+        </xsl:call-template>
428
+      </xsl:otherwise>
429
+    </xsl:choose>
430
+
431
+    <xsl:if test='$notation'>
432
+      <xsl:text> NDATA "</xsl:text>
433
+      <xsl:copy-of select='$notation'/>
434
+      <xsl:text>"</xsl:text>
435
+    </xsl:if>
436
+
437
+    <xsl:text disable-output-escaping='yes'>&gt;</xsl:text>
438
+  </xsl:template>
439
+
440
+  <doc:template name="markup:quote-value" xmlns="">
441
+    <refpurpose>Quote an Attribute Value</refpurpose>
442
+
443
+    <refdescription>
444
+      <para>This template returns a quoted value.</para>
445
+    </refdescription>
446
+
447
+    <refparameter>
448
+      <variablelist>
449
+	<varlistentry>
450
+	  <term>value</term>
451
+	  <listitem>
452
+	    <para>The value to quote.</para>
453
+	  </listitem>
454
+	</varlistentry>
455
+      </variablelist>
456
+    </refparameter>
457
+
458
+    <refreturn>
459
+      <para>Returns a quote value as a string.</para>
460
+    </refreturn>
461
+  </doc:template>
462
+
463
+  <xsl:template name='markup:quote-value'>
464
+    <xsl:param name='value'/>
465
+
466
+    <xsl:variable name="quoted">
467
+      <xsl:call-template name='markup:quote-value-aux'>
468
+        <xsl:with-param name='value' select='$value'/>
469
+      </xsl:call-template>
470
+    </xsl:variable>
471
+
472
+    <xsl:choose>
473
+      <xsl:when test="contains($value, '&lt;')">
474
+        <xsl:call-template name='str:subst'>
475
+          <xsl:with-param name='text' select='$quoted'/>
476
+          <xsl:with-param name='replace'>&lt;</xsl:with-param>
477
+          <xsl:with-param name='with'>
478
+            <xsl:text disable-output-escaping='yes'>&amp;lt;</xsl:text>
479
+          </xsl:with-param>
480
+        </xsl:call-template>
481
+      </xsl:when>
482
+      <xsl:otherwise>
483
+        <xsl:copy-of select='$quoted'/>
484
+      </xsl:otherwise>
485
+    </xsl:choose>
486
+  </xsl:template>
487
+
488
+  <xsl:template name='markup:quote-value-aux'>
489
+    <xsl:param name='value'/>
490
+
491
+    <!-- Quoting hell! -->
492
+    <xsl:variable name="quot">&quot;</xsl:variable>
493
+    <xsl:variable name="apos">&apos;</xsl:variable>
494
+
495
+    <xsl:choose>
496
+      <xsl:when test='contains($value, $quot) and contains($value, $apos)'>
497
+        <xsl:text>"</xsl:text>
498
+        <xsl:call-template name='str:subst'>
499
+          <xsl:with-param name='text' select='$value'/>
500
+          <xsl:with-param name='replace'>"</xsl:with-param>
501
+          <xsl:with-param name='with'>
502
+            <xsl:text disable-output-escaping='yes'>&amp;quot;</xsl:text>
503
+          </xsl:with-param>
504
+        </xsl:call-template>
505
+        <xsl:text>"</xsl:text>
506
+      </xsl:when>
507
+      <xsl:when test='contains($value, $quot)'>
508
+        <xsl:text>'</xsl:text>
509
+        <xsl:value-of select='$value'/>
510
+        <xsl:text>'</xsl:text>
511
+      </xsl:when>
512
+      <xsl:otherwise>
513
+        <xsl:text>"</xsl:text>
514
+        <xsl:value-of select='$value'/>
515
+        <xsl:text>"</xsl:text>
516
+      </xsl:otherwise>
517
+    </xsl:choose>
518
+  </xsl:template>
519
+
520
+  <doc:template name="markup:external-identifier" xmlns="">
521
+    <refpurpose>Create an External Identifier</refpurpose>
522
+
523
+    <refdescription>
524
+      <para>This template returns an external identifier.</para>
525
+    </refdescription>
526
+
527
+    <refparameter>
528
+      <variablelist>
529
+	<varlistentry>
530
+	  <term>publicid</term>
531
+	  <listitem>
532
+	    <para>The public identifier.</para>
533
+	  </listitem>
534
+	</varlistentry>
535
+	<varlistentry>
536
+	  <term>systemid</term>
537
+	  <listitem>
538
+	    <para>The system identifier.</para>
539
+	  </listitem>
540
+	</varlistentry>
541
+      </variablelist>
542
+    </refparameter>
543
+
544
+    <refreturn>
545
+      <para>Returns an external identifier as a string.</para>
546
+    </refreturn>
547
+  </doc:template>
548
+
549
+  <xsl:template name='markup:external-identifier'>
550
+    <xsl:param name='publicid'/>
551
+    <xsl:param name='systemid'/>
552
+    <xsl:param name='leading-space' select='false()'/>
553
+
554
+    <xsl:choose>
555
+      <xsl:when test='string-length($publicid) &gt; 0'>
556
+        <xsl:if test='$leading-space'>
557
+          <xsl:text> </xsl:text>
558
+        </xsl:if>
559
+        <xsl:text disable-output-escaping='yes'>PUBLIC "</xsl:text>
560
+        <xsl:value-of select='$publicid' disable-output-escaping='yes'/>
561
+        <xsl:text disable-output-escaping='yes'>"</xsl:text>
562
+        <xsl:if test='string-length($systemid) &gt; 0'>
563
+          <xsl:text disable-output-escaping='yes'> "</xsl:text>
564
+          <xsl:value-of select='$systemid' disable-output-escaping='yes'/>
565
+          <xsl:text disable-output-escaping='yes'>"</xsl:text>
566
+        </xsl:if>
567
+      </xsl:when>
568
+      <xsl:when test="string-length($systemid) &gt; 0">
569
+        <xsl:if test='$leading-space'>
570
+          <xsl:text> </xsl:text>
571
+        </xsl:if>
572
+        <xsl:text disable-output-escaping='yes'>SYSTEM "</xsl:text>
573
+        <xsl:value-of select='$systemid' disable-output-escaping='yes'/>
574
+        <xsl:text disable-output-escaping='yes'>"</xsl:text>
575
+      </xsl:when>
576
+    </xsl:choose>
577
+  </xsl:template>
578
+
579
+  <doc:template name="markup:entity-reference" xmlns="">
580
+    <refpurpose>Create an Entity Reference</refpurpose>
581
+
582
+    <refdescription>
583
+      <para>This template returns an entity reference.</para>
584
+    </refdescription>
585
+
586
+    <refparameter>
587
+      <variablelist>
588
+	<varlistentry>
589
+	  <term>name</term>
590
+	  <listitem>
591
+	    <para>The name of the entity.</para>
592
+	  </listitem>
593
+	</varlistentry>
594
+      </variablelist>
595
+    </refparameter>
596
+
597
+    <refreturn>
598
+      <para>Returns an entity reference as a string.</para>
599
+    </refreturn>
600
+  </doc:template>
601
+
602
+  <xsl:template name='markup:entity-reference'>
603
+    <xsl:param name='name'/>
604
+
605
+    <xsl:text disable-output-escaping='yes'>&amp;</xsl:text>
606
+    <xsl:value-of select='$name'/>
607
+    <xsl:text>;</xsl:text>
608
+
609
+  </xsl:template>
610
+
611
+  <doc:template name="markup:notation-declaration" xmlns="">
612
+    <refpurpose>Create a Notation Declaration</refpurpose>
613
+
614
+    <refdescription>
615
+      <para>This template returns a notation declaration.</para>
616
+    </refdescription>
617
+
618
+    <refparameter>
619
+      <variablelist>
620
+	<varlistentry>
621
+	  <term>name</term>
622
+	  <listitem>
623
+	    <para>The notation name.</para>
624
+	  </listitem>
625
+	</varlistentry>
626
+	<varlistentry>
627
+	  <term>publicid</term>
628
+	  <listitem>
629
+	    <para>The public identifier for the notation.</para>
630
+	  </listitem>
631
+	</varlistentry>
632
+	<varlistentry>
633
+	  <term>systemid</term>
634
+	  <listitem>
635
+	    <para>The system identifier for the notation.</para>
636
+	  </listitem>
637
+	</varlistentry>
638
+      </variablelist>
639
+    </refparameter>
640
+
641
+    <refreturn>
642
+      <para>Returns a notation declaration as a string.</para>
643
+    </refreturn>
644
+  </doc:template>
645
+
646
+  <xsl:template name='markup:notation-declaration'>
647
+    <xsl:param name='name'/>
648
+    <xsl:param name='publicid'/>
649
+    <xsl:param name='systemid'/>
650
+
651
+    <xsl:if test='string-length($name) = 0'>
652
+      <xsl:message terminate='yes'>notation name must be specified</xsl:message>
653
+    </xsl:if>
654
+    <xsl:if test='string-length($publicid) = 0 and string-length($systemid) = 0'>
655
+      <xsl:message terminate='yes'>external identifier must be specified</xsl:message>
656
+    </xsl:if>
657
+
658
+    <xsl:text disable-output-escaping='yes'>&lt;!NOTATION </xsl:text>
659
+    <xsl:copy-of select='$name'/>
660
+
661
+    <xsl:call-template name='markup:external-identifier'>
662
+      <xsl:with-param name='publicid' select='$publicid'/>
663
+      <xsl:with-param name='systemid' select='$systemid'/>
664
+      <xsl:with-param name='leading-space' select='true()'/>
665
+    </xsl:call-template>
666
+
667
+    <xsl:text disable-output-escaping='yes'>&gt;</xsl:text>
668
+  </xsl:template>
669
+
670
+  <doc:template name="markup:cdata-section" xmlns="">
671
+    <refpurpose>Create a CDATA Section</refpurpose>
672
+
673
+    <refdescription>
674
+      <para>This template returns a CDATA Section.  The XSLT specification provides a mechanism for instructing the XSL processor to output character data in a CDATA section for certain elements, but this template may be useful in those circumstances where not all instances of an element are to have their content placed in a CDATA section.</para>
675
+    </refdescription>
676
+
677
+    <refparameter>
678
+      <variablelist>
679
+	<varlistentry>
680
+	  <term>text</term>
681
+	  <listitem>
682
+	    <para>The content of the CDATA section.</para>
683
+	  </listitem>
684
+	</varlistentry>
685
+      </variablelist>
686
+    </refparameter>
687
+
688
+    <refreturn>
689
+      <para>Returns a CDATA section as a string.</para>
690
+    </refreturn>
691
+  </doc:template>
692
+
693
+  <xsl:template name='markup:cdata-section'>
694
+    <xsl:param name='text'/>
695
+
696
+    <xsl:if test="contains($text, ']]&gt;')">
697
+      <xsl:message terminate="yes">CDATA section contains "]]&gt;"</xsl:message>
698
+    </xsl:if>
699
+
700
+    <xsl:text disable-output-escaping='yes'>&lt;![CDATA[</xsl:text>
701
+    <xsl:copy-of select='$text'/>
702
+    <xsl:text disable-output-escaping='yes'>]]&gt;</xsl:text>
703
+  </xsl:template>
704
+
705
+  <doc:template name="markup:as-xml" xmlns="">
706
+    <refpurpose>Format Nodeset As XML Markup</refpurpose>
707
+
708
+    <refdescription>
709
+      <para>This template returns XML markup.  Each node in the given nodeset is converted to its equivalent XML markup.</para>
710
+
711
+      <para>BUG: This version may not adequately handle XML Namespaces.</para>
712
+    </refdescription>
713
+
714
+    <refparameter>
715
+      <variablelist>
716
+	<varlistentry>
717
+	  <term>nodes</term>
718
+	  <listitem>
719
+	    <para>Nodeset to format as XML.</para>
720
+	  </listitem>
721
+	</varlistentry>
722
+      </variablelist>
723
+    </refparameter>
724
+
725
+    <refreturn>
726
+      <para>Returns XML markup.</para>
727
+    </refreturn>
728
+  </doc:template>
729
+
730
+  <xsl:template name='markup:as-xml'>
731
+    <xsl:param name='nodes'/>
732
+
733
+    <xsl:if test="$nodes">
734
+      <xsl:choose>
735
+        <xsl:when test="$nodes[1]/self::*">
736
+          <xsl:text disable-output-escaping='yes'>&lt;</xsl:text>
737
+          <xsl:value-of select="name($nodes[1])"/>
738
+          <xsl:for-each select="$nodes[1]/@*">
739
+            <xsl:text> </xsl:text>
740
+            <xsl:value-of select="name()"/>
741
+            <xsl:text>=</xsl:text>
742
+            <xsl:call-template name='markup:quote-value'>
743
+              <xsl:with-param name='value' select='.'/>
744
+            </xsl:call-template>
745
+          </xsl:for-each>
746
+
747
+          <xsl:choose>
748
+            <xsl:when test='$nodes[1]/node()'>
749
+              <xsl:text disable-output-escaping='yes'>&gt;</xsl:text>
750
+              <xsl:call-template name='markup:as-xml'>
751
+                <xsl:with-param name='nodes' select='$nodes[1]/node()'/>
752
+              </xsl:call-template>
753
+              <xsl:text disable-output-escaping='yes'>&lt;/</xsl:text>
754
+              <xsl:value-of select="name($nodes[1])"/>
755
+              <xsl:text disable-output-escaping='yes'>&gt;</xsl:text>
756
+            </xsl:when>
757
+            <xsl:otherwise>
758
+              <xsl:text disable-output-escaping='yes'>/&gt;</xsl:text>
759
+            </xsl:otherwise>
760
+          </xsl:choose>
761
+        </xsl:when>
762
+        <xsl:when test="$nodes[1]/self::text()">
763
+          <xsl:value-of select="$nodes[1]"/>
764
+        </xsl:when>
765
+        <xsl:when test="$nodes[1]/self::comment()">
766
+          <xsl:text disable-output-escaping='yes'>&lt;!--</xsl:text>
767
+          <xsl:value-of select="$nodes[1]"/>
768
+          <xsl:text disable-output-escaping='yes'>--&gt;</xsl:text>
769
+        </xsl:when>
770
+        <xsl:when test="$nodes[1]/self::processing-instruction()">
771
+          <xsl:text disable-output-escaping='yes'>&lt;?</xsl:text>
772
+          <xsl:value-of select="name($nodes[1])"/>
773
+          <xsl:text> </xsl:text>
774
+          <xsl:value-of select="$nodes[1]"/>
775
+          <xsl:text disable-output-escaping='yes'>?&gt;</xsl:text>
776
+        </xsl:when>
777
+
778
+        <xsl:when test="not($nodes[1]/parent::*)"/> <!-- root node -->
779
+        <xsl:when test="count($nodes[1] | $nodes[1]/../namespace::*) = count($nodes[1]/../namespace::*)"/> <!-- namespace node -->
780
+        <xsl:when test="count($nodes[1] | $nodes[1]/../@*) = count($nodes[1]/../@*)"/> <!-- attribute node -->
781
+      </xsl:choose>
782
+
783
+      <xsl:call-template name="markup:as-xml">
784
+        <xsl:with-param name="nodes" select="$nodes[position() &gt; 1]"/>
785
+      </xsl:call-template>
786
+    </xsl:if>
787
+  </xsl:template>
788
+
789
+</xsl:stylesheet>

+ 618
- 0
texml-xsl/math.xsl View File

@@ -0,0 +1,618 @@
1
+<?xml version="1.0"?>
2
+<xsl:stylesheet version="1.0"
3
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4
+  xmlns:doc="http://xsltsl.org/xsl/documentation/1.0"
5
+  xmlns:math="http://xsltsl.org/math"
6
+  exclude-result-prefixes="doc math">
7
+
8
+  <doc:reference xmlns="">
9
+    <referenceinfo>
10
+      <releaseinfo role="meta">
11
+        $Id$
12
+      </releaseinfo>
13
+      <author>
14
+        <surname>Ball</surname>
15
+        <firstname>Steve</firstname>
16
+      </author>
17
+      <copyright>
18
+        <year>2004</year>
19
+        <year>2002</year>
20
+        <holder>Steve Ball</holder>
21
+      </copyright>
22
+    </referenceinfo>
23
+
24
+    <title>Math Module</title>
25
+
26
+    <partintro>
27
+      <section>
28
+        <title>Introduction</title>
29
+
30
+        <para>This module provides mathematical functions.</para>
31
+      </section>
32
+    </partintro>
33
+
34
+  </doc:reference>
35
+
36
+  <doc:template name="math:power" xmlns="">
37
+    <refpurpose>Power</refpurpose>
38
+
39
+    <refdescription>
40
+      <para>Raises a number to a power.</para>
41
+    </refdescription>
42
+
43
+    <refparameter>
44
+      <variablelist>
45
+        <varlistentry>
46
+          <term>base</term>
47
+          <listitem>
48
+            <para>The base number.  Must be a number.</para>
49
+          </listitem>
50
+        </varlistentry>
51
+        <varlistentry>
52
+          <term>power</term>
53
+          <listitem>
54
+            <para>The power to raise the number to.  Must be an integer.</para>
55
+          </listitem>
56
+        </varlistentry>
57
+      </variablelist>
58
+    </refparameter>
59
+
60
+    <refreturn>
61
+      <para>Returns base multiplied by itself power times.  If the base or power are not numbers or if the power is fractional then an empty string is returned.</para>
62
+    </refreturn>
63
+  </doc:template>
64
+
65
+  <xsl:template name="math:power">
66
+    <xsl:param name="base"/>
67
+    <xsl:param name="power"/>
68
+
69
+    <xsl:choose>
70
+      <xsl:when test='$power = "0" and $base = "0"'>
71
+        <xsl:text>1</xsl:text>
72
+      </xsl:when>
73
+      <xsl:when test='$power = "0" and number($base)'>
74
+        <xsl:text>1</xsl:text>
75
+      </xsl:when>
76
+      <xsl:when test='$power = "0" and not(number($base))'/>
77
+      <xsl:when test='$base = "0" and number($power)'>
78
+        <xsl:text>0</xsl:text>
79
+      </xsl:when>
80
+
81
+      <xsl:when test='not(number($base)) or not(number($power))'/>
82
+
83
+      <xsl:when test='floor(number($power)) != number($power)'/>
84
+
85
+      <xsl:when test='number($power) &lt; 0'>
86
+        <xsl:variable name='x'>
87
+          <xsl:call-template name='math:power'>
88
+            <xsl:with-param name='base' select='$base'/>
89
+            <xsl:with-param name='power' select='-1 * $power'/>
90
+          </xsl:call-template>
91
+        </xsl:variable>
92
+        <xsl:value-of select='1 div $x'/>
93
+      </xsl:when>
94
+
95
+      <xsl:when test='number($power) = 1'>
96
+        <xsl:value-of select='$base'/>
97
+      </xsl:when>
98
+
99
+      <xsl:when test='number($power) &gt; 0'>
100
+        <xsl:variable name='x'>
101
+          <xsl:call-template name='math:power'>
102
+            <xsl:with-param name='base' select='$base'/>
103
+            <xsl:with-param name='power' select='$power - 1'/>
104
+          </xsl:call-template>
105
+        </xsl:variable>
106
+        <xsl:value-of select='$base * $x'/>
107
+      </xsl:when>
108
+      <xsl:otherwise/>
109
+    </xsl:choose>
110
+  </xsl:template>
111
+
112
+  <doc:template name="math:cvt-hex-decimal" xmlns="">
113
+    <refpurpose>Conversion</refpurpose>
114
+
115
+    <refdescription>
116
+      <para>Converts a hexidecimal value to a decimal value.</para>
117
+    </refdescription>
118
+
119
+    <refparameter>
120
+      <variablelist>
121
+        <varlistentry>
122
+          <term>value</term>
123
+          <listitem>
124
+            <para>The hexidecimal number.  Must be a number in hexidecimal format.</para>
125
+          </listitem>
126
+        </varlistentry>
127
+      </variablelist>
128
+    </refparameter>
129
+
130
+    <refreturn>
131
+      <para>Returns the value as a decimal string.  If the value is not a number then a NaN value is returned.</para>
132
+    </refreturn>
133
+  </doc:template>
134
+
135
+  <xsl:template name="math:cvt-hex-decimal">
136
+    <xsl:param name="value"/>
137
+
138
+    <xsl:choose>
139
+      <xsl:when test='$value = ""'/>
140
+
141
+      <xsl:when test='string-length($value) = 1'>
142
+        <xsl:call-template name='math:cvt-hex-decimal-digit'>
143
+          <xsl:with-param name='digit' select='$value'/>
144
+        </xsl:call-template>
145
+      </xsl:when>
146
+      <xsl:otherwise>
147
+        <xsl:variable name='first-digit'>
148
+          <xsl:call-template name='math:cvt-hex-decimal-digit'>
149
+            <xsl:with-param name='digit' select='substring($value, 1, 1)'/>
150
+          </xsl:call-template>
151
+        </xsl:variable>
152
+        <xsl:variable name='remainder'>
153
+          <xsl:call-template name='math:cvt-hex-decimal'>
154
+            <xsl:with-param name='value' select='substring($value, 2)'/>
155
+          </xsl:call-template>
156
+        </xsl:variable>
157
+
158
+        <xsl:value-of select='$first-digit * 16 + $remainder'/>
159
+      </xsl:otherwise>
160
+    </xsl:choose>
161
+  </xsl:template>
162
+
163
+  <xsl:template name='math:cvt-hex-decimal-digit'>
164
+    <xsl:param name='digit' select='0'/>
165
+    <xsl:choose>
166
+      <xsl:when test='$digit &lt;= 9'>
167
+        <xsl:value-of select='$digit'/>
168
+      </xsl:when>
169
+      <xsl:when test='$digit = "a" or $digit = "A"'>10</xsl:when>
170
+      <xsl:when test='$digit = "b" or $digit = "B"'>11</xsl:when>
171
+      <xsl:when test='$digit = "c" or $digit = "C"'>12</xsl:when>
172
+      <xsl:when test='$digit = "d" or $digit = "D"'>13</xsl:when>
173
+      <xsl:when test='$digit = "e" or $digit = "E"'>14</xsl:when>
174
+      <xsl:when test='$digit = "f" or $digit = "F"'>15</xsl:when>
175
+    </xsl:choose>
176
+  </xsl:template>
177
+
178
+  <doc:template name="math:ordinal" xmlns="">
179
+    <refpurpose>Ordinal number</refpurpose>
180
+
181
+    <refdescription>
182
+      <para>Gives the ordinal number of a given counting number.  For example, 1 becomes "1st".</para>
183
+    </refdescription>
184
+
185
+    <refparameter>
186
+      <variablelist>
187
+        <varlistentry>
188
+          <term>number</term>
189
+          <listitem>
190
+            <para>An integer number.</para>
191
+          </listitem>
192
+        </varlistentry>
193
+      </variablelist>
194
+    </refparameter>
195
+
196
+    <refreturn>
197
+      <para>Returns the number with an ordinal suffix.</para>
198
+    </refreturn>
199
+  </doc:template>
200
+
201
+  <xsl:template name="math:ordinal">
202
+    <xsl:param name="number"/>
203
+
204
+    <xsl:choose>
205
+      <xsl:when test='$number &lt; 0'/>
206
+      <xsl:otherwise>
207
+        <xsl:value-of select='$number'/>
208
+        <xsl:choose>
209
+          <xsl:when test='$number = 11 or $number = 12 or $number = 13'>th</xsl:when>
210
+          <xsl:when test='$number mod 10 = 1'>st</xsl:when>
211
+          <xsl:when test='$number mod 10 = 2'>nd</xsl:when>
212
+          <xsl:when test='$number mod 10 = 3'>rd</xsl:when>
213
+          <xsl:otherwise>th</xsl:otherwise>
214
+        </xsl:choose>
215
+      </xsl:otherwise>
216
+    </xsl:choose>
217
+  </xsl:template>
218
+
219
+
220
+  <doc:template name="math:ordinal-as-word" xmlns="">
221
+    <refpurpose>Returns an ordinal number</refpurpose>
222
+
223
+    <refdescription>
224
+      <para>This template returns the ordinal number for a given counting number as a word.  For example "first" for 1.</para>
225
+      <para>Only handles numbers less than 10000000 (ten million).</para>
226
+    </refdescription>
227
+
228
+    <refparameter>
229
+      <variablelist>
230
+	<varlistentry>
231
+	  <term>number</term>
232
+	  <listitem>
233
+	    <para>The counting number.</para>
234
+	  </listitem>
235
+	</varlistentry>
236
+	<varlistentry>
237
+	  <term>conjunctive</term>
238
+	  <listitem>
239
+	    <para>Whether to add the word "and" to the result, for example "one hundred and first" rather than "one hundred first".  Default is "yes".</para>
240
+	  </listitem>
241
+	</varlistentry>
242
+      </variablelist>
243
+    </refparameter>
244
+
245
+    <refreturn>
246
+      <para>Returns the ordinal number as a string.</para>
247
+    </refreturn>
248
+  </doc:template>
249
+
250
+  <xsl:template name="math:ordinal-as-word">
251
+    <xsl:param name="number" select="0"/>
252
+    <xsl:param name='conjunctive' select='"yes"'/>
253
+    <xsl:param name='preceding' select='0'/>
254
+
255
+    <xsl:choose>
256
+      <xsl:when test='$preceding = 1 and $number = 0'/>
257
+      <xsl:when test='$number = 0'>zeroth</xsl:when>
258
+
259
+      <xsl:when test="$number &lt; 1 or $number != floor($number)"/>
260
+
261
+      <xsl:when test='$number = 1'>
262
+        <xsl:if test='$preceding = 1'> and </xsl:if>
263
+        <xsl:text>first</xsl:text>
264
+      </xsl:when>
265
+      <xsl:when test='$number = 2'>
266
+        <xsl:if test='$preceding = 1'> and </xsl:if>
267
+        <xsl:text>second</xsl:text>
268
+      </xsl:when>
269
+      <xsl:when test='$number = 3'>
270
+        <xsl:if test='$preceding = 1'> and </xsl:if>
271
+        <xsl:text>third</xsl:text>
272
+      </xsl:when>
273
+      <xsl:when test='$number = 4'>
274
+        <xsl:if test='$preceding = 1'> and </xsl:if>
275
+        <xsl:text>fourth</xsl:text>
276
+      </xsl:when>
277
+      <xsl:when test='$number = 5'>
278
+        <xsl:if test='$preceding = 1'> and </xsl:if>
279
+        <xsl:text>fifth</xsl:text>
280
+      </xsl:when>
281
+      <xsl:when test='$number = 6'>
282
+        <xsl:if test='$preceding = 1'> and </xsl:if>
283
+        <xsl:text>sixth</xsl:text>
284
+      </xsl:when>
285
+      <xsl:when test='$number = 7'>
286
+        <xsl:if test='$preceding = 1'> and </xsl:if>
287
+        <xsl:text>seventh</xsl:text>
288
+      </xsl:when>
289
+      <xsl:when test='$number = 8'>
290
+        <xsl:if test='$preceding = 1'> and </xsl:if>
291
+        <xsl:text>eighth</xsl:text>
292
+      </xsl:when>
293
+      <xsl:when test='$number = 9'>
294
+        <xsl:if test='$preceding = 1'> and </xsl:if>
295
+        <xsl:text>ninth</xsl:text>
296
+      </xsl:when>
297
+      <xsl:when test='$number = 10'>
298
+        <xsl:if test='$preceding = 1'> and </xsl:if>
299
+        <xsl:text>tenth</xsl:text>
300
+      </xsl:when>
301
+      <xsl:when test='$number = 11'>
302
+        <xsl:if test='$preceding = 1'> and </xsl:if>
303
+        <xsl:text>eleventh</xsl:text>
304
+      </xsl:when>
305
+      <xsl:when test='$number = 12'>
306
+        <xsl:if test='$preceding = 1'> and </xsl:if>
307
+        <xsl:text>twelveth</xsl:text>
308
+      </xsl:when>
309
+      <xsl:when test='$number = 13'>
310
+        <xsl:if test='$preceding = 1'> and </xsl:if>
311
+        <xsl:text>thirteenth</xsl:text>
312
+      </xsl:when>
313
+      <xsl:when test='$number = 14'>
314
+        <xsl:if test='$preceding = 1'> and </xsl:if>
315
+        <xsl:text>fourteenth</xsl:text>
316
+      </xsl:when>
317
+      <xsl:when test='$number = 15'>
318
+        <xsl:if test='$preceding = 1'> and </xsl:if>
319
+        <xsl:text>fifteenth</xsl:text>
320
+      </xsl:when>
321
+      <xsl:when test='$number = 16'>
322
+        <xsl:if test='$preceding = 1'> and </xsl:if>
323
+        <xsl:text>sixteenth</xsl:text>
324
+      </xsl:when>
325
+      <xsl:when test='$number = 17'>
326
+        <xsl:if test='$preceding = 1'> and </xsl:if>
327
+        <xsl:text>seventeenth</xsl:text>
328
+      </xsl:when>
329
+      <xsl:when test='$number = 18'>
330
+        <xsl:if test='$preceding = 1'> and </xsl:if>
331
+        <xsl:text>eighteenth</xsl:text>
332
+      </xsl:when>
333
+      <xsl:when test='$number = 19'>
334
+        <xsl:if test='$preceding = 1'> and </xsl:if>
335
+        <xsl:text>nineteenth</xsl:text>
336
+      </xsl:when>
337
+      <xsl:when test='$number = 20'>
338
+        <xsl:if test='$preceding = 1'> and </xsl:if>
339
+        <xsl:text>twentieth</xsl:text>
340
+      </xsl:when>
341
+      <xsl:when test='$number = 30'>
342
+        <xsl:if test='$preceding = 1'> and </xsl:if>
343
+        <xsl:text>thirtieth</xsl:text>
344
+      </xsl:when>
345
+      <xsl:when test='$number = 40'>
346
+        <xsl:if test='$preceding = 1'> and </xsl:if>
347
+        <xsl:text>fortieth</xsl:text>
348
+      </xsl:when>
349
+      <xsl:when test='$number = 50'>
350
+        <xsl:if test='$preceding = 1'> and </xsl:if>
351
+        <xsl:text>fiftieth</xsl:text>
352
+      </xsl:when>
353
+      <xsl:when test='$number = 60'>
354
+        <xsl:if test='$preceding = 1'> and </xsl:if>
355
+        <xsl:text>sixtieth</xsl:text>
356
+      </xsl:when>
357
+      <xsl:when test='$number = 70'>
358
+        <xsl:if test='$preceding = 1'> and </xsl:if>
359
+        <xsl:text>seventieth</xsl:text>
360
+      </xsl:when>
361
+      <xsl:when test='$number = 80'>
362
+        <xsl:if test='$preceding = 1'> and </xsl:if>
363
+        <xsl:text>eightieth</xsl:text>
364
+      </xsl:when>
365
+      <xsl:when test='$number = 90'>
366
+        <xsl:if test='$preceding = 1'> and </xsl:if>
367
+        <xsl:text>ninetieth</xsl:text>
368
+      </xsl:when>
369
+
370
+      <xsl:when test='$number mod 1000000 = 0'>
371
+        <xsl:call-template name='math:number-as-word'>
372
+          <xsl:with-param name='number' select='floor($number div 1000000)'/>
373
+        </xsl:call-template>
374
+        <xsl:text> millionth</xsl:text>
375
+      </xsl:when>
376
+      <xsl:when test='$number &lt; 1000000 and $number mod 1000 = 0'>
377
+        <xsl:if test='$preceding = 1 and $conjunctive'> and </xsl:if>
378
+        <xsl:call-template name='math:number-as-word'>
379
+          <xsl:with-param name='number' select='floor($number div 1000)'/>
380
+        </xsl:call-template>
381
+        <xsl:text> thousandth</xsl:text>
382
+      </xsl:when>
383
+      <xsl:when test='$number &lt; 1000 and $number mod 100 = 0'>
384
+        <xsl:if test='$preceding = 1 and $conjunctive'> and </xsl:if>
385
+        <xsl:call-template name='math:number-as-word'>
386
+          <xsl:with-param name='number' select='floor($number div 100)'/>
387
+        </xsl:call-template>
388
+        <xsl:text> hundredth</xsl:text>
389
+      </xsl:when>
390
+
391
+      <xsl:when test='$number &gt; 1000000'>
392
+        <xsl:if test='$preceding = 1'>
393
+          <xsl:text> </xsl:text>
394
+          <xsl:if test='$conjunctive'>and </xsl:if>
395
+        </xsl:if>
396
+        <xsl:call-template name='math:number-as-word'>
397
+          <xsl:with-param name='number' select='floor($number div 1000000) * 1000000'/>
398
+        </xsl:call-template>
399
+        <xsl:choose>
400
+          <xsl:when
401
+            test='(floor(floor(($number mod 1000000) + 0.1) div 100000) > 0 and $number mod 100000 > 0) or
402
+            (floor(floor(($number mod 100000) + 0.1) div 10000) > 0 and $number mod 10000 > 0) or
403
+            (floor(floor(($number mod 10000) + 0.1) div 1000) > 0 and $number mod 1000 > 0) or
404
+            (floor(floor(($number mod 1000) + 0.1) div 100) > 0 and $number mod 100 > 0) or
405
+            (floor(floor(($number mod 100) + 0.1) div 10) > 0 and $number mod 10 > 0 and $number mod 100 > 20)'>
406
+            <xsl:text> </xsl:text>
407
+            <xsl:call-template name='math:ordinal-as-word'>
408
+              <xsl:with-param name='number' select='floor(($number mod 1000000) + 0.1)'/>
409
+              <xsl:with-param name='conjunctive' select='$conjunctive'/>
410
+              <xsl:with-param name='preceding' select='0'/>
411
+            </xsl:call-template>
412
+          </xsl:when>
413
+          <xsl:otherwise>
414
+            <xsl:call-template name='math:ordinal-as-word'>
415
+              <xsl:with-param name='number' select='floor(($number mod 1000000) + 0.1)'/>
416
+              <xsl:with-param name='conjunctive' select='$conjunctive'/>
417
+              <xsl:with-param name='preceding' select='1'/>
418
+            </xsl:call-template>
419
+          </xsl:otherwise>
420
+        </xsl:choose>
421
+      </xsl:when>
422
+      <xsl:when test='$number &gt; 1000'>
423
+        <xsl:if test='$preceding = 1'>
424
+          <xsl:text> </xsl:text>
425
+          <xsl:if test='$conjunctive'>and </xsl:if>
426
+        </xsl:if>
427
+        <xsl:call-template name='math:number-as-word'>
428
+          <xsl:with-param name='number' select='floor($number div 1000) * 1000'/>
429
+          <xsl:with-param name='conjunctive' select='$conjunctive'/>
430
+        </xsl:call-template>
431
+        <xsl:choose>
432
+          <xsl:when test='floor(floor(($number mod 1000) + 0.1) div 100) > 0'>
433
+            <xsl:text> </xsl:text>
434
+            <xsl:call-template name='math:ordinal-as-word'>
435
+              <xsl:with-param name='number' select='floor(($number mod 1000) + 0.1)'/>
436
+              <xsl:with-param name='conjunctive' select='$conjunctive'/>
437
+              <xsl:with-param name='preceding' select='0'/>
438
+            </xsl:call-template>
439
+          </xsl:when>
440
+          <xsl:otherwise>
441
+            <xsl:call-template name='math:ordinal-as-word'>
442
+              <xsl:with-param name='number' select='floor(($number mod 1000) + 0.1)'/>
443
+              <xsl:with-param name='conjunctive' select='$conjunctive'/>
444
+              <xsl:with-param name='preceding' select='1'/>
445
+            </xsl:call-template>
446
+          </xsl:otherwise>
447
+        </xsl:choose>
448
+      </xsl:when>
449
+      <xsl:when test='$number &gt; 100'>
450
+        <xsl:if test='$preceding = 1'>
451
+          <xsl:text> </xsl:text>
452
+          <xsl:if test='$conjunctive'>and </xsl:if>
453
+        </xsl:if>
454
+        <xsl:call-template name='math:number-as-word'>
455
+          <xsl:with-param name='number' select='floor($number div 100) * 100'/>
456
+        </xsl:call-template>
457
+        <xsl:call-template name='math:ordinal-as-word'>
458
+          <xsl:with-param name='number' select='floor(($number mod 100) + 0.1)'/>
459
+          <xsl:with-param name='conjunctive' select='$conjunctive'/>
460
+          <xsl:with-param name='preceding' select='1'/>
461
+        </xsl:call-template>
462
+      </xsl:when>
463
+
464
+      <xsl:when test='$number &gt; 20'>
465
+        <xsl:if test='$preceding = 1'>
466
+          <xsl:text> </xsl:text>
467
+          <xsl:if test='$conjunctive'>and </xsl:if>
468
+        </xsl:if>
469
+        <xsl:call-template name='math:number-as-word'>
470
+          <xsl:with-param name='number' select='floor($number div 10) * 10'/>
471
+        </xsl:call-template>
472
+        <xsl:text> </xsl:text>
473
+        <xsl:call-template name='math:ordinal-as-word'>
474
+          <xsl:with-param name='number' select='floor(($number mod 10) + 0.1)'/>
475
+          <xsl:with-param name='conjunctive' select='$conjunctive'/>
476
+        </xsl:call-template>
477
+      </xsl:when>
478
+
479
+      <xsl:otherwise/>
480
+    </xsl:choose>
481
+  </xsl:template>
482
+
483
+  <doc:template name="math:number-as-word" xmlns="">
484
+    <refpurpose>Returns a number as a word</refpurpose>
485
+
486
+    <refdescription>
487
+      <para>This template returns the word for a given integer number, for example "one" for 1.</para>
488
+      <para>Only handles numbers less than 10000000 (ten million).</para>
489
+    </refdescription>
490
+
491
+    <refparameter>
492
+      <variablelist>
493
+	<varlistentry>
494
+	  <term>number</term>
495
+	  <listitem>
496
+	    <para>The counting number.</para>
497
+	  </listitem>
498
+	</varlistentry>
499
+	<varlistentry>
500
+	  <term>conjunctive</term>
501
+	  <listitem>
502
+	    <para>Adds the word "and" where appropriate, for example.</para>
503
+	  </listitem>
504
+	</varlistentry>
505
+      </variablelist>
506
+    </refparameter>
507
+
508
+    <refreturn>
509
+      <para>Returns the number as a string.</para>
510
+    </refreturn>
511
+  </doc:template>
512
+
513
+  <xsl:template name="math:number-as-word">
514
+    <xsl:param name="number" select="0"/>
515
+    <xsl:param name='conjunctive' select='true()'/>
516
+
517
+    <xsl:choose>
518
+
519
+      <xsl:when test='$number = 0'>zero</xsl:when>
520
+
521
+      <xsl:when test='$number &lt; 0'>
522
+        <xsl:text>minus </xsl:text>
523
+        <xsl:call-template name='math:number-as-word'>
524
+          <xsl:with-param name='number' select='-1 * $number'/>
525
+        </xsl:call-template>
526
+      </xsl:when>
527
+
528
+      <xsl:when test="$number != floor($number)"/>
529
+
530
+      <xsl:when test='$number mod 1000000 = 0'>
531
+        <xsl:call-template name='math:number-as-word'>
532
+          <xsl:with-param name='number' select='floor($number div 1000000)'/>
533
+        </xsl:call-template>
534
+        <xsl:text> million</xsl:text>
535
+      </xsl:when>
536
+      <xsl:when test='$number &gt;= 1000000'>
537
+        <xsl:call-template name='math:number-as-word'>
538
+          <xsl:with-param name='number' select='floor($number div 1000000)'/>
539
+        </xsl:call-template>
540
+        <xsl:text> million </xsl:text>
541
+        <xsl:call-template name='math:number-as-word'>
542
+          <xsl:with-param name='number' select='floor(($number mod 1000000) + 0.1)'/>
543
+        </xsl:call-template>
544
+      </xsl:when>
545
+      <xsl:when test='$number mod 1000 = 0'>
546
+        <xsl:call-template name='math:number-as-word'>
547
+          <xsl:with-param name='number' select='floor($number div 1000)'/>
548
+        </xsl:call-template>
549
+        <xsl:text> thousand</xsl:text>
550
+      </xsl:when>
551
+      <xsl:when test='$number &gt;= 1000'>
552
+        <xsl:call-template name='math:number-as-word'>
553
+          <xsl:with-param name='number' select='floor($number div 1000)'/>
554
+        </xsl:call-template>
555
+        <xsl:text> thousand </xsl:text>
556
+        <xsl:if test='$conjunctive and floor(floor(($number mod 1000) + 0.1) div 100) = 0'>and </xsl:if>
557
+        <xsl:call-template name='math:number-as-word'>
558
+          <xsl:with-param name='number' select='floor(($number mod 1000) + 0.1)'/>
559
+        </xsl:call-template>
560
+      </xsl:when>
561
+      <xsl:when test='$number mod 100 = 0'>
562
+        <xsl:call-template name='math:number-as-word'>
563
+          <xsl:with-param name='number' select='floor($number div 100)'/>
564
+        </xsl:call-template>
565
+        <xsl:text> hundred</xsl:text>
566
+      </xsl:when>
567
+      <xsl:when test='$number &gt;= 100'>
568
+        <xsl:call-template name='math:number-as-word'>
569
+          <xsl:with-param name='number' select='floor($number div 100)'/>
570
+        </xsl:call-template>
571
+        <xsl:text> hundred </xsl:text>
572
+        <xsl:if test='$conjunctive'>and </xsl:if>
573
+        <xsl:call-template name='math:number-as-word'>
574
+          <xsl:with-param name='number' select='floor(($number mod 100) + 0.1)'/>
575
+        </xsl:call-template>
576
+      </xsl:when>
577
+
578
+      <xsl:when test='$number = 1'>one</xsl:when>
579
+      <xsl:when test='$number = 2'>two</xsl:when>
580
+      <xsl:when test='$number = 3'>three</xsl:when>
581
+      <xsl:when test='$number = 4'>four</xsl:when>
582
+      <xsl:when test='$number = 5'>five</xsl:when>
583
+      <xsl:when test='$number = 6'>six</xsl:when>
584
+      <xsl:when test='$number = 7'>seven</xsl:when>
585
+      <xsl:when test='$number = 8'>eight</xsl:when>
586
+      <xsl:when test='$number = 9'>nine</xsl:when>
587
+      <xsl:when test='$number = 10'>ten</xsl:when>
588
+      <xsl:when test='$number = 11'>eleven</xsl:when>
589
+      <xsl:when test='$number = 12'>twelve</xsl:when>
590
+      <xsl:when test='$number = 13'>thirteen</xsl:when>
591
+      <xsl:when test='$number = 14'>fourteen</xsl:when>
592
+      <xsl:when test='$number = 15'>fifteen</xsl:when>
593
+      <xsl:when test='$number = 16'>sixteen</xsl:when>
594
+      <xsl:when test='$number = 17'>seventeen</xsl:when>
595
+      <xsl:when test='$number = 18'>eighteen</xsl:when>
596
+      <xsl:when test='$number = 19'>nineteen</xsl:when>
597
+      <xsl:when test='$number = 20'>twenty</xsl:when>
598
+      <xsl:when test='$number = 30'>thirty</xsl:when>
599
+      <xsl:when test='$number = 40'>forty</xsl:when>
600
+      <xsl:when test='$number = 50'>fifty</xsl:when>
601
+      <xsl:when test='$number = 60'>sixty</xsl:when>
602
+      <xsl:when test='$number = 70'>seventy</xsl:when>
603
+      <xsl:when test='$number = 80'>eighty</xsl:when>
604
+      <xsl:when test='$number = 90'>ninety</xsl:when>
605
+
606
+      <xsl:when test='$number &lt; 100'>
607
+        <xsl:call-template name='math:number-as-word'>
608
+          <xsl:with-param name='number' select='floor($number div 10) * 10'/>
609
+        </xsl:call-template>
610
+        <xsl:text> </xsl:text>
611
+        <xsl:call-template name='math:number-as-word'>
612
+          <xsl:with-param name='number' select='floor(($number mod 10) + 0.1)'/>
613
+        </xsl:call-template>
614
+      </xsl:when>
615
+    </xsl:choose>
616
+  </xsl:template>
617
+</xsl:stylesheet>
618
+

+ 229
- 0
texml-xsl/node.xsl View File

@@ -0,0 +1,229 @@
1
+<?xml version="1.0"?>
2
+
3
+<xsl:stylesheet version="1.0"
4
+	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5
+	xmlns:doc="http://xsltsl.org/xsl/documentation/1.0"
6
+	xmlns:node="http://xsltsl.org/node"
7
+	extension-element-prefixes="doc node">
8
+
9
+  <doc:reference xmlns="">
10
+    <referenceinfo>
11
+      <releaseinfo role="meta">
12
+	$Id$
13
+      </releaseinfo>
14
+      <author>
15
+	<surname>Ball</surname>
16
+	<firstname>Steve</firstname>
17
+      </author>
18
+      <copyright>
19
+	<year>2001</year>
20
+	<holder>Steve Ball</holder>
21
+      </copyright>
22
+    </referenceinfo>
23
+
24
+    <title>Node Templates</title>
25
+
26
+    <partintro>
27
+      <section>
28
+	<title>Introduction</title>
29
+
30
+	<para>This stylesheet module provides functions for reporting on or manipulating nodes and nodesets.</para>
31
+
32
+      </section>
33
+    </partintro>
34
+
35
+  </doc:reference>
36
+
37
+  <doc:template name="node:xpath" xmlns="">
38
+    <refpurpose>Returns an XPath location path</refpurpose>
39
+
40
+    <refdescription>
41
+      <para>This template returns an XPath location path that uniquely identifies the given node within the document.</para>
42
+    </refdescription>
43
+
44
+    <refparameter>
45
+      <variablelist>
46
+	<varlistentry>
47
+	  <term>node</term>
48
+	  <listitem>
49
+	    <para>The node to create an XPath for.  If this parameter is given as a nodeset, then the first node in the nodeset is used.</para>
50
+	  </listitem>
51
+	</varlistentry>
52
+      </variablelist>
53
+    </refparameter>
54
+
55
+    <refreturn>
56
+      <para>Returns an XPath location path as a string.</para>
57
+    </refreturn>
58
+  </doc:template>
59
+
60
+  <xsl:template name="node:xpath">
61
+    <xsl:param name="node" select="."/>
62
+
63
+    <xsl:choose>
64
+
65
+      <xsl:when test="$node">
66
+
67
+        <xsl:for-each select="$node[1]/ancestor-or-self::*">
68
+          <xsl:text/>/<xsl:value-of select="name()"/>
69
+          <xsl:text/>[<xsl:value-of select="count(preceding-sibling::*[name() = name(current())]) + 1"/>]<xsl:text/>
70
+        </xsl:for-each>
71
+
72
+        <xsl:choose>
73
+
74
+          <xsl:when test="$node[1]/self::comment()">
75
+            <xsl:text>/comment()</xsl:text>
76
+            <xsl:text/>[<xsl:value-of select="count($node[1]/preceding-sibling::comment()) + 1" />]<xsl:text/>
77
+          </xsl:when>
78
+
79
+          <xsl:when test="$node[1]/self::processing-instruction()">
80
+            <xsl:text>/processing-instruction()</xsl:text>
81
+            <xsl:text/>[<xsl:value-of select="count($node[1]/preceding-sibling::processing-instruction()) + 1" />]<xsl:text/>
82
+          </xsl:when>
83
+
84
+          <xsl:when test="$node[1]/self::text()">
85
+            <xsl:text>/text()</xsl:text>
86
+            <xsl:text/>[<xsl:value-of select="count($node[1]/preceding-sibling::text()) + 1" />]<xsl:text/>
87
+          </xsl:when>
88
+
89
+          <xsl:when test="not($node[1]/..)">
90
+            <xsl:text>/</xsl:text>
91
+          </xsl:when>
92
+
93
+          <xsl:when test="count($node[1]/../namespace::* | $node[1]) = count($node[1]/../namespace::*)">
94
+            <xsl:text/>/namespace::<xsl:value-of select="name($node[1])" />
95
+          </xsl:when>
96
+
97
+          <xsl:when test="count($node[1]/../@* | $node[1]) = count($node[1]/../@*)">
98
+            <xsl:text/>/@<xsl:value-of select="name($node[1])" />
99
+          </xsl:when>
100
+
101
+        </xsl:choose>      
102
+      </xsl:when>
103
+
104
+      <xsl:otherwise>
105
+        <xsl:text>/..</xsl:text>
106
+      </xsl:otherwise>
107
+
108
+    </xsl:choose>
109
+
110
+  </xsl:template>
111
+
112
+  <doc:template name="node:type" xmlns="">
113
+    <refpurpose>Return node type</refpurpose>
114
+
115
+    <refdescription>
116
+      <para>Returns the type of a node as a string.</para>
117
+    </refdescription>
118
+
119
+    <refparameter>
120
+      <variablelist>
121
+	<varlistentry>
122
+	  <term>node</term>
123
+	  <listitem>
124
+	    <para>The node to get the type for.  If this parameter is given as a nodeset, then the first node in the nodeset is used.</para>
125
+	  </listitem>
126
+	</varlistentry>
127
+      </variablelist>
128
+    </refparameter>
129
+
130
+    <refreturn>
131
+      <para>Returns node type as a string.  Values returned are:</para>
132
+      <variablelist>
133
+	<varlistentry>
134
+	  <term>Element</term>
135
+	  <listitem>
136
+	    <para><literal>element</literal></para>
137
+	  </listitem>
138
+	</varlistentry>
139
+	<varlistentry>
140
+	  <term>Text Node</term>
141
+	  <listitem>
142
+	    <para><literal>text</literal></para>
143
+	  </listitem>
144
+	</varlistentry>
145
+	<varlistentry>
146
+	  <term>Comment</term>
147
+	  <listitem>
148
+	    <para><literal>comment</literal></para>
149
+	  </listitem>
150
+	</varlistentry>
151
+	<varlistentry>
152
+	  <term>Processing Instruction</term>
153
+	  <listitem>
154
+	    <para><literal>processing instruction</literal></para>
155
+	  </listitem>
156
+	</varlistentry>
157
+      </variablelist>
158
+    </refreturn>
159
+  </doc:template>
160
+
161
+  <xsl:template name="node:type">
162
+    <xsl:param name="node" select="."/>
163
+
164
+    <xsl:choose>
165
+      <xsl:when test="not($node)"/>
166
+      <xsl:when test="$node[1]/self::*">
167
+	<xsl:text>element</xsl:text>
168
+      </xsl:when>
169
+      <xsl:when test="$node[1]/self::text()">
170
+	<xsl:text>text</xsl:text>
171
+      </xsl:when>
172
+      <xsl:when test="$node[1]/self::comment()">
173
+	<xsl:text>comment</xsl:text>
174
+      </xsl:when>
175
+      <xsl:when test="$node[1]/self::processing-instruction()">
176
+	<xsl:text>processing instruction</xsl:text>
177
+      </xsl:when>
178
+      <xsl:when test="not($node[1]/parent::*)">
179
+        <xsl:text>root</xsl:text>
180
+      </xsl:when>
181
+      <xsl:when test="count($node[1] | $node[1]/../namespace::*) = count($node[1]/../namespace::*)">
182
+        <xsl:text>namespace</xsl:text>
183
+      </xsl:when>
184
+      <xsl:when test="count($node[1] | $node[1]/../@*) = count($node[1]/../@*)">
185
+        <xsl:text>attribute</xsl:text>
186
+      </xsl:when>
187
+    </xsl:choose>
188
+  </xsl:template>
189
+
190
+  <doc:template name="node:copy" xmlns="">
191
+    <refpurpose>Copy Nodes</refpurpose>
192
+
193
+    <refdescription>
194
+      <para>Makes a copy of the given nodes, including attributes and descendants.</para>
195
+    </refdescription>
196
+
197
+    <refparameter>
198
+      <variablelist>
199
+	<varlistentry>
200
+	  <term>nodes</term>
201
+	  <listitem>
202
+	    <para>The nodes to copy.</para>
203
+	  </listitem>
204
+	</varlistentry>
205
+      </variablelist>
206
+    </refparameter>
207
+
208
+    <refreturn>
209
+      <para>Returns the copied nodes as a result tree fragment.</para>
210
+    </refreturn>
211
+  </doc:template>
212
+
213
+  <xsl:template name='node:copy'>
214
+    <xsl:param name='nodes' select='.'/>
215
+
216
+    <xsl:for-each select='$nodes'>
217
+      <xsl:copy>
218
+        <xsl:for-each select='@*'>
219
+          <xsl:copy/>
220
+        </xsl:for-each>
221
+
222
+        <xsl:for-each select='node()'>
223
+          <xsl:call-template name='node:copy'/>
224
+        </xsl:for-each>
225
+      </xsl:copy>
226
+    </xsl:for-each>
227
+  </xsl:template>
228
+</xsl:stylesheet>
229
+

+ 340
- 0
texml-xsl/stdlib.xsl View File

@@ -0,0 +1,340 @@
1
+<?xml version="1.0"?>
2
+<!DOCTYPE xsl:stylesheet [
3
+  <!ENTITY version "1.2.1">
4
+]>
5
+
6
+<xsl:stylesheet
7
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
8
+  xmlns:doc="http://xsltsl.org/xsl/documentation/1.0"
9
+  exclude-result-prefixes="doc"
10
+  version="1.0">
11
+
12
+  <xsl:import href="string.xsl"/>
13
+  <xsl:import href="date-time.xsl"/>
14
+  <xsl:import href="node.xsl"/>
15
+  <xsl:import href="uri.xsl"/>
16
+  <xsl:import href="markup.xsl"/>
17
+  <xsl:import href="math.xsl"/>
18
+  <xsl:import href="cmp.xsl"/>
19
+
20
+  <xsl:import href="svg.xsl"/>
21
+<!--
22
+  <xsl:import href="html/html.xsl"/>
23
+  <xsl:import href="fo/fo.xsl"/>
24
+-->
25
+
26
+  <!-- For a new module, add an import element here -->
27
+  <xsl:import href="example.xsl"/>
28
+
29
+  <doc:book xmlns="">
30
+    <bookinfo>
31
+      <title>XSLT Standard Library</title>
32
+      <subtitle>Version &version;</subtitle>
33
+      <!-- $Id$ -->
34
+
35
+      <author>
36
+        <surname>Ball</surname>
37
+        <firstname>Steve</firstname>
38
+      </author>
39
+      <copyright>
40
+        <year>2004</year>
41
+        <year>2002</year>
42
+        <holder>Steve Ball</holder>
43
+      </copyright>
44
+    </bookinfo>
45
+
46
+    <preface>
47
+      <para>The <ulink url="http://www.w3.org/Style/XSL">XSLT</ulink> Standard Library, <acronym>xsltsl</acronym>, provides the XSLT developer with a set of XSLT templates for commonly used functions.  These are implemented purely in XSLT, that is they do not use any extensions.</para>
48
+      <para><acronym>xsltsl</acronym> is a <ulink url="http://sourceforge.net/projects/xsltsl/">SourceForge project</ulink>.</para>
49
+      <para><ulink url="http://sourceforge.net/"><inlinemediaobject>
50
+	  <imageobject>
51
+	    <imagedata fileref="sflogo.gif" width="88" height="31"/>
52
+	  </imageobject>
53
+	  <textobject>
54
+	    <phrase>SourceForge Logo</phrase>
55
+	  </textobject>
56
+	</inlinemediaobject></ulink></para>
57
+      <para>Goals of the <acronym>xsltsl</acronym> project include:</para>
58
+      <itemizedlist>
59
+        <listitem>
60
+          <para>Provision of a high-quality library of XSLT templates, suitable for inclusion by vendors in XSLT processor software products.</para>
61
+        </listitem>
62
+        <listitem>
63
+          <para>Demonstration of best practice in XSLT stylesheet development and documentation.</para>
64
+        </listitem>
65
+        <listitem>
66
+          <para>Provide examples of various techniques used to develop XSLT stylesheets (ie. a working FAQ).</para>
67
+        </listitem>
68
+      </itemizedlist>
69
+    </preface>
70
+
71
+    <chapter>
72
+      <title>Using The Library</title>
73
+
74
+      <para>There are two ways of using the library:</para>
75
+      <itemizedlist>
76
+	<listitem>
77
+	  <para>Use a local copy of the library.</para>
78
+	  <orderedlist>
79
+	    <listitem>
80
+	      <para>Download the distribution (see below).</para>
81
+	    </listitem>
82
+	    <listitem>
83
+	      <para>Unpack the distribution, using either gunzip/tar or unzip.</para>
84
+	    </listitem>
85
+	    <listitem>
86
+	      <para>In your stylesheet import or include either the main stylesheet, <filename>stdlib.xsl</filename>, or the stylesheet module you wish to use, such as <filename>string.xsl</filename>.  This example assumes that the distribution has been extracted into the same directory as your own stylesheet:</para>
87
+	      <informalexample>
88
+		<programlisting><![CDATA[
89
+<xsl:import href="stdlib.xsl"/>
90
+]]></programlisting>
91
+	      </informalexample>
92
+	    </listitem>
93
+	  </orderedlist>
94
+	</listitem>
95
+	<listitem>
96
+          <para>Import or include either the main stylesheet, or the stylesheet module you wish to use, directly from the library website; http://xsltsl.sourceforge.net/modules/.  The <filename>modules</filename> directory always contains the latest stable release.  For example:</para>
97
+	  <informalexample>
98
+	    <programlisting><![CDATA[
99
+<xsl:import href="http://xsltsl.sourceforge.net/modules/stdlib.xsl"/>
100
+]]></programlisting>
101
+	  </informalexample>
102
+          <para>Older versions of the library are available in subdirectories.  For example, to access version 1.1 of the library use:</para>
103
+	  <informalexample>
104
+	    <programlisting><![CDATA[
105
+<xsl:import href="http://xsltsl.sourceforge.net/modules/1.1/stdlib.xsl"/>
106
+]]></programlisting>
107
+	  </informalexample>
108
+	</listitem>
109
+      </itemizedlist>
110
+      <para>Next, add XML Namespace declarations for the modules you wish to use.  For example, to use templates from the string module, your stylesheet should have the following declaration:</para>
111
+      <informalexample>
112
+	<programlisting><![CDATA[
113
+<xsl:stylesheet version="1.0"
114
+	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
115
+	xmlns:str="http://xsltsl.org/string">
116
+
117
+<xsl:import href="http://xsltsl.sourceforge.net/modules/stdlib.xsl"/>
118
+]]></programlisting>
119
+      </informalexample>
120
+      <para>Finally, use a template with the <sgmltag>call-template</sgmltag> element.  Most templates require parameters, which are passed using the <sgmltag>with-param</sgmltag> element.  For example:</para>
121
+      <informalexample>
122
+	<programlisting><![CDATA[
123
+<xsl:template match="foo">
124
+  <xsl:call-template name="str:subst">
125
+    <xsl:with-param name="text" select="."/>
126
+    <xsl:with-param name="replace">a word</xsl:with-param>
127
+    <xsl:with-param name="with">another word</xsl:with-param>
128
+  </xsl:call-template>
129
+</xsl:template>
130
+]]></programlisting>
131
+      </informalexample>
132
+    </chapter>
133
+
134
+    <chapter>
135
+      <title>Obtaining The Library</title>
136
+
137
+      <para>The XSLT Standard Library is available for download as either:</para>
138
+      <itemizedlist>
139
+	<listitem>
140
+	  <para>Gzip'd tarball: <ulink url="http://prdownloads.sourceforge.net/xsltsl/xsltsl-&version;.tar.gz">http://prdownloads.sourceforge.net/xsltsl/xsltsl-&version;.tar.gz</ulink></para>
141
+	</listitem>
142
+	<listitem>
143
+	  <para>Zip file: <ulink url="http://prdownloads.sourceforge.net/xsltsl/xsltsl-&version;.zip">http://prdownloads.sourceforge.net/xsltsl/xsltsl-&version;.zip</ulink></para>
144
+	</listitem>
145
+      </itemizedlist>
146
+    </chapter>
147
+
148
+    <chapter>
149
+      <title>Getting Involved</title>
150
+
151
+      <para>Contributions to the project are most welcome, and may be in the form of stylesheet modules, patches, bug reports or sample code.  Any contributed code must use the LGPL license to be accepted into the library.</para>
152
+
153
+      <para>See the SourceForge Project Page <ulink url="http://sourceforge.net/projects/xsltsl/">http://sourceforge.net/projects/xsltsl/</ulink> for information on the development of the project.  Bug reports may be submitted here.</para>
154
+
155
+      <para>See the project Web Page <ulink url="http://xsltsl.sourceforge.net/">http://xsltsl.sourceforge.net/</ulink> for documentation.</para>
156
+
157
+      <para>There are three mailing lists for the project:</para>
158
+      <variablelist>
159
+	<varlistentry>
160
+	  <term><email>xsltsl-users@lists.sourceforge.net</email></term>
161
+	  <listitem>
162
+	    <para>Discussion of the use of <acronym>xsltsl</acronym>.</para>
163
+	  </listitem>
164
+	</varlistentry>
165
+	<varlistentry>
166
+	  <term><email>xsltsl-devel@lists.sourceforge.net</email></term>
167
+	  <listitem>
168
+	    <para>Discussion of the development of <acronym>xsltsl</acronym>.</para>
169
+	  </listitem>
170
+	</varlistentry>
171
+	<varlistentry>
172
+	  <term><email>xsltsl-announce@lists.sourceforge.net</email></term>
173
+	  <listitem>
174
+	    <para>Project announcements.</para>
175
+	  </listitem>
176
+	</varlistentry>
177
+      </variablelist>
178
+    </chapter>
179
+
180
+    <chapter>
181
+      <title>XML Namespaces</title>
182
+
183
+      <para>Apart from the XSLT XML Namespace (http://www.w3.org/1999/XSL/Transform), <acronym>xsltsl</acronym> employs a number of XML Namespaces to allow inclusion of the library in developer stylesheets.  In addition, documentation is defined in a separate namespace.</para>
184
+      <para>Each module is allocated a namespace URI by appending the module name to the URI for the project, http://xsltsl.org/.  For example, the string module has the namespace URI http://xsltsl.org/string.</para>
185
+      <para>All documentation is written using an <ulink url="docbook-extensions.html">extension</ulink> of <ulink url="http://www.docbook.org/">DocBook</ulink> designed for <ulink url="docbook-extensions.html">embedding DocBook into XSLT stylesheets</ulink>.  The namespace URI for DocBook embedded in stylesheets is http://xsltsl.org/xsl/documentation/1.0</para>
186
+    </chapter>
187
+
188
+    <chapter>
189
+      <title>Engineering Standards</title>
190
+
191
+      <para>In order to maintain a high engineering standard, all modules and contributions to the <acronym>xsltsl</acronym> project must adhere to the following coding and documentation standards.  Submissions which do not meet (or exceed) this standard will not be accepted.</para>
192
+      <itemizedlist>
193
+        <listitem>
194
+          <para>All stylesheets must be indented, with each level indented by two spaces.  NB. a simple stylesheet could be used to enforce/fix this.</para>
195
+        </listitem>
196
+        <listitem>
197
+          <para>Templates are named using a qualified name (QName).  The namespace URI for the template's containing stylesheet is assigned as above.</para>
198
+        </listitem>
199
+        <listitem>
200
+          <para>Parameters for templates should use sensible names.  Where possible (or if in doubt), follow these conventions:</para>
201
+          <itemizedlist>
202
+            <listitem>
203
+              <para>A parameter containing a single node is named <parametername>node</parametername>.  Where more than one parameter contains a single node, the suffix <parametername>Node</parametername> is appended to the parameter name, eg. <parametername>referenceNode</parametername></para>
204
+            </listitem>
205
+            <listitem>
206
+              <para>A parameter which potentially contains multiple nodes is named <parametername>nodes</parametername>.  Where more than one parameter potentially contains multiple nodes, the suffix <parametername>Nodes</parametername> is appended to the parameter name, eg. <parametername>copyNodes</parametername></para>
207
+            </listitem>
208
+            <listitem>
209
+              <para>A parameter which contains a string value is named <parametername>text</parametername>.</para>
210
+            </listitem>
211
+          </itemizedlist>
212
+        </listitem>
213
+        <listitem>
214
+          <para>All templates in each stylesheet must be documented.  A template is documented as a <ulink url="http://www.docbook.org/">DocBook</ulink> RefEntry.</para>
215
+        </listitem>
216
+        <listitem>
217
+          <para>Every stylesheet must include a test suite.  The test system is in the <filename>test</filename> subdirectory.  See <ulink url="test/test.html">test/test.html</ulink> for further details.</para>
218
+        </listitem>
219
+      </itemizedlist>
220
+
221
+      <para>An <ulink url="example.xsl">example stylesheet</ulink> has been provided, which acts as a template for new stylesheet modules.</para>
222
+
223
+    </chapter>
224
+
225
+    <chapter>
226
+      <title>Related Work</title>
227
+
228
+      <para>The <ulink url="http://www.exslt.org/">EXSLT</ulink> project is creating a library to standardise extension functions.  The XSLT Standard Library is complementary to the EXSLT project.</para>
229
+
230
+    </chapter>
231
+
232
+    <chapter>
233
+      <title>Reference Documentation</title>
234
+
235
+      <para>Reference documentation is available for each module.</para>
236
+
237
+      <section>
238
+        <title>String Processing</title>
239
+
240
+        <itemizedlist>
241
+          <listitem>
242
+            <para><ulink url="string.html">string.xsl</ulink></para>
243
+          </listitem>
244
+        </itemizedlist>
245
+      </section>
246
+
247
+      <section>
248
+        <title>Nodes</title>
249
+
250
+        <itemizedlist>
251
+          <listitem>
252
+            <para><ulink url="node.html">node.xsl</ulink></para>
253
+          </listitem>
254
+        </itemizedlist>
255
+      </section>
256
+
257
+      <section>
258
+        <title>Date/Time Processing</title>
259
+
260
+        <itemizedlist>
261
+          <listitem>
262
+            <para><ulink url="date-time.html">date-time.xsl</ulink></para>
263
+          </listitem>
264
+        </itemizedlist>
265
+      </section>
266
+
267
+      <section>
268
+        <title>Mathematics</title>
269
+
270
+        <itemizedlist>
271
+          <listitem>
272
+            <para><ulink url="math.html">math.xsl</ulink></para>
273
+          </listitem>
274
+        </itemizedlist>
275
+      </section>
276
+
277
+      <section>
278
+        <title>URI (Uniform Resource Identifier) Processing</title>
279
+
280
+        <itemizedlist>
281
+          <listitem>
282
+            <para><ulink url="uri.html">uri.xsl</ulink></para>
283
+          </listitem>
284
+        </itemizedlist>
285
+      </section>
286
+
287
+      <section>
288
+        <title>Comparing Nodesets</title>
289
+
290
+        <itemizedlist>
291
+          <listitem>
292
+            <para><ulink url="cmp.html">cmp.xsl</ulink></para>
293
+          </listitem>
294
+        </itemizedlist>
295
+      </section>
296
+
297
+      <section>
298
+        <title>Generating XML Markup</title>
299
+
300
+        <itemizedlist>
301
+          <listitem>
302
+            <para><ulink url="markup.html">markup.xsl</ulink></para>
303
+          </listitem>
304
+        </itemizedlist>
305
+      </section>
306
+
307
+      <section>
308
+        <title>Presentation Media Support</title>
309
+
310
+        <itemizedlist>
311
+          <listitem>
312
+            <para>Scalable Vector Graphics: <ulink url="svg.html">svg.xsl</ulink></para>
313
+          </listitem>
314
+<!--
315
+          <listitem>
316
+            <para><ulink url="html/html.html">html/html.xsl</ulink></para>
317
+          </listitem>
318
+          <listitem>
319
+            <para><ulink url="fo/fo.html">fo/fo.xsl</ulink></para>
320
+          </listitem>
321
+-->
322
+        </itemizedlist>
323
+      </section>
324
+
325
+      <section>
326
+        <title>Example</title>
327
+
328
+        <!-- Add a new module in a similar fashion -->
329
+
330
+        <itemizedlist>
331
+          <listitem>
332
+            <para><ulink url="example.html">example.xsl</ulink></para>
333
+          </listitem>
334
+        </itemizedlist>
335
+      </section>
336
+    </chapter>
337
+
338
+  </doc:book>
339
+
340
+</xsl:stylesheet>

+ 1233
- 0
texml-xsl/string.xsl
File diff suppressed because it is too large
View File


+ 1
- 0
texml-xsl/svg.xsl
File diff suppressed because it is too large
View File


+ 580
- 0
texml-xsl/uri.xsl View File

@@ -0,0 +1,580 @@
1
+<?xml version="1.0"?>
2
+
3
+<xsl:stylesheet
4
+  version="1.0"
5
+  extension-element-prefixes="doc"
6
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
7
+  xmlns:doc="http://xsltsl.org/xsl/documentation/1.0"
8
+  xmlns:uri="http://xsltsl.org/uri"
9
+>
10
+
11
+  <doc:reference xmlns="">
12
+    <referenceinfo>
13
+      <releaseinfo role="meta">
14
+        $Id$
15
+      </releaseinfo>
16
+      <author>
17
+        <surname>Diamond</surname>
18
+        <firstname>Jason</firstname>
19
+      </author>
20
+      <copyright>
21
+        <year>2001</year>
22
+        <holder>Jason Diamond</holder>
23
+      </copyright>
24
+    </referenceinfo>
25
+
26
+    <title>URI (Uniform Resource Identifier) Processing</title>
27
+
28
+    <partintro>
29
+      <section>
30
+        <title>Introduction</title>
31
+        <para>This module provides templates for processing URIs (Uniform Resource Identifers).</para>
32
+      </section>
33
+    </partintro>
34
+
35
+  </doc:reference>
36
+
37
+  <doc:template name="uri:is-absolute-uri" xmlns="">
38
+    <refpurpose>Determines if a URI is absolute or relative.</refpurpose>
39
+
40
+    <refdescription>
41
+      <para>Absolute URIs start with a scheme (like "http:" or "mailto:").</para>
42
+    </refdescription>
43
+
44
+    <refparameter>
45
+      <variablelist>
46
+        <varlistentry>
47
+          <term>uri</term>
48
+          <listitem>
49
+            <para>An absolute or relative URI.</para>
50
+          </listitem>
51
+        </varlistentry>
52
+      </variablelist>
53
+    </refparameter>
54
+
55
+    <refreturn>
56
+      <para>Returns 'true' if the URI is absolute or '' if it's not.</para>
57
+    </refreturn>
58
+  </doc:template>
59
+
60
+  <xsl:template name="uri:is-absolute-uri">
61
+    <xsl:param name="uri"/>
62
+
63
+    <xsl:if test="contains($uri, ':')">
64
+      <xsl:value-of select="true()"/>
65
+    </xsl:if>
66
+
67
+  </xsl:template>
68
+
69
+  <doc:template name="uri:get-uri-scheme" xmlns="">
70
+    <refpurpose>Gets the scheme part of a URI.</refpurpose>
71
+
72
+    <refdescription>
73
+      <para>The ':' is not part of the scheme.</para>
74
+    </refdescription>
75
+
76
+    <refparameter>
77
+      <variablelist>
78
+        <varlistentry>
79
+          <term>uri</term>
80
+          <listitem>
81
+            <para>An absolute or relative URI.</para>
82
+          </listitem>
83
+        </varlistentry>
84
+      </variablelist>
85
+    </refparameter>
86
+
87
+    <refreturn>
88
+      <para>Returns the scheme (without the ':') or '' if the URI is relative.</para>
89
+    </refreturn>
90
+  </doc:template>
91
+
92
+  <xsl:template name="uri:get-uri-scheme">
93
+    <xsl:param name="uri"/>
94
+    <xsl:if test="contains($uri, ':')">
95
+      <xsl:value-of select="substring-before($uri, ':')"/>
96
+    </xsl:if>
97
+  </xsl:template>
98
+
99
+  <doc:template name="uri:get-uri-authority" xmlns="">
100
+    <refpurpose>Gets the authority part of a URI.</refpurpose>
101
+
102
+    <refdescription>
103
+      <para>The authority usually specifies the host machine for a resource. It always follows '//' in a typical URI.</para>
104
+    </refdescription>
105
+
106
+    <refparameter>
107
+      <variablelist>
108
+        <varlistentry>
109
+          <term>uri</term>
110
+          <listitem>
111
+            <para>An absolute or relative URI.</para>
112
+          </listitem>
113
+        </varlistentry>
114
+      </variablelist>
115
+    </refparameter>
116
+
117
+    <refreturn>
118
+      <para>Returns the authority (without the '//') or '' if the URI has no authority.</para>
119
+    </refreturn>
120
+  </doc:template>
121
+
122
+  <xsl:template name="uri:get-uri-authority">
123
+    <xsl:param name="uri"/>
124
+
125
+    <xsl:variable name="a">
126
+      <xsl:choose>
127
+        <xsl:when test="contains($uri, ':')">
128
+          <xsl:if test="substring(substring-after($uri, ':'), 1, 2) = '//'">
129
+              <xsl:value-of select="substring(substring-after($uri, ':'), 3)"/>
130
+          </xsl:if>
131
+        </xsl:when>
132
+        <xsl:otherwise>
133
+          <xsl:if test="substring($uri, 1, 2) = '//'">
134
+            <xsl:value-of select="substring($uri, 3)"/>
135
+          </xsl:if>
136
+        </xsl:otherwise>
137
+      </xsl:choose>
138
+    </xsl:variable>
139
+
140
+    <xsl:choose>
141
+      <xsl:when test="contains($a, '/')">
142
+        <xsl:value-of select="substring-before($a, '/')" />
143
+      </xsl:when>
144
+      <xsl:when test="contains($a, '?')">
145
+        <xsl:value-of select="substring-before($a, '?')" />
146
+      </xsl:when>
147
+      <xsl:when test="contains($a, '#')">
148
+        <xsl:value-of select="substring-before($a, '#')" />
149
+      </xsl:when>
150
+      <xsl:otherwise>
151
+        <xsl:value-of select="$a" />
152
+      </xsl:otherwise>
153
+    </xsl:choose>
154
+
155
+  </xsl:template>
156
+
157
+  <doc:template name="uri:get-uri-path" xmlns="">
158
+    <refpurpose>Gets the path part of a URI.</refpurpose>
159
+
160
+    <refdescription>
161
+      <para>The path usually comes after the '/' in a URI.</para>
162
+    </refdescription>
163
+
164
+    <refparameter>
165
+      <variablelist>
166
+        <varlistentry>
167
+          <term>uri</term>
168
+          <listitem>
169
+            <para>An absolute or relative URI.</para>
170
+          </listitem>
171
+        </varlistentry>
172
+      </variablelist>
173
+    </refparameter>
174
+
175
+    <refreturn>