xslt-processor 5.0.4 → 5.0.6
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/README.md +1 -1
- package/dist/README.md +1 -1
- package/dist/index.d.mts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +32 -99
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -98
- package/dist/index.mjs.map +1 -1
- package/dist/umd/xslt-processor.global.js +5 -5
- package/dist/umd/xslt-processor.global.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -296,7 +296,7 @@ console.log(result2); // "<users><user>John</user></users>" (XML)
|
|
|
296
296
|
You can simply add a tag like this:
|
|
297
297
|
|
|
298
298
|
```html
|
|
299
|
-
<script type="application/javascript" src="https://unpkg.com/xslt-processor@latest/umd/xslt-processor.global.js"></script>
|
|
299
|
+
<script type="application/javascript" src="https://unpkg.com/xslt-processor@latest/dist/umd/xslt-processor.global.js"></script>
|
|
300
300
|
```
|
|
301
301
|
|
|
302
302
|
All the exports will live under `globalThis.XsltProcessor` and `window.XsltProcessor`. [See a usage example here](https://github.com/DesignLiquido/xslt-processor/blob/main/interactive-tests/xslt.html).
|
package/dist/README.md
CHANGED
|
@@ -296,7 +296,7 @@ console.log(result2); // "<users><user>John</user></users>" (XML)
|
|
|
296
296
|
You can simply add a tag like this:
|
|
297
297
|
|
|
298
298
|
```html
|
|
299
|
-
<script type="application/javascript" src="https://unpkg.com/xslt-processor@latest/umd/xslt-processor.global.js"></script>
|
|
299
|
+
<script type="application/javascript" src="https://unpkg.com/xslt-processor@latest/dist/umd/xslt-processor.global.js"></script>
|
|
300
300
|
```
|
|
301
301
|
|
|
302
302
|
All the exports will live under `globalThis.XsltProcessor` and `window.XsltProcessor`. [See a usage example here](https://github.com/DesignLiquido/xslt-processor/blob/main/interactive-tests/xslt.html).
|
package/dist/index.d.mts
CHANGED
|
@@ -86,6 +86,22 @@ declare class XDocument extends XNode {
|
|
|
86
86
|
*/
|
|
87
87
|
declare function domDocumentToXDocument(nativeNode: Document | Node): XDocument;
|
|
88
88
|
|
|
89
|
+
type XmlOutputOptions = {
|
|
90
|
+
cData: boolean;
|
|
91
|
+
escape: boolean;
|
|
92
|
+
selfClosingTags: boolean;
|
|
93
|
+
outputMethod: 'xml' | 'html' | 'text' | 'name' | 'xhtml';
|
|
94
|
+
outputVersion?: string;
|
|
95
|
+
itemSeparator?: string;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Returns the representation of a node as XML text.
|
|
100
|
+
* @param {XNode} node The starting node.
|
|
101
|
+
* @param {XmlOutputOptions} options XML output options.
|
|
102
|
+
* @returns The XML string.
|
|
103
|
+
*/
|
|
104
|
+
declare function xmlTransformedText(node: XNode, options?: XmlOutputOptions): string;
|
|
89
105
|
/**
|
|
90
106
|
* Escape XML special markup characters: tag delimiter <, >, and entity
|
|
91
107
|
* reference start delimiter &. The escaped string can be used in XML
|
|
@@ -1771,4 +1787,4 @@ declare class Xslt {
|
|
|
1771
1787
|
protected isXsltElement(element: XNode, opt_wantedName?: string): boolean;
|
|
1772
1788
|
}
|
|
1773
1789
|
|
|
1774
|
-
export { ExprContext, XDocument, XNode, XPath, XmlParser, Xslt, type XsltOptions, domDocumentToXDocument, xmlEscapeText };
|
|
1790
|
+
export { ExprContext, XDocument, XNode, XPath, XmlParser, Xslt, type XsltOptions, domDocumentToXDocument, xmlEscapeText, xmlTransformedText };
|
package/dist/index.d.ts
CHANGED
|
@@ -86,6 +86,22 @@ declare class XDocument extends XNode {
|
|
|
86
86
|
*/
|
|
87
87
|
declare function domDocumentToXDocument(nativeNode: Document | Node): XDocument;
|
|
88
88
|
|
|
89
|
+
type XmlOutputOptions = {
|
|
90
|
+
cData: boolean;
|
|
91
|
+
escape: boolean;
|
|
92
|
+
selfClosingTags: boolean;
|
|
93
|
+
outputMethod: 'xml' | 'html' | 'text' | 'name' | 'xhtml';
|
|
94
|
+
outputVersion?: string;
|
|
95
|
+
itemSeparator?: string;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Returns the representation of a node as XML text.
|
|
100
|
+
* @param {XNode} node The starting node.
|
|
101
|
+
* @param {XmlOutputOptions} options XML output options.
|
|
102
|
+
* @returns The XML string.
|
|
103
|
+
*/
|
|
104
|
+
declare function xmlTransformedText(node: XNode, options?: XmlOutputOptions): string;
|
|
89
105
|
/**
|
|
90
106
|
* Escape XML special markup characters: tag delimiter <, >, and entity
|
|
91
107
|
* reference start delimiter &. The escaped string can be used in XML
|
|
@@ -1771,4 +1787,4 @@ declare class Xslt {
|
|
|
1771
1787
|
protected isXsltElement(element: XNode, opt_wantedName?: string): boolean;
|
|
1772
1788
|
}
|
|
1773
1789
|
|
|
1774
|
-
export { ExprContext, XDocument, XNode, XPath, XmlParser, Xslt, type XsltOptions, domDocumentToXDocument, xmlEscapeText };
|
|
1790
|
+
export { ExprContext, XDocument, XNode, XPath, XmlParser, Xslt, type XsltOptions, domDocumentToXDocument, xmlEscapeText, xmlTransformedText };
|
package/dist/index.js
CHANGED
|
@@ -6328,9 +6328,9 @@ var init_function_call_expression = __esm({
|
|
|
6328
6328
|
case "concat":
|
|
6329
6329
|
return evaluatedArgs.map((arg) => this.convertToString(arg)).join("");
|
|
6330
6330
|
case "starts-with":
|
|
6331
|
-
return
|
|
6331
|
+
return this.convertToString(evaluatedArgs[0]).startsWith(this.convertToString(evaluatedArgs[1]));
|
|
6332
6332
|
case "contains":
|
|
6333
|
-
return
|
|
6333
|
+
return this.convertToString(evaluatedArgs[0]).includes(this.convertToString(evaluatedArgs[1]));
|
|
6334
6334
|
case "substring-before":
|
|
6335
6335
|
return this.substringBefore(evaluatedArgs);
|
|
6336
6336
|
case "substring-after":
|
|
@@ -6476,13 +6476,13 @@ var init_function_call_expression = __esm({
|
|
|
6476
6476
|
return Number(value);
|
|
6477
6477
|
}
|
|
6478
6478
|
stringValue(args, context) {
|
|
6479
|
-
var _a, _b
|
|
6479
|
+
var _a, _b;
|
|
6480
6480
|
if (args.length === 0) {
|
|
6481
6481
|
return (_b = (_a = context.node) == null ? void 0 : _a.textContent) != null ? _b : "";
|
|
6482
6482
|
}
|
|
6483
6483
|
const value = args[0];
|
|
6484
6484
|
if (Array.isArray(value) && value.length > 0) {
|
|
6485
|
-
return
|
|
6485
|
+
return this.getNodeStringValue(value[0]);
|
|
6486
6486
|
}
|
|
6487
6487
|
return String(value);
|
|
6488
6488
|
}
|
|
@@ -6515,6 +6515,9 @@ var init_function_call_expression = __esm({
|
|
|
6515
6515
|
if (!node) {
|
|
6516
6516
|
return "";
|
|
6517
6517
|
}
|
|
6518
|
+
if (typeof node === "string") return node;
|
|
6519
|
+
if (typeof node === "number") return String(node);
|
|
6520
|
+
if (typeof node === "boolean") return node ? "true" : "false";
|
|
6518
6521
|
if (typeof node.textContent === "string") {
|
|
6519
6522
|
return node.textContent;
|
|
6520
6523
|
}
|
|
@@ -6552,26 +6555,26 @@ var init_function_call_expression = __esm({
|
|
|
6552
6555
|
if (args.length === 0) {
|
|
6553
6556
|
return this.stringValue([], context).length;
|
|
6554
6557
|
}
|
|
6555
|
-
return
|
|
6558
|
+
return this.convertToString(args[0]).length;
|
|
6556
6559
|
}
|
|
6557
6560
|
normalizeSpace(args, context) {
|
|
6558
|
-
const str = args.length === 0 ? this.stringValue([], context) :
|
|
6561
|
+
const str = args.length === 0 ? this.stringValue([], context) : this.convertToString(args[0]);
|
|
6559
6562
|
return str.trim().replace(/\s+/g, " ");
|
|
6560
6563
|
}
|
|
6561
6564
|
substringBefore(args) {
|
|
6562
|
-
const str =
|
|
6563
|
-
const search =
|
|
6565
|
+
const str = this.convertToString(args[0]);
|
|
6566
|
+
const search = this.convertToString(args[1]);
|
|
6564
6567
|
const index = str.indexOf(search);
|
|
6565
6568
|
return index === -1 ? "" : str.substring(0, index);
|
|
6566
6569
|
}
|
|
6567
6570
|
substringAfter(args) {
|
|
6568
|
-
const str =
|
|
6569
|
-
const search =
|
|
6571
|
+
const str = this.convertToString(args[0]);
|
|
6572
|
+
const search = this.convertToString(args[1]);
|
|
6570
6573
|
const index = str.indexOf(search);
|
|
6571
6574
|
return index === -1 ? "" : str.substring(index + search.length);
|
|
6572
6575
|
}
|
|
6573
6576
|
substring(args) {
|
|
6574
|
-
const str =
|
|
6577
|
+
const str = this.convertToString(args[0]);
|
|
6575
6578
|
const start = Math.round(Number(args[1])) - 1;
|
|
6576
6579
|
if (args.length === 2) {
|
|
6577
6580
|
return str.substring(Math.max(0, start));
|
|
@@ -6585,9 +6588,9 @@ var init_function_call_expression = __esm({
|
|
|
6585
6588
|
return str.substring(adjustedStart, adjustedStart + adjustedLength);
|
|
6586
6589
|
}
|
|
6587
6590
|
translate(args) {
|
|
6588
|
-
const str =
|
|
6589
|
-
const from =
|
|
6590
|
-
const to =
|
|
6591
|
+
const str = this.convertToString(args[0]);
|
|
6592
|
+
const from = this.convertToString(args[1]);
|
|
6593
|
+
const to = this.convertToString(args[2]);
|
|
6591
6594
|
let result = "";
|
|
6592
6595
|
for (const char of str) {
|
|
6593
6596
|
const index = from.indexOf(char);
|
|
@@ -6625,7 +6628,7 @@ var init_function_call_expression = __esm({
|
|
|
6625
6628
|
if (!Array.isArray(nodeSet)) return 0;
|
|
6626
6629
|
return nodeSet.reduce((acc, node) => {
|
|
6627
6630
|
var _a;
|
|
6628
|
-
const value = Number((_a = node == null ? void 0 : node.textContent) != null ? _a : node);
|
|
6631
|
+
const value = Number((_a = node == null ? void 0 : node.textContent) != null ? _a : this.getNodeStringValue(node));
|
|
6629
6632
|
return acc + (isNaN(value) ? 0 : value);
|
|
6630
6633
|
}, 0);
|
|
6631
6634
|
}
|
|
@@ -7816,7 +7819,8 @@ __export(index_exports, {
|
|
|
7816
7819
|
XmlParser: () => XmlParser,
|
|
7817
7820
|
Xslt: () => Xslt,
|
|
7818
7821
|
domDocumentToXDocument: () => domDocumentToXDocument,
|
|
7819
|
-
xmlEscapeText: () => xmlEscapeText
|
|
7822
|
+
xmlEscapeText: () => xmlEscapeText,
|
|
7823
|
+
xmlTransformedText: () => xmlTransformedText
|
|
7820
7824
|
});
|
|
7821
7825
|
module.exports = __toCommonJS(index_exports);
|
|
7822
7826
|
|
|
@@ -11024,7 +11028,7 @@ function xmlTransformedTextRecursive(node, buffer, options) {
|
|
|
11024
11028
|
}
|
|
11025
11029
|
} else if (nodeType == DOM_COMMENT_NODE) {
|
|
11026
11030
|
if (options.outputMethod !== "text") {
|
|
11027
|
-
buffer.push(
|
|
11031
|
+
buffer.push(`<!--${nodeValue}-->`);
|
|
11028
11032
|
}
|
|
11029
11033
|
} else if (nodeType === DOM_PROCESSING_INSTRUCTION_NODE) {
|
|
11030
11034
|
if (options.outputMethod !== "text") {
|
|
@@ -11462,14 +11466,14 @@ var XmlParser = class {
|
|
|
11462
11466
|
}
|
|
11463
11467
|
if (htmlText.slice(i + 1, i + 4) === "!--") {
|
|
11464
11468
|
let endTagIndex = htmlText.slice(i + 4).indexOf("-->");
|
|
11465
|
-
if (endTagIndex) {
|
|
11469
|
+
if (endTagIndex >= 0) {
|
|
11466
11470
|
let node = domCreateComment(xmlDocument, htmlText.slice(i + 4, i + endTagIndex + 4));
|
|
11467
11471
|
domAppendChild(parent, node);
|
|
11468
11472
|
i += endTagIndex + 6;
|
|
11469
11473
|
}
|
|
11470
11474
|
} else if (htmlText.slice(i + 1, i + 9) === "!DOCTYPE") {
|
|
11471
11475
|
let endTagIndex = htmlText.slice(i + 9).indexOf(">");
|
|
11472
|
-
if (endTagIndex) {
|
|
11476
|
+
if (endTagIndex >= 0) {
|
|
11473
11477
|
const dtdValue = htmlText.slice(i + 9, i + endTagIndex + 9).trimStart();
|
|
11474
11478
|
const node = domCreateDTDSection(xmlDocument, dtdValue);
|
|
11475
11479
|
domAppendChild(parent, node);
|
|
@@ -11568,21 +11572,21 @@ var XmlParser = class {
|
|
|
11568
11572
|
}
|
|
11569
11573
|
if (xml.slice(i + 1, i + 4) === "!--") {
|
|
11570
11574
|
let endTagIndex = xml.slice(i + 4).indexOf("-->");
|
|
11571
|
-
if (endTagIndex) {
|
|
11575
|
+
if (endTagIndex >= 0) {
|
|
11572
11576
|
let node = domCreateComment(xmlDocument, xml.slice(i + 4, i + endTagIndex + 4));
|
|
11573
11577
|
domAppendChild(parent, node);
|
|
11574
11578
|
i += endTagIndex + 6;
|
|
11575
11579
|
}
|
|
11576
11580
|
} else if (xml.slice(i + 1, i + 9) === "![CDATA[") {
|
|
11577
11581
|
let endTagIndex = xml.slice(i + 9).indexOf("]]>");
|
|
11578
|
-
if (endTagIndex) {
|
|
11582
|
+
if (endTagIndex >= 0) {
|
|
11579
11583
|
let node = domCreateCDATASection(xmlDocument, xml.slice(i + 9, i + endTagIndex + 9));
|
|
11580
11584
|
domAppendChild(parent, node);
|
|
11581
11585
|
i += endTagIndex + 11;
|
|
11582
11586
|
}
|
|
11583
11587
|
} else if (xml.slice(i + 1, i + 9) === "!DOCTYPE") {
|
|
11584
11588
|
let endTagIndex = xml.slice(i + 9).indexOf(">");
|
|
11585
|
-
if (endTagIndex) {
|
|
11589
|
+
if (endTagIndex >= 0) {
|
|
11586
11590
|
const dtdValue = xml.slice(i + 9, i + endTagIndex + 9).trimStart();
|
|
11587
11591
|
const node = domCreateDTDSection(xmlDocument, dtdValue);
|
|
11588
11592
|
domAppendChild(parent, node);
|
|
@@ -14540,7 +14544,7 @@ var Xslt = class {
|
|
|
14540
14544
|
return;
|
|
14541
14545
|
}
|
|
14542
14546
|
const childNodes = node.childNodes.filter(
|
|
14543
|
-
(n) => n.nodeType !== DOM_ATTRIBUTE_NODE
|
|
14547
|
+
(n) => n.nodeType !== DOM_ATTRIBUTE_NODE && n.nodeName !== "#dtd-section"
|
|
14544
14548
|
);
|
|
14545
14549
|
for (const childNode of childNodes) {
|
|
14546
14550
|
if (childNode.nodeType === DOM_TEXT_NODE) {
|
|
@@ -16977,7 +16981,7 @@ var Xslt = class {
|
|
|
16977
16981
|
*/
|
|
16978
16982
|
xsltTransformOrStylesheet(context, template, output) {
|
|
16979
16983
|
return __async(this, null, function* () {
|
|
16980
|
-
var _a
|
|
16984
|
+
var _a;
|
|
16981
16985
|
const mainStylesheetMetadata = {
|
|
16982
16986
|
importDepth: 0,
|
|
16983
16987
|
href: "(main stylesheet)",
|
|
@@ -17068,80 +17072,8 @@ var Xslt = class {
|
|
|
17068
17072
|
this.currentTemplateStack.pop();
|
|
17069
17073
|
} else {
|
|
17070
17074
|
const rootNode = context.nodeList[context.position];
|
|
17071
|
-
if (rootNode
|
|
17072
|
-
|
|
17073
|
-
if (childNodes.length > 0) {
|
|
17074
|
-
const childContext = context.clone(childNodes);
|
|
17075
|
-
for (let j = 0; j < childContext.contextSize(); ++j) {
|
|
17076
|
-
const currentNode = childContext.nodeList[j];
|
|
17077
|
-
if (currentNode.nodeType === DOM_TEXT_NODE) {
|
|
17078
|
-
const textNodeContext = context.clone([currentNode], 0);
|
|
17079
|
-
this.commonLogicTextNode(textNodeContext, currentNode, output);
|
|
17080
|
-
} else {
|
|
17081
|
-
const clonedContext = childContext.clone([currentNode], 0);
|
|
17082
|
-
const selection = selectBestTemplate(
|
|
17083
|
-
expandedTemplates,
|
|
17084
|
-
clonedContext,
|
|
17085
|
-
this.matchResolver,
|
|
17086
|
-
this.xPath,
|
|
17087
|
-
this.warningsCallback
|
|
17088
|
-
);
|
|
17089
|
-
if (selection.selectedTemplate) {
|
|
17090
|
-
const templateContext = clonedContext.clone([currentNode], 0);
|
|
17091
|
-
templateContext.inApplyTemplates = true;
|
|
17092
|
-
const metadata = this.templateSourceMap.get(selection.selectedTemplate);
|
|
17093
|
-
const matchPattern = xmlGetAttribute(selection.selectedTemplate, "match");
|
|
17094
|
-
const modeAttr = xmlGetAttribute(selection.selectedTemplate, "mode");
|
|
17095
|
-
this.currentTemplateStack.push({
|
|
17096
|
-
template: selection.selectedTemplate,
|
|
17097
|
-
stylesheetDepth: (_b = metadata == null ? void 0 : metadata.importDepth) != null ? _b : 0,
|
|
17098
|
-
mode: modeAttr || null,
|
|
17099
|
-
match: matchPattern
|
|
17100
|
-
});
|
|
17101
|
-
yield this.xsltChildNodes(templateContext, selection.selectedTemplate, output);
|
|
17102
|
-
this.currentTemplateStack.pop();
|
|
17103
|
-
} else {
|
|
17104
|
-
if (currentNode.childNodes && currentNode.childNodes.length > 0) {
|
|
17105
|
-
const grandchildNodes = currentNode.childNodes.filter((n) => n.nodeName !== "#dtd-section");
|
|
17106
|
-
if (grandchildNodes.length > 0) {
|
|
17107
|
-
const grandchildContext = context.clone(grandchildNodes);
|
|
17108
|
-
for (let k = 0; k < grandchildContext.contextSize(); ++k) {
|
|
17109
|
-
const grandchildNode = grandchildContext.nodeList[k];
|
|
17110
|
-
if (grandchildNode.nodeType === DOM_TEXT_NODE) {
|
|
17111
|
-
const textNodeContext = context.clone([grandchildNode], 0);
|
|
17112
|
-
this.commonLogicTextNode(textNodeContext, grandchildNode, output);
|
|
17113
|
-
} else {
|
|
17114
|
-
const grandchildClonedContext = grandchildContext.clone([grandchildNode], 0);
|
|
17115
|
-
const grandchildSelection = selectBestTemplate(
|
|
17116
|
-
expandedTemplates,
|
|
17117
|
-
grandchildClonedContext,
|
|
17118
|
-
this.matchResolver,
|
|
17119
|
-
this.xPath,
|
|
17120
|
-
this.warningsCallback
|
|
17121
|
-
);
|
|
17122
|
-
if (grandchildSelection.selectedTemplate) {
|
|
17123
|
-
const grandchildTemplateContext = grandchildClonedContext.clone([grandchildNode], 0);
|
|
17124
|
-
grandchildTemplateContext.inApplyTemplates = true;
|
|
17125
|
-
const metadata = this.templateSourceMap.get(grandchildSelection.selectedTemplate);
|
|
17126
|
-
const matchPattern = xmlGetAttribute(grandchildSelection.selectedTemplate, "match");
|
|
17127
|
-
const modeAttr = xmlGetAttribute(grandchildSelection.selectedTemplate, "mode");
|
|
17128
|
-
this.currentTemplateStack.push({
|
|
17129
|
-
template: grandchildSelection.selectedTemplate,
|
|
17130
|
-
stylesheetDepth: (_c = metadata == null ? void 0 : metadata.importDepth) != null ? _c : 0,
|
|
17131
|
-
mode: modeAttr || null,
|
|
17132
|
-
match: matchPattern
|
|
17133
|
-
});
|
|
17134
|
-
yield this.xsltChildNodes(grandchildTemplateContext, grandchildSelection.selectedTemplate, output);
|
|
17135
|
-
this.currentTemplateStack.pop();
|
|
17136
|
-
}
|
|
17137
|
-
}
|
|
17138
|
-
}
|
|
17139
|
-
}
|
|
17140
|
-
}
|
|
17141
|
-
}
|
|
17142
|
-
}
|
|
17143
|
-
}
|
|
17144
|
-
}
|
|
17075
|
+
if (rootNode) {
|
|
17076
|
+
yield this.applyBuiltInTemplate(rootNode, expandedTemplates, null, context, output);
|
|
17145
17077
|
}
|
|
17146
17078
|
}
|
|
17147
17079
|
}
|
|
@@ -18196,6 +18128,7 @@ var Xslt = class {
|
|
|
18196
18128
|
XmlParser,
|
|
18197
18129
|
Xslt,
|
|
18198
18130
|
domDocumentToXDocument,
|
|
18199
|
-
xmlEscapeText
|
|
18131
|
+
xmlEscapeText,
|
|
18132
|
+
xmlTransformedText
|
|
18200
18133
|
});
|
|
18201
18134
|
//# sourceMappingURL=index.js.map
|