@tradik/xslt-processor 1.1.1 → 1.3.0

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 (122) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +102 -757
  3. package/bin/lib/decode.js +15 -0
  4. package/bin/lib/dom.js +177 -0
  5. package/bin/lib/loaders.js +127 -0
  6. package/bin/lib/options.js +17 -0
  7. package/bin/lib/output.js +114 -0
  8. package/bin/lib/paths.js +3 -3
  9. package/bin/lib/transform.js +124 -33
  10. package/bin/xslt.js +26 -27
  11. package/dist/xslt-processor.browser.js +8784 -2720
  12. package/dist/xslt-processor.browser.js.map +4 -4
  13. package/dist/xslt-processor.browser.min.js +13 -6
  14. package/dist/xslt-processor.browser.min.js.map +4 -4
  15. package/dist/xslt-processor.cjs +8789 -2723
  16. package/dist/xslt-processor.cjs.map +4 -4
  17. package/dist/xslt-processor.d.cts +380 -21
  18. package/dist/xslt-processor.d.ts +380 -21
  19. package/dist/xslt-processor.js +8770 -2722
  20. package/dist/xslt-processor.js.map +4 -4
  21. package/package.json +51 -11
  22. package/src/XSLTProcessor.js +343 -66
  23. package/src/async/abort.js +63 -0
  24. package/src/async/documentUris.js +128 -0
  25. package/src/async/loaders.js +134 -0
  26. package/src/async/preload.js +159 -0
  27. package/src/async/processor.js +206 -0
  28. package/src/async/stream.js +125 -0
  29. package/src/bridge/engine.js +221 -0
  30. package/src/bridge/loader.js +78 -0
  31. package/src/bridge/results.js +75 -0
  32. package/src/bridge/version.js +63 -0
  33. package/src/index.js +16 -4
  34. package/src/io/decode.js +140 -0
  35. package/src/io/readSource.js +167 -0
  36. package/src/xpath/axes.js +562 -0
  37. package/src/xpath/documentOrder.js +270 -0
  38. package/src/xpath/evaluator.js +475 -355
  39. package/src/xpath/index.js +8 -2
  40. package/src/xpath/namespaceNodes.js +172 -0
  41. package/src/xpath/nodeSetFunctions.js +169 -0
  42. package/src/xpath/parser.js +30 -5
  43. package/src/xpath/strings.js +183 -0
  44. package/src/xpath/tokenizer.js +37 -23
  45. package/src/xslt/attributeSets.js +95 -0
  46. package/src/xslt/avt.js +103 -0
  47. package/src/xslt/computedNames.js +91 -0
  48. package/src/xslt/copying.js +212 -0
  49. package/src/xslt/declarationNames.js +80 -0
  50. package/src/xslt/domParsing.js +95 -0
  51. package/src/xslt/elements.js +1 -1
  52. package/src/xslt/engine/bindings.js +195 -0
  53. package/src/xslt/engine/context.js +105 -0
  54. package/src/xslt/engine/controlFlow.js +145 -0
  55. package/src/xslt/engine/copyInstructions.js +133 -0
  56. package/src/xslt/engine/declarations.js +233 -0
  57. package/src/xslt/engine/functionSupport.js +103 -0
  58. package/src/xslt/engine/methods.js +33 -0
  59. package/src/xslt/engine/nodeConstruction.js +187 -0
  60. package/src/xslt/engine/numbering.js +104 -0
  61. package/src/xslt/engine/outputDeclaration.js +77 -0
  62. package/src/xslt/engine/sequenceConstructor.js +228 -0
  63. package/src/xslt/engine/stylesheetLoading.js +208 -0
  64. package/src/xslt/engine/templateInvocation.js +253 -0
  65. package/src/xslt/engine/templateRules.js +243 -0
  66. package/src/xslt/engine/textInstructions.js +171 -0
  67. package/src/xslt/engine/topLevel.js +130 -0
  68. package/src/xslt/engine/transformation.js +263 -0
  69. package/src/xslt/engine/workStack.js +245 -0
  70. package/src/xslt/engine.js +176 -2020
  71. package/src/xslt/exslt/arguments.js +99 -0
  72. package/src/xslt/exslt/calendar.js +120 -0
  73. package/src/xslt/exslt/common.js +44 -0
  74. package/src/xslt/exslt/dateCalc.js +261 -0
  75. package/src/xslt/exslt/dateFormat.js +150 -0
  76. package/src/xslt/exslt/dateParse.js +265 -0
  77. package/src/xslt/exslt/dates.js +259 -0
  78. package/src/xslt/exslt/duration.js +207 -0
  79. package/src/xslt/exslt/dynamic.js +59 -0
  80. package/src/xslt/exslt/index.js +59 -0
  81. package/src/xslt/exslt/math.js +177 -0
  82. package/src/xslt/exslt/sets.js +96 -0
  83. package/src/xslt/exslt/stringOps.js +163 -0
  84. package/src/xslt/exslt/strings.js +147 -0
  85. package/src/xslt/exslt/uri.js +92 -0
  86. package/src/xslt/formatNumber.js +22 -9
  87. package/src/xslt/forwardsCompatible.js +75 -0
  88. package/src/xslt/functions.js +94 -15
  89. package/src/xslt/index.js +7 -1
  90. package/src/xslt/keys.js +51 -28
  91. package/src/xslt/literalResult.js +63 -7
  92. package/src/xslt/matchScope.js +116 -0
  93. package/src/xslt/number.js +171 -78
  94. package/src/xslt/numberFormat.js +124 -26
  95. package/src/xslt/outputNames.js +58 -0
  96. package/src/xslt/patternCompiler.js +175 -0
  97. package/src/xslt/patterns.js +324 -0
  98. package/src/xslt/qname.js +90 -0
  99. package/src/xslt/resultDocument.js +98 -0
  100. package/src/xslt/resultNamespaces.js +219 -0
  101. package/src/xslt/resultTree.js +143 -6
  102. package/src/xslt/serializer/baseWriter.js +173 -66
  103. package/src/xslt/serializer/chunks.js +120 -0
  104. package/src/xslt/serializer/constants.js +14 -0
  105. package/src/xslt/serializer/encoding.js +327 -0
  106. package/src/xslt/serializer/escape.js +49 -12
  107. package/src/xslt/serializer/frames.js +168 -0
  108. package/src/xslt/serializer/htmlDoctype.js +102 -0
  109. package/src/xslt/serializer/htmlEntities.js +77 -0
  110. package/src/xslt/serializer/htmlSerializer.js +123 -25
  111. package/src/xslt/serializer/settings.js +89 -13
  112. package/src/xslt/serializer/textSerializer.js +58 -10
  113. package/src/xslt/serializer/xhtmlDocument.js +103 -0
  114. package/src/xslt/serializer/xmlSerializer.js +113 -13
  115. package/src/xslt/serializer.js +50 -17
  116. package/src/xslt/sort.js +151 -0
  117. package/src/xslt/spaceNameTests.js +115 -0
  118. package/src/xslt/stylesheetChecks.js +206 -0
  119. package/src/xslt/stylesheetNamespaces.js +266 -0
  120. package/src/xslt/variables.js +152 -0
  121. package/src/xslt/whitespace.js +43 -27
  122. package/LICENSE +0 -29
@@ -9,37 +9,47 @@
9
9
 
10
10
  "use strict";
11
11
 
12
+ import { isTextContinuation, isTextNode } from "../xpath/axes.js";
13
+ import { matchesNameTest, nameTestPriority } from "./spaceNameTests.js";
14
+
12
15
  /** Node type of a document type declaration, which cannot be imported. */
13
16
  const DOCUMENT_TYPE_NODE = 10;
14
17
 
18
+ /** Text made only of XML whitespace: #x20, #x9, #xD and #xA (not NBSP). */
19
+ const XML_WHITESPACE_ONLY = /^[ \t\r\n]*$/;
20
+
15
21
  /**
16
- * Compute the XSLT default priority of an element name test.
22
+ * Whether a string consists of XML whitespace only (XML 1.0 production S).
23
+ * Unlike `trim()` and `\s`, a no-break space is not whitespace.
17
24
  *
18
- * @param {string} nameTest - A name test such as `*`, `ns:*` or `item`
19
- * @returns {number} The default priority
25
+ * @param {string} text - Any string
26
+ * @returns {boolean} True for "" and strings of #x20 #x9 #xD #xA
27
+ *
28
+ * @example
29
+ * isXmlWhitespace(" \n"); // true
30
+ * isXmlWhitespace("\u00a0"); // false
20
31
  */
21
- function nameTestPriority(nameTest) {
22
- if (nameTest === "*") return -0.5;
23
- if (nameTest.endsWith(":*")) return -0.25;
24
- return 0;
32
+ export function isXmlWhitespace(text) {
33
+ return XML_WHITESPACE_ONLY.test(text);
25
34
  }
26
35
 
27
36
  /**
28
- * Check whether an element matches a name test.
37
+ * The DOM nodes of the text run starting at a node: the node and every
38
+ * directly following Text/CDATA sibling (one XPath text node).
29
39
  *
30
- * @param {Element} element - The element to test
31
- * @param {string} nameTest - A name test such as `*`, `ns:*` or `item`
32
- * @returns {boolean} True when the element matches
40
+ * @param {Node} first - The first node of the run
41
+ * @returns {Node[]} The nodes of the run
33
42
  */
34
- function matchesNameTest(element, nameTest) {
35
- if (nameTest === "*") return true;
36
-
37
- if (nameTest.endsWith(":*")) {
38
- const prefix = nameTest.slice(0, -2);
39
- return element.nodeName.startsWith(`${prefix}:`);
43
+ export function textRun(first) {
44
+ const run = [first];
45
+ for (
46
+ let next = first.nextSibling;
47
+ isTextNode(next);
48
+ next = next.nextSibling
49
+ ) {
50
+ run.push(next);
40
51
  }
41
-
42
- return element.nodeName === nameTest || element.localName === nameTest;
52
+ return run;
43
53
  }
44
54
 
45
55
  /**
@@ -47,8 +57,11 @@ function matchesNameTest(element, nameTest) {
47
57
  */
48
58
  export class WhitespaceFilter {
49
59
  /**
50
- * @param {string[]} [stripSpace] - Name tests from `xsl:strip-space`
51
- * @param {string[]} [preserveSpace] - Name tests from `xsl:preserve-space`
60
+ * @param {Array<string|import('./spaceNameTests.js').ElementNameTest>} [stripSpace] -
61
+ * Name tests from `xsl:strip-space`: expanded (see spaceNameTests.js),
62
+ * or strings matched by their lexical name
63
+ * @param {Array<string|import('./spaceNameTests.js').ElementNameTest>} [preserveSpace] -
64
+ * Name tests from `xsl:preserve-space`
52
65
  */
53
66
  constructor(stripSpace = [], preserveSpace = []) {
54
67
  this.stripSpace = stripSpace;
@@ -121,7 +134,8 @@ function hasXmlSpacePreserve(node) {
121
134
  }
122
135
 
123
136
  /**
124
- * Remove whitespace-only text nodes from a subtree.
137
+ * Remove whitespace-only text nodes from a subtree. Adjacent Text/CDATA
138
+ * nodes form one text node and are only removed together.
125
139
  *
126
140
  * @param {Node} root - The root of the subtree to prune
127
141
  * @param {WhitespaceFilter} filter - The configured filter
@@ -135,14 +149,16 @@ function pruneWhitespace(root, filter) {
135
149
  const current = stack.pop();
136
150
 
137
151
  if (
138
- (current.nodeType === 3 || current.nodeType === 4) &&
139
- current.nodeValue !== null &&
140
- current.nodeValue.trim() === "" &&
152
+ isTextNode(current) &&
153
+ !isTextContinuation(current) &&
141
154
  current.parentNode?.nodeType === 1 &&
142
155
  filter.isStripped(current.parentNode) &&
143
156
  !hasXmlSpacePreserve(current.parentNode)
144
157
  ) {
145
- doomed.push(current);
158
+ const run = textRun(current);
159
+ if (run.every((node) => isXmlWhitespace(node.nodeValue))) {
160
+ doomed.push(...run);
161
+ }
146
162
  }
147
163
 
148
164
  const children = current.childNodes;
@@ -151,7 +167,7 @@ function pruneWhitespace(root, filter) {
151
167
  }
152
168
  }
153
169
 
154
- for (const node of doomed) node.remove();
170
+ for (const node of doomed) node.parentNode.removeChild(node);
155
171
  }
156
172
 
157
173
  /**
package/LICENSE DELETED
@@ -1,29 +0,0 @@
1
- BSD 3-Clause License
2
-
3
- Copyright (c) 2026, XSLT-Processor Contributors
4
- All rights reserved.
5
-
6
- Redistribution and use in source and binary forms, with or without
7
- modification, are permitted provided that the following conditions are met:
8
-
9
- 1. Redistributions of source code must retain the above copyright notice, this
10
- list of conditions and the following disclaimer.
11
-
12
- 2. Redistributions in binary form must reproduce the above copyright notice,
13
- this list of conditions and the following disclaimer in the documentation
14
- and/or other materials provided with the distribution.
15
-
16
- 3. Neither the name of the copyright holder nor the names of its
17
- contributors may be used to endorse or promote products derived from
18
- this software without specific prior written permission.
19
-
20
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.