@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.
- package/LICENSE.md +1 -1
- package/README.md +102 -757
- package/bin/lib/decode.js +15 -0
- package/bin/lib/dom.js +177 -0
- package/bin/lib/loaders.js +127 -0
- package/bin/lib/options.js +17 -0
- package/bin/lib/output.js +114 -0
- package/bin/lib/paths.js +3 -3
- package/bin/lib/transform.js +124 -33
- package/bin/xslt.js +26 -27
- package/dist/xslt-processor.browser.js +8784 -2720
- package/dist/xslt-processor.browser.js.map +4 -4
- package/dist/xslt-processor.browser.min.js +13 -6
- package/dist/xslt-processor.browser.min.js.map +4 -4
- package/dist/xslt-processor.cjs +8789 -2723
- package/dist/xslt-processor.cjs.map +4 -4
- package/dist/xslt-processor.d.cts +380 -21
- package/dist/xslt-processor.d.ts +380 -21
- package/dist/xslt-processor.js +8770 -2722
- package/dist/xslt-processor.js.map +4 -4
- package/package.json +51 -11
- package/src/XSLTProcessor.js +343 -66
- package/src/async/abort.js +63 -0
- package/src/async/documentUris.js +128 -0
- package/src/async/loaders.js +134 -0
- package/src/async/preload.js +159 -0
- package/src/async/processor.js +206 -0
- package/src/async/stream.js +125 -0
- package/src/bridge/engine.js +221 -0
- package/src/bridge/loader.js +78 -0
- package/src/bridge/results.js +75 -0
- package/src/bridge/version.js +63 -0
- package/src/index.js +16 -4
- package/src/io/decode.js +140 -0
- package/src/io/readSource.js +167 -0
- package/src/xpath/axes.js +562 -0
- package/src/xpath/documentOrder.js +270 -0
- package/src/xpath/evaluator.js +475 -355
- package/src/xpath/index.js +8 -2
- package/src/xpath/namespaceNodes.js +172 -0
- package/src/xpath/nodeSetFunctions.js +169 -0
- package/src/xpath/parser.js +30 -5
- package/src/xpath/strings.js +183 -0
- package/src/xpath/tokenizer.js +37 -23
- package/src/xslt/attributeSets.js +95 -0
- package/src/xslt/avt.js +103 -0
- package/src/xslt/computedNames.js +91 -0
- package/src/xslt/copying.js +212 -0
- package/src/xslt/declarationNames.js +80 -0
- package/src/xslt/domParsing.js +95 -0
- package/src/xslt/elements.js +1 -1
- package/src/xslt/engine/bindings.js +195 -0
- package/src/xslt/engine/context.js +105 -0
- package/src/xslt/engine/controlFlow.js +145 -0
- package/src/xslt/engine/copyInstructions.js +133 -0
- package/src/xslt/engine/declarations.js +233 -0
- package/src/xslt/engine/functionSupport.js +103 -0
- package/src/xslt/engine/methods.js +33 -0
- package/src/xslt/engine/nodeConstruction.js +187 -0
- package/src/xslt/engine/numbering.js +104 -0
- package/src/xslt/engine/outputDeclaration.js +77 -0
- package/src/xslt/engine/sequenceConstructor.js +228 -0
- package/src/xslt/engine/stylesheetLoading.js +208 -0
- package/src/xslt/engine/templateInvocation.js +253 -0
- package/src/xslt/engine/templateRules.js +243 -0
- package/src/xslt/engine/textInstructions.js +171 -0
- package/src/xslt/engine/topLevel.js +130 -0
- package/src/xslt/engine/transformation.js +263 -0
- package/src/xslt/engine/workStack.js +245 -0
- package/src/xslt/engine.js +176 -2020
- package/src/xslt/exslt/arguments.js +99 -0
- package/src/xslt/exslt/calendar.js +120 -0
- package/src/xslt/exslt/common.js +44 -0
- package/src/xslt/exslt/dateCalc.js +261 -0
- package/src/xslt/exslt/dateFormat.js +150 -0
- package/src/xslt/exslt/dateParse.js +265 -0
- package/src/xslt/exslt/dates.js +259 -0
- package/src/xslt/exslt/duration.js +207 -0
- package/src/xslt/exslt/dynamic.js +59 -0
- package/src/xslt/exslt/index.js +59 -0
- package/src/xslt/exslt/math.js +177 -0
- package/src/xslt/exslt/sets.js +96 -0
- package/src/xslt/exslt/stringOps.js +163 -0
- package/src/xslt/exslt/strings.js +147 -0
- package/src/xslt/exslt/uri.js +92 -0
- package/src/xslt/formatNumber.js +22 -9
- package/src/xslt/forwardsCompatible.js +75 -0
- package/src/xslt/functions.js +94 -15
- package/src/xslt/index.js +7 -1
- package/src/xslt/keys.js +51 -28
- package/src/xslt/literalResult.js +63 -7
- package/src/xslt/matchScope.js +116 -0
- package/src/xslt/number.js +171 -78
- package/src/xslt/numberFormat.js +124 -26
- package/src/xslt/outputNames.js +58 -0
- package/src/xslt/patternCompiler.js +175 -0
- package/src/xslt/patterns.js +324 -0
- package/src/xslt/qname.js +90 -0
- package/src/xslt/resultDocument.js +98 -0
- package/src/xslt/resultNamespaces.js +219 -0
- package/src/xslt/resultTree.js +143 -6
- package/src/xslt/serializer/baseWriter.js +173 -66
- package/src/xslt/serializer/chunks.js +120 -0
- package/src/xslt/serializer/constants.js +14 -0
- package/src/xslt/serializer/encoding.js +327 -0
- package/src/xslt/serializer/escape.js +49 -12
- package/src/xslt/serializer/frames.js +168 -0
- package/src/xslt/serializer/htmlDoctype.js +102 -0
- package/src/xslt/serializer/htmlEntities.js +77 -0
- package/src/xslt/serializer/htmlSerializer.js +123 -25
- package/src/xslt/serializer/settings.js +89 -13
- package/src/xslt/serializer/textSerializer.js +58 -10
- package/src/xslt/serializer/xhtmlDocument.js +103 -0
- package/src/xslt/serializer/xmlSerializer.js +113 -13
- package/src/xslt/serializer.js +50 -17
- package/src/xslt/sort.js +151 -0
- package/src/xslt/spaceNameTests.js +115 -0
- package/src/xslt/stylesheetChecks.js +206 -0
- package/src/xslt/stylesheetNamespaces.js +266 -0
- package/src/xslt/variables.js +152 -0
- package/src/xslt/whitespace.js +43 -27
- package/LICENSE +0 -29
package/src/xslt/whitespace.js
CHANGED
|
@@ -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
|
-
*
|
|
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}
|
|
19
|
-
* @returns {
|
|
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
|
|
22
|
-
|
|
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
|
-
*
|
|
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 {
|
|
31
|
-
* @
|
|
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
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
|
51
|
-
*
|
|
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
|
|
139
|
-
current
|
|
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
|
-
|
|
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.
|
|
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.
|