@pretextbook/pretext-html 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/README.md +42 -3
  2. package/assets/preview-html.xsl +230 -230
  3. package/assets/upstream.json +7 -7
  4. package/assets/xsl/README.md +0 -0
  5. package/assets/xsl/entities.ent +154 -154
  6. package/assets/xsl/extract-asymptote.xsl +68 -68
  7. package/assets/xsl/extract-biblio-csl.xsl +327 -327
  8. package/assets/xsl/extract-datafile.xsl +71 -71
  9. package/assets/xsl/extract-dynamic.xsl +139 -139
  10. package/assets/xsl/extract-identity.xsl +136 -136
  11. package/assets/xsl/extract-interactive.xsl +81 -81
  12. package/assets/xsl/extract-latex-image.xsl +118 -118
  13. package/assets/xsl/extract-mermaid.xsl +58 -58
  14. package/assets/xsl/extract-mom.xsl +63 -63
  15. package/assets/xsl/extract-pg.xsl +2897 -2897
  16. package/assets/xsl/extract-prefigure.xsl +157 -157
  17. package/assets/xsl/extract-qrcode.xsl +100 -100
  18. package/assets/xsl/extract-runestone-page-template.xsl +139 -139
  19. package/assets/xsl/extract-sageplot.xsl +166 -166
  20. package/assets/xsl/extract-stack.xsl +56 -56
  21. package/assets/xsl/extract-trace.xsl +134 -134
  22. package/assets/xsl/extract-youtube.xsl +63 -63
  23. package/assets/xsl/html-symbols.xsl +3344 -3344
  24. package/assets/xsl/latex/pretext-latex-AIM.xsl +56 -56
  25. package/assets/xsl/latex/pretext-latex-CLP.xsl +148 -148
  26. package/assets/xsl/latex/pretext-latex-chaos.xsl +317 -317
  27. package/assets/xsl/latex/pretext-latex-dyslexic-font.xsl +76 -76
  28. package/assets/xsl/latex/pretext-latex-guide.xsl +104 -104
  29. package/assets/xsl/latex/pretext-latex-texstyle.xsl +862 -862
  30. package/assets/xsl/localizations/README.md +0 -0
  31. package/assets/xsl/localizations/af-ZA.xml +276 -276
  32. package/assets/xsl/localizations/bg-BG.xml +276 -276
  33. package/assets/xsl/localizations/ca-ES.xml +285 -285
  34. package/assets/xsl/localizations/cs-CZ.xml +280 -280
  35. package/assets/xsl/localizations/de-DE.xml +281 -281
  36. package/assets/xsl/localizations/en-US.xml +427 -427
  37. package/assets/xsl/localizations/es-ES.xml +287 -287
  38. package/assets/xsl/localizations/fi-FI.xml +275 -275
  39. package/assets/xsl/localizations/fr-CA.xml +276 -276
  40. package/assets/xsl/localizations/fr-FR.xml +280 -280
  41. package/assets/xsl/localizations/hu-HU.xml +280 -280
  42. package/assets/xsl/localizations/it-IT.xml +276 -276
  43. package/assets/xsl/localizations/ku-CKB.xml +275 -275
  44. package/assets/xsl/localizations/localizations.xml +48 -48
  45. package/assets/xsl/localizations/nl-NL.xml +275 -275
  46. package/assets/xsl/localizations/pt-BR.xml +288 -288
  47. package/assets/xsl/localizations/pt-PT.xml +292 -292
  48. package/assets/xsl/localizations/zh-HANS.xml +269 -269
  49. package/assets/xsl/pretext-assembly.xsl +4795 -4795
  50. package/assets/xsl/pretext-basic-html.xsl +86 -86
  51. package/assets/xsl/pretext-beamer.xsl +662 -662
  52. package/assets/xsl/pretext-braille-preprint.xsl +2249 -2249
  53. package/assets/xsl/pretext-common.xsl +12018 -12018
  54. package/assets/xsl/pretext-dynamic.xsl +65 -65
  55. package/assets/xsl/pretext-epub.xsl +1483 -1483
  56. package/assets/xsl/pretext-fo.xsl +4593 -4593
  57. package/assets/xsl/pretext-html.xsl +14791 -14791
  58. package/assets/xsl/pretext-json-manifest.xsl +150 -150
  59. package/assets/xsl/pretext-jupyter.xsl +868 -868
  60. package/assets/xsl/pretext-latex-classic.xsl +952 -952
  61. package/assets/xsl/pretext-latex-common.xsl +11563 -11563
  62. package/assets/xsl/pretext-latex.xsl +47 -47
  63. package/assets/xsl/pretext-litprog.xsl +105 -105
  64. package/assets/xsl/pretext-merge.xsl +41 -41
  65. package/assets/xsl/pretext-numbers.xsl +875 -875
  66. package/assets/xsl/pretext-revealjs.xsl +522 -522
  67. package/assets/xsl/pretext-runestone-fitb.xsl +1233 -1233
  68. package/assets/xsl/pretext-runestone-static.xsl +1438 -1438
  69. package/assets/xsl/pretext-runestone.xsl +3083 -3083
  70. package/assets/xsl/pretext-sage-doctest.xsl +289 -289
  71. package/assets/xsl/pretext-smc.xsl +492 -492
  72. package/assets/xsl/pretext-solution-manual-latex.xsl +323 -323
  73. package/assets/xsl/pretext-text-utilities.xsl +1217 -1217
  74. package/assets/xsl/pretext-text.xsl +392 -392
  75. package/assets/xsl/pretext-units.xsl +195 -195
  76. package/assets/xsl/pretext-view-source.xsl +157 -157
  77. package/assets/xsl/pretext-ww-problem-sets.xsl +391 -391
  78. package/assets/xsl/publisher-variables.xsl +4756 -4756
  79. package/assets/xsl/support/README.md +0 -0
  80. package/assets/xsl/support/extract-math.xsl +256 -256
  81. package/assets/xsl/support/package-math.xsl +141 -141
  82. package/assets/xsl/support/play-button/README.md +0 -0
  83. package/assets/xsl/support/play-button/play-button.png +0 -0
  84. package/assets/xsl/support/play-button/play-button.svg +3 -3
  85. package/assets/xsl/support/pretext-pg-macros.xsl +110 -110
  86. package/assets/xsl/support/webpack_static_imports.xml +14 -14
  87. package/assets/xsl/tests/README.md +0 -0
  88. package/assets/xsl/tests/null.xml +3 -3
  89. package/assets/xsl/tests/pretext-text-utilities-test.xsl +333 -333
  90. package/assets/xsl/utilities/README.md +0 -0
  91. package/assets/xsl/utilities/author-report.xsl +107 -107
  92. package/assets/xsl/utilities/deprecate-autoname.sed +18 -18
  93. package/assets/xsl/utilities/deprecate-index.sed +33 -33
  94. package/assets/xsl/utilities/fix-deprecations.xsl +663 -663
  95. package/assets/xsl/utilities/pretext-enhanced-source.xsl +112 -112
  96. package/assets/xsl/utilities/report-publisher-variables.xsl +162 -162
  97. package/assets/xsl/xml-to-json.xsl +326 -326
  98. package/assets/xsl/xml-to-string.xsl +328 -328
  99. package/dist/{cli-C6tfAVvi.js → cli-BQizBK0N.js} +74 -72
  100. package/dist/cli.d.ts +0 -0
  101. package/dist/cli.js +1 -1
  102. package/dist/index.d.ts +2 -0
  103. package/dist/index.js +12 -6
  104. package/dist/mounts.d.ts +0 -0
  105. package/dist/publication.d.ts +0 -0
  106. package/dist/renderer.d.ts +10 -0
  107. package/dist/sourcemap.d.ts +0 -0
  108. package/dist/theme.d.ts +68 -0
  109. package/dist/theme.js +93 -0
  110. package/dist/xinclude.d.ts +0 -0
  111. package/package.json +14 -2
@@ -1,328 +1,328 @@
1
- <!--
2
- Copyright (c) 2001-2009, Evan Lenz
3
- All rights reserved.
4
-
5
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6
-
7
- * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
- * Neither the name of Lenz Consulting Group nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
-
11
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12
-
13
- Recent changes:
14
-
15
- 2010-06-10: Added the $force-exclude-all-namespaces parameter
16
- 2009-10-19: Added the $exclude-these-namespaces parameter
17
- 2009-10-08: Added $att-value parameter and template name to template rule for attributes.
18
-
19
- 2025-05-27: PreTeXt, R. Beezer. Escaped "greater-than".
20
-
21
- -->
22
- <xsl:stylesheet version="1.0"
23
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
24
-
25
- <xsl:output omit-xml-declaration="yes"/>
26
-
27
- <xsl:param name="use-empty-syntax" select="true()"/>
28
- <xsl:param name="exclude-unused-prefixes" select="true()"/>
29
-
30
- <xsl:param name="force-exclude-all-namespaces" select="false()"/>
31
-
32
- <!-- a node-set; each node's string-value
33
- will be interpreted as a namespace URI to be
34
- excluded from the serialization. -->
35
- <xsl:param name="namespaces-to-exclude" select="/.."/>
36
- <!-- initialized to empty node-set -->
37
-
38
- <xsl:param name="start-tag-start" select="'&lt;'"/>
39
- <xsl:param name="start-tag-end" select="'>'"/>
40
- <xsl:param name="empty-tag-end" select="'/>'"/>
41
- <xsl:param name="end-tag-start" select="'&lt;/'"/>
42
- <xsl:param name="end-tag-end" select="'>'"/>
43
- <xsl:param name="space" select="' '"/>
44
- <xsl:param name="ns-decl" select="'xmlns'"/>
45
- <xsl:param name="colon" select="':'"/>
46
- <xsl:param name="equals" select="'='"/>
47
- <xsl:param name="attribute-delimiter" select="'&quot;'"/>
48
- <xsl:param name="comment-start" select="'&lt;!--'"/>
49
- <xsl:param name="comment-end" select="'-->'"/>
50
- <xsl:param name="pi-start" select="'&lt;?'"/>
51
- <xsl:param name="pi-end" select="'?>'"/>
52
-
53
- <xsl:template name="xml-to-string">
54
- <xsl:param name="node-set" select="."/>
55
- <xsl:apply-templates select="$node-set" mode="xml-to-string">
56
- <xsl:with-param name="depth" select="1"/>
57
- </xsl:apply-templates>
58
- </xsl:template>
59
-
60
- <xsl:template match="/" name="xml-to-string-root-rule">
61
- <xsl:call-template name="xml-to-string"/>
62
- </xsl:template>
63
-
64
- <xsl:template match="/" mode="xml-to-string">
65
- <xsl:param name="depth"/>
66
- <xsl:apply-templates mode="xml-to-string">
67
- <xsl:with-param name="depth" select="$depth"/>
68
- </xsl:apply-templates>
69
- </xsl:template>
70
-
71
- <xsl:template match="*" mode="xml-to-string">
72
- <xsl:param name="depth"/>
73
- <xsl:variable name="element" select="."/>
74
- <xsl:value-of select="$start-tag-start"/>
75
- <xsl:call-template name="element-name">
76
- <xsl:with-param name="text" select="name()"/>
77
- </xsl:call-template>
78
- <xsl:apply-templates select="@*" mode="xml-to-string"/>
79
- <xsl:if test="not($force-exclude-all-namespaces)">
80
- <xsl:for-each select="namespace::*">
81
- <xsl:call-template name="process-namespace-node">
82
- <xsl:with-param name="element" select="$element"/>
83
- <xsl:with-param name="depth" select="$depth"/>
84
- </xsl:call-template>
85
- </xsl:for-each>
86
- </xsl:if>
87
- <xsl:choose>
88
- <xsl:when test="node() or not($use-empty-syntax)">
89
- <xsl:value-of select="$start-tag-end"/>
90
- <xsl:apply-templates mode="xml-to-string">
91
- <xsl:with-param name="depth" select="$depth + 1"/>
92
- </xsl:apply-templates>
93
- <xsl:value-of select="$end-tag-start"/>
94
- <xsl:call-template name="element-name">
95
- <xsl:with-param name="text" select="name()"/>
96
- </xsl:call-template>
97
- <xsl:value-of select="$end-tag-end"/>
98
- </xsl:when>
99
- <xsl:otherwise>
100
- <xsl:value-of select="$empty-tag-end"/>
101
- </xsl:otherwise>
102
- </xsl:choose>
103
- </xsl:template>
104
-
105
- <xsl:template name="process-namespace-node">
106
- <xsl:param name="element"/>
107
- <xsl:param name="depth"/>
108
- <xsl:variable name="declaredAbove">
109
- <xsl:call-template name="isDeclaredAbove">
110
- <xsl:with-param name="depth" select="$depth - 1"/>
111
- <xsl:with-param name="element" select="$element/.."/>
112
- </xsl:call-template>
113
- </xsl:variable>
114
-
115
- <xsl:variable name="is-used-on-this-element" select="($element | $element/@*) [namespace-uri() = current()]"/>
116
- <xsl:variable name="is-used-on-a-descendant" select="($element//* | $element//@*)[namespace-uri() = current()]"/>
117
- <xsl:variable name="is-unused" select="not($is-used-on-this-element) and
118
- not($is-used-on-a-descendant)"/>
119
- <xsl:variable name="exclude-ns" select="($is-unused and $exclude-unused-prefixes) or
120
- (. = $namespaces-to-exclude)"/>
121
-
122
- <xsl:variable name="force-include" select="$is-used-on-this-element and (. = $namespaces-to-exclude)"/>
123
-
124
- <xsl:if test="(name() != 'xml') and ($force-include or (not($exclude-ns) and not(string($declaredAbove))))">
125
- <xsl:value-of select="$space"/>
126
- <xsl:value-of select="$ns-decl"/>
127
- <xsl:if test="name()">
128
- <xsl:value-of select="$colon"/>
129
- <xsl:call-template name="ns-prefix">
130
- <xsl:with-param name="text" select="name()"/>
131
- </xsl:call-template>
132
- </xsl:if>
133
- <xsl:value-of select="$equals"/>
134
- <xsl:value-of select="$attribute-delimiter"/>
135
- <xsl:call-template name="ns-uri">
136
- <xsl:with-param name="text" select="string(.)"/>
137
- </xsl:call-template>
138
- <xsl:value-of select="$attribute-delimiter"/>
139
- </xsl:if>
140
- </xsl:template>
141
-
142
- <xsl:template name="isDeclaredAbove">
143
- <xsl:param name="element"/>
144
- <xsl:param name="depth"/>
145
- <xsl:if test="$depth > 0">
146
- <xsl:choose>
147
- <xsl:when test="$element/namespace::*[name(.)=name(current()) and .=current()]">1</xsl:when>
148
- <xsl:when test="$element/namespace::*[name(.)=name(current())]"/>
149
- <xsl:otherwise>
150
- <xsl:call-template name="isDeclaredAbove">
151
- <xsl:with-param name="depth" select="$depth - 1"/>
152
- <xsl:with-param name="element" select="$element/.."/>
153
- </xsl:call-template>
154
- </xsl:otherwise>
155
- </xsl:choose>
156
- </xsl:if>
157
- </xsl:template>
158
-
159
- <xsl:template match="@*" mode="xml-to-string" name="serialize-attribute">
160
- <xsl:param name="att-value" select="string(.)"/>
161
- <xsl:value-of select="$space"/>
162
- <xsl:call-template name="attribute-name">
163
- <xsl:with-param name="text" select="name()"/>
164
- </xsl:call-template>
165
- <xsl:value-of select="$equals"/>
166
- <xsl:value-of select="$attribute-delimiter"/>
167
- <xsl:call-template name="attribute-value">
168
- <xsl:with-param name="text" select="$att-value"/>
169
- </xsl:call-template>
170
- <xsl:value-of select="$attribute-delimiter"/>
171
- </xsl:template>
172
-
173
- <xsl:template match="comment()" mode="xml-to-string">
174
- <xsl:value-of select="$comment-start"/>
175
- <xsl:call-template name="comment-text">
176
- <xsl:with-param name="text" select="string(.)"/>
177
- </xsl:call-template>
178
- <xsl:value-of select="$comment-end"/>
179
- </xsl:template>
180
-
181
- <xsl:template match="processing-instruction()" mode="xml-to-string">
182
- <xsl:value-of select="$pi-start"/>
183
- <xsl:call-template name="pi-target">
184
- <xsl:with-param name="text" select="name()"/>
185
- </xsl:call-template>
186
- <xsl:value-of select="$space"/>
187
- <xsl:call-template name="pi-text">
188
- <xsl:with-param name="text" select="string(.)"/>
189
- </xsl:call-template>
190
- <xsl:value-of select="$pi-end"/>
191
- </xsl:template>
192
-
193
- <xsl:template match="text()" mode="xml-to-string">
194
- <xsl:call-template name="text-content">
195
- <xsl:with-param name="text" select="string(.)"/>
196
- </xsl:call-template>
197
- </xsl:template>
198
-
199
- <xsl:template name="element-name">
200
- <xsl:param name="text"/>
201
- <xsl:value-of select="$text"/>
202
- </xsl:template>
203
-
204
- <xsl:template name="attribute-name">
205
- <xsl:param name="text"/>
206
- <xsl:value-of select="$text"/>
207
- </xsl:template>
208
-
209
- <xsl:template name="attribute-value">
210
- <xsl:param name="text"/>
211
- <xsl:variable name="escaped-markup">
212
- <xsl:call-template name="escape-markup-characters">
213
- <xsl:with-param name="text" select="$text"/>
214
- </xsl:call-template>
215
- </xsl:variable>
216
- <xsl:choose>
217
- <xsl:when test="$attribute-delimiter = &quot;'&quot;">
218
- <xsl:call-template name="replace-string">
219
- <xsl:with-param name="text" select="$escaped-markup"/>
220
- <xsl:with-param name="replace" select="&quot;'&quot;"/>
221
- <xsl:with-param name="with" select="'&amp;apos;'"/>
222
- </xsl:call-template>
223
- </xsl:when>
224
- <xsl:when test="$attribute-delimiter = '&quot;'">
225
- <xsl:call-template name="replace-string">
226
- <xsl:with-param name="text" select="$escaped-markup"/>
227
- <xsl:with-param name="replace" select="'&quot;'"/>
228
- <xsl:with-param name="with" select="'&amp;quot;'"/>
229
- </xsl:call-template>
230
- </xsl:when>
231
- <xsl:otherwise>
232
- <xsl:call-template name="replace-string">
233
- <xsl:with-param name="text" select="$escaped-markup"/>
234
- <xsl:with-param name="replace" select="$attribute-delimiter"/>
235
- <xsl:with-param name="with" select="''"/>
236
- </xsl:call-template>
237
- </xsl:otherwise>
238
- </xsl:choose>
239
- </xsl:template>
240
-
241
- <xsl:template name="ns-prefix">
242
- <xsl:param name="text"/>
243
- <xsl:value-of select="$text"/>
244
- </xsl:template>
245
-
246
- <xsl:template name="ns-uri">
247
- <xsl:param name="text"/>
248
- <xsl:call-template name="attribute-value">
249
- <xsl:with-param name="text" select="$text"/>
250
- </xsl:call-template>
251
- </xsl:template>
252
-
253
- <xsl:template name="text-content">
254
- <xsl:param name="text"/>
255
- <xsl:call-template name="escape-markup-characters">
256
- <xsl:with-param name="text" select="$text"/>
257
- </xsl:call-template>
258
- </xsl:template>
259
-
260
- <xsl:template name="pi-target">
261
- <xsl:param name="text"/>
262
- <xsl:value-of select="$text"/>
263
- </xsl:template>
264
-
265
- <xsl:template name="pi-text">
266
- <xsl:param name="text"/>
267
- <xsl:value-of select="$text"/>
268
- </xsl:template>
269
-
270
- <xsl:template name="comment-text">
271
- <xsl:param name="text"/>
272
- <xsl:value-of select="$text"/>
273
- </xsl:template>
274
-
275
- <xsl:template name="escape-markup-characters">
276
- <xsl:param name="text"/>
277
- <xsl:variable name="ampEscaped">
278
- <xsl:call-template name="replace-string">
279
- <xsl:with-param name="text" select="$text"/>
280
- <xsl:with-param name="replace" select="'&amp;'"/>
281
- <xsl:with-param name="with" select="'&amp;amp;'"/>
282
- </xsl:call-template>
283
- </xsl:variable>
284
- <xsl:variable name="ltEscaped">
285
- <xsl:call-template name="replace-string">
286
- <xsl:with-param name="text" select="$ampEscaped"/>
287
- <xsl:with-param name="replace" select="'&lt;'"/>
288
- <xsl:with-param name="with" select="'&amp;lt;'"/>
289
- </xsl:call-template>
290
- </xsl:variable>
291
- <!-- 2025-05-27: PreTeXt, R. Beezer. Escaped "greater-than". -->
292
- <!-- Inserted new step w/ "gtEscaped" variable -->
293
- <xsl:variable name="gtEscaped">
294
- <xsl:call-template name="replace-string">
295
- <xsl:with-param name="text" select="$ltEscaped"/>
296
- <xsl:with-param name="replace" select="'&gt;'"/>
297
- <xsl:with-param name="with" select="'&amp;gt;'"/>
298
- </xsl:call-template>
299
- </xsl:variable>
300
- <xsl:call-template name="replace-string">
301
- <xsl:with-param name="text" select="$gtEscaped"/>
302
- <xsl:with-param name="replace" select="']]>'"/>
303
- <xsl:with-param name="with" select="']]&amp;gt;'"/>
304
- </xsl:call-template>
305
- </xsl:template>
306
-
307
- <xsl:template name="replace-string">
308
- <xsl:param name="text"/>
309
- <xsl:param name="replace"/>
310
- <xsl:param name="with"/>
311
- <xsl:variable name="stringText" select="string($text)"/>
312
- <xsl:choose>
313
- <xsl:when test="contains($stringText,$replace)">
314
- <xsl:value-of select="substring-before($stringText,$replace)"/>
315
- <xsl:value-of select="$with"/>
316
- <xsl:call-template name="replace-string">
317
- <xsl:with-param name="text" select="substring-after($stringText,$replace)"/>
318
- <xsl:with-param name="replace" select="$replace"/>
319
- <xsl:with-param name="with" select="$with"/>
320
- </xsl:call-template>
321
- </xsl:when>
322
- <xsl:otherwise>
323
- <xsl:value-of select="$stringText"/>
324
- </xsl:otherwise>
325
- </xsl:choose>
326
- </xsl:template>
327
-
328
- </xsl:stylesheet>
1
+ <!--
2
+ Copyright (c) 2001-2009, Evan Lenz
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
+ * Neither the name of Lenz Consulting Group nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12
+
13
+ Recent changes:
14
+
15
+ 2010-06-10: Added the $force-exclude-all-namespaces parameter
16
+ 2009-10-19: Added the $exclude-these-namespaces parameter
17
+ 2009-10-08: Added $att-value parameter and template name to template rule for attributes.
18
+
19
+ 2025-05-27: PreTeXt, R. Beezer. Escaped "greater-than".
20
+
21
+ -->
22
+ <xsl:stylesheet version="1.0"
23
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
24
+
25
+ <xsl:output omit-xml-declaration="yes"/>
26
+
27
+ <xsl:param name="use-empty-syntax" select="true()"/>
28
+ <xsl:param name="exclude-unused-prefixes" select="true()"/>
29
+
30
+ <xsl:param name="force-exclude-all-namespaces" select="false()"/>
31
+
32
+ <!-- a node-set; each node's string-value
33
+ will be interpreted as a namespace URI to be
34
+ excluded from the serialization. -->
35
+ <xsl:param name="namespaces-to-exclude" select="/.."/>
36
+ <!-- initialized to empty node-set -->
37
+
38
+ <xsl:param name="start-tag-start" select="'&lt;'"/>
39
+ <xsl:param name="start-tag-end" select="'>'"/>
40
+ <xsl:param name="empty-tag-end" select="'/>'"/>
41
+ <xsl:param name="end-tag-start" select="'&lt;/'"/>
42
+ <xsl:param name="end-tag-end" select="'>'"/>
43
+ <xsl:param name="space" select="' '"/>
44
+ <xsl:param name="ns-decl" select="'xmlns'"/>
45
+ <xsl:param name="colon" select="':'"/>
46
+ <xsl:param name="equals" select="'='"/>
47
+ <xsl:param name="attribute-delimiter" select="'&quot;'"/>
48
+ <xsl:param name="comment-start" select="'&lt;!--'"/>
49
+ <xsl:param name="comment-end" select="'-->'"/>
50
+ <xsl:param name="pi-start" select="'&lt;?'"/>
51
+ <xsl:param name="pi-end" select="'?>'"/>
52
+
53
+ <xsl:template name="xml-to-string">
54
+ <xsl:param name="node-set" select="."/>
55
+ <xsl:apply-templates select="$node-set" mode="xml-to-string">
56
+ <xsl:with-param name="depth" select="1"/>
57
+ </xsl:apply-templates>
58
+ </xsl:template>
59
+
60
+ <xsl:template match="/" name="xml-to-string-root-rule">
61
+ <xsl:call-template name="xml-to-string"/>
62
+ </xsl:template>
63
+
64
+ <xsl:template match="/" mode="xml-to-string">
65
+ <xsl:param name="depth"/>
66
+ <xsl:apply-templates mode="xml-to-string">
67
+ <xsl:with-param name="depth" select="$depth"/>
68
+ </xsl:apply-templates>
69
+ </xsl:template>
70
+
71
+ <xsl:template match="*" mode="xml-to-string">
72
+ <xsl:param name="depth"/>
73
+ <xsl:variable name="element" select="."/>
74
+ <xsl:value-of select="$start-tag-start"/>
75
+ <xsl:call-template name="element-name">
76
+ <xsl:with-param name="text" select="name()"/>
77
+ </xsl:call-template>
78
+ <xsl:apply-templates select="@*" mode="xml-to-string"/>
79
+ <xsl:if test="not($force-exclude-all-namespaces)">
80
+ <xsl:for-each select="namespace::*">
81
+ <xsl:call-template name="process-namespace-node">
82
+ <xsl:with-param name="element" select="$element"/>
83
+ <xsl:with-param name="depth" select="$depth"/>
84
+ </xsl:call-template>
85
+ </xsl:for-each>
86
+ </xsl:if>
87
+ <xsl:choose>
88
+ <xsl:when test="node() or not($use-empty-syntax)">
89
+ <xsl:value-of select="$start-tag-end"/>
90
+ <xsl:apply-templates mode="xml-to-string">
91
+ <xsl:with-param name="depth" select="$depth + 1"/>
92
+ </xsl:apply-templates>
93
+ <xsl:value-of select="$end-tag-start"/>
94
+ <xsl:call-template name="element-name">
95
+ <xsl:with-param name="text" select="name()"/>
96
+ </xsl:call-template>
97
+ <xsl:value-of select="$end-tag-end"/>
98
+ </xsl:when>
99
+ <xsl:otherwise>
100
+ <xsl:value-of select="$empty-tag-end"/>
101
+ </xsl:otherwise>
102
+ </xsl:choose>
103
+ </xsl:template>
104
+
105
+ <xsl:template name="process-namespace-node">
106
+ <xsl:param name="element"/>
107
+ <xsl:param name="depth"/>
108
+ <xsl:variable name="declaredAbove">
109
+ <xsl:call-template name="isDeclaredAbove">
110
+ <xsl:with-param name="depth" select="$depth - 1"/>
111
+ <xsl:with-param name="element" select="$element/.."/>
112
+ </xsl:call-template>
113
+ </xsl:variable>
114
+
115
+ <xsl:variable name="is-used-on-this-element" select="($element | $element/@*) [namespace-uri() = current()]"/>
116
+ <xsl:variable name="is-used-on-a-descendant" select="($element//* | $element//@*)[namespace-uri() = current()]"/>
117
+ <xsl:variable name="is-unused" select="not($is-used-on-this-element) and
118
+ not($is-used-on-a-descendant)"/>
119
+ <xsl:variable name="exclude-ns" select="($is-unused and $exclude-unused-prefixes) or
120
+ (. = $namespaces-to-exclude)"/>
121
+
122
+ <xsl:variable name="force-include" select="$is-used-on-this-element and (. = $namespaces-to-exclude)"/>
123
+
124
+ <xsl:if test="(name() != 'xml') and ($force-include or (not($exclude-ns) and not(string($declaredAbove))))">
125
+ <xsl:value-of select="$space"/>
126
+ <xsl:value-of select="$ns-decl"/>
127
+ <xsl:if test="name()">
128
+ <xsl:value-of select="$colon"/>
129
+ <xsl:call-template name="ns-prefix">
130
+ <xsl:with-param name="text" select="name()"/>
131
+ </xsl:call-template>
132
+ </xsl:if>
133
+ <xsl:value-of select="$equals"/>
134
+ <xsl:value-of select="$attribute-delimiter"/>
135
+ <xsl:call-template name="ns-uri">
136
+ <xsl:with-param name="text" select="string(.)"/>
137
+ </xsl:call-template>
138
+ <xsl:value-of select="$attribute-delimiter"/>
139
+ </xsl:if>
140
+ </xsl:template>
141
+
142
+ <xsl:template name="isDeclaredAbove">
143
+ <xsl:param name="element"/>
144
+ <xsl:param name="depth"/>
145
+ <xsl:if test="$depth > 0">
146
+ <xsl:choose>
147
+ <xsl:when test="$element/namespace::*[name(.)=name(current()) and .=current()]">1</xsl:when>
148
+ <xsl:when test="$element/namespace::*[name(.)=name(current())]"/>
149
+ <xsl:otherwise>
150
+ <xsl:call-template name="isDeclaredAbove">
151
+ <xsl:with-param name="depth" select="$depth - 1"/>
152
+ <xsl:with-param name="element" select="$element/.."/>
153
+ </xsl:call-template>
154
+ </xsl:otherwise>
155
+ </xsl:choose>
156
+ </xsl:if>
157
+ </xsl:template>
158
+
159
+ <xsl:template match="@*" mode="xml-to-string" name="serialize-attribute">
160
+ <xsl:param name="att-value" select="string(.)"/>
161
+ <xsl:value-of select="$space"/>
162
+ <xsl:call-template name="attribute-name">
163
+ <xsl:with-param name="text" select="name()"/>
164
+ </xsl:call-template>
165
+ <xsl:value-of select="$equals"/>
166
+ <xsl:value-of select="$attribute-delimiter"/>
167
+ <xsl:call-template name="attribute-value">
168
+ <xsl:with-param name="text" select="$att-value"/>
169
+ </xsl:call-template>
170
+ <xsl:value-of select="$attribute-delimiter"/>
171
+ </xsl:template>
172
+
173
+ <xsl:template match="comment()" mode="xml-to-string">
174
+ <xsl:value-of select="$comment-start"/>
175
+ <xsl:call-template name="comment-text">
176
+ <xsl:with-param name="text" select="string(.)"/>
177
+ </xsl:call-template>
178
+ <xsl:value-of select="$comment-end"/>
179
+ </xsl:template>
180
+
181
+ <xsl:template match="processing-instruction()" mode="xml-to-string">
182
+ <xsl:value-of select="$pi-start"/>
183
+ <xsl:call-template name="pi-target">
184
+ <xsl:with-param name="text" select="name()"/>
185
+ </xsl:call-template>
186
+ <xsl:value-of select="$space"/>
187
+ <xsl:call-template name="pi-text">
188
+ <xsl:with-param name="text" select="string(.)"/>
189
+ </xsl:call-template>
190
+ <xsl:value-of select="$pi-end"/>
191
+ </xsl:template>
192
+
193
+ <xsl:template match="text()" mode="xml-to-string">
194
+ <xsl:call-template name="text-content">
195
+ <xsl:with-param name="text" select="string(.)"/>
196
+ </xsl:call-template>
197
+ </xsl:template>
198
+
199
+ <xsl:template name="element-name">
200
+ <xsl:param name="text"/>
201
+ <xsl:value-of select="$text"/>
202
+ </xsl:template>
203
+
204
+ <xsl:template name="attribute-name">
205
+ <xsl:param name="text"/>
206
+ <xsl:value-of select="$text"/>
207
+ </xsl:template>
208
+
209
+ <xsl:template name="attribute-value">
210
+ <xsl:param name="text"/>
211
+ <xsl:variable name="escaped-markup">
212
+ <xsl:call-template name="escape-markup-characters">
213
+ <xsl:with-param name="text" select="$text"/>
214
+ </xsl:call-template>
215
+ </xsl:variable>
216
+ <xsl:choose>
217
+ <xsl:when test="$attribute-delimiter = &quot;'&quot;">
218
+ <xsl:call-template name="replace-string">
219
+ <xsl:with-param name="text" select="$escaped-markup"/>
220
+ <xsl:with-param name="replace" select="&quot;'&quot;"/>
221
+ <xsl:with-param name="with" select="'&amp;apos;'"/>
222
+ </xsl:call-template>
223
+ </xsl:when>
224
+ <xsl:when test="$attribute-delimiter = '&quot;'">
225
+ <xsl:call-template name="replace-string">
226
+ <xsl:with-param name="text" select="$escaped-markup"/>
227
+ <xsl:with-param name="replace" select="'&quot;'"/>
228
+ <xsl:with-param name="with" select="'&amp;quot;'"/>
229
+ </xsl:call-template>
230
+ </xsl:when>
231
+ <xsl:otherwise>
232
+ <xsl:call-template name="replace-string">
233
+ <xsl:with-param name="text" select="$escaped-markup"/>
234
+ <xsl:with-param name="replace" select="$attribute-delimiter"/>
235
+ <xsl:with-param name="with" select="''"/>
236
+ </xsl:call-template>
237
+ </xsl:otherwise>
238
+ </xsl:choose>
239
+ </xsl:template>
240
+
241
+ <xsl:template name="ns-prefix">
242
+ <xsl:param name="text"/>
243
+ <xsl:value-of select="$text"/>
244
+ </xsl:template>
245
+
246
+ <xsl:template name="ns-uri">
247
+ <xsl:param name="text"/>
248
+ <xsl:call-template name="attribute-value">
249
+ <xsl:with-param name="text" select="$text"/>
250
+ </xsl:call-template>
251
+ </xsl:template>
252
+
253
+ <xsl:template name="text-content">
254
+ <xsl:param name="text"/>
255
+ <xsl:call-template name="escape-markup-characters">
256
+ <xsl:with-param name="text" select="$text"/>
257
+ </xsl:call-template>
258
+ </xsl:template>
259
+
260
+ <xsl:template name="pi-target">
261
+ <xsl:param name="text"/>
262
+ <xsl:value-of select="$text"/>
263
+ </xsl:template>
264
+
265
+ <xsl:template name="pi-text">
266
+ <xsl:param name="text"/>
267
+ <xsl:value-of select="$text"/>
268
+ </xsl:template>
269
+
270
+ <xsl:template name="comment-text">
271
+ <xsl:param name="text"/>
272
+ <xsl:value-of select="$text"/>
273
+ </xsl:template>
274
+
275
+ <xsl:template name="escape-markup-characters">
276
+ <xsl:param name="text"/>
277
+ <xsl:variable name="ampEscaped">
278
+ <xsl:call-template name="replace-string">
279
+ <xsl:with-param name="text" select="$text"/>
280
+ <xsl:with-param name="replace" select="'&amp;'"/>
281
+ <xsl:with-param name="with" select="'&amp;amp;'"/>
282
+ </xsl:call-template>
283
+ </xsl:variable>
284
+ <xsl:variable name="ltEscaped">
285
+ <xsl:call-template name="replace-string">
286
+ <xsl:with-param name="text" select="$ampEscaped"/>
287
+ <xsl:with-param name="replace" select="'&lt;'"/>
288
+ <xsl:with-param name="with" select="'&amp;lt;'"/>
289
+ </xsl:call-template>
290
+ </xsl:variable>
291
+ <!-- 2025-05-27: PreTeXt, R. Beezer. Escaped "greater-than". -->
292
+ <!-- Inserted new step w/ "gtEscaped" variable -->
293
+ <xsl:variable name="gtEscaped">
294
+ <xsl:call-template name="replace-string">
295
+ <xsl:with-param name="text" select="$ltEscaped"/>
296
+ <xsl:with-param name="replace" select="'&gt;'"/>
297
+ <xsl:with-param name="with" select="'&amp;gt;'"/>
298
+ </xsl:call-template>
299
+ </xsl:variable>
300
+ <xsl:call-template name="replace-string">
301
+ <xsl:with-param name="text" select="$gtEscaped"/>
302
+ <xsl:with-param name="replace" select="']]>'"/>
303
+ <xsl:with-param name="with" select="']]&amp;gt;'"/>
304
+ </xsl:call-template>
305
+ </xsl:template>
306
+
307
+ <xsl:template name="replace-string">
308
+ <xsl:param name="text"/>
309
+ <xsl:param name="replace"/>
310
+ <xsl:param name="with"/>
311
+ <xsl:variable name="stringText" select="string($text)"/>
312
+ <xsl:choose>
313
+ <xsl:when test="contains($stringText,$replace)">
314
+ <xsl:value-of select="substring-before($stringText,$replace)"/>
315
+ <xsl:value-of select="$with"/>
316
+ <xsl:call-template name="replace-string">
317
+ <xsl:with-param name="text" select="substring-after($stringText,$replace)"/>
318
+ <xsl:with-param name="replace" select="$replace"/>
319
+ <xsl:with-param name="with" select="$with"/>
320
+ </xsl:call-template>
321
+ </xsl:when>
322
+ <xsl:otherwise>
323
+ <xsl:value-of select="$stringText"/>
324
+ </xsl:otherwise>
325
+ </xsl:choose>
326
+ </xsl:template>
327
+
328
+ </xsl:stylesheet>