xslt-processor 4.9.0 → 5.0.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/README.md +35 -0
- package/index.d.mts +32 -1
- package/index.d.ts +32 -1
- package/index.js +189 -69
- package/index.js.map +1 -1
- package/index.mjs +186 -69
- package/index.mjs.map +1 -1
- package/package.json +2 -2
- package/umd/xslt-processor.global.js +5 -5
- package/umd/xslt-processor.global.js.map +1 -1
package/README.md
CHANGED
|
@@ -63,6 +63,41 @@ xslt.xsltProcess(
|
|
|
63
63
|
|
|
64
64
|
If you write pre-2015 JS code, make adjustments as needed.
|
|
65
65
|
|
|
66
|
+
### Working with browser DOM and XDocument output
|
|
67
|
+
|
|
68
|
+
Feature available in v5 (next major) of this library.
|
|
69
|
+
|
|
70
|
+
If you already have a browser DOM `Document` or `Node`, convert it to an `XDocument` without re-parsing XML strings:
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
import { domDocumentToXDocument } from 'xslt-processor'
|
|
74
|
+
|
|
75
|
+
const parser = new DOMParser();
|
|
76
|
+
const nativeDoc = parser.parseFromString('<root>hello</root>', 'text/xml');
|
|
77
|
+
const xDoc = domDocumentToXDocument(nativeDoc);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
You can also run XSLT and get the output as an `XDocument` tree instead of a serialized string:
|
|
81
|
+
|
|
82
|
+
```js
|
|
83
|
+
import { Xslt, XmlParser } from 'xslt-processor'
|
|
84
|
+
|
|
85
|
+
const xmlParser = new XmlParser();
|
|
86
|
+
const xslt = new Xslt();
|
|
87
|
+
|
|
88
|
+
const xmlDoc = xmlParser.xmlParse('<root><item>hello</item></root>');
|
|
89
|
+
const styleDoc = xmlParser.xmlParse(
|
|
90
|
+
'<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">' +
|
|
91
|
+
' <xsl:template match="/">' +
|
|
92
|
+
' <output><xsl:value-of select="/root/item"/></output>' +
|
|
93
|
+
' </xsl:template>' +
|
|
94
|
+
'</xsl:stylesheet>'
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
const outDoc = await xslt.xsltProcessToDocument(xmlDoc, styleDoc);
|
|
98
|
+
// outDoc is an XDocument you can traverse or serialize with xmlTransformedText.
|
|
99
|
+
```
|
|
100
|
+
|
|
66
101
|
### `Xslt` class options
|
|
67
102
|
|
|
68
103
|
You can pass an `options` object to `Xslt` class:
|
package/index.d.mts
CHANGED
|
@@ -76,6 +76,16 @@ declare class XDocument extends XNode {
|
|
|
76
76
|
createProcessingInstruction(target: string, data: any): XNode;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Converts a native browser DOM Document or Node into an XDocument/XNode tree
|
|
81
|
+
* compatible with the XSLT processor. This allows browser users who already
|
|
82
|
+
* have a parsed DOM to skip the string-based xmlParse() step.
|
|
83
|
+
*
|
|
84
|
+
* @param nativeNode A browser DOM Document, Element, or other Node.
|
|
85
|
+
* @returns An XDocument representing the same tree structure.
|
|
86
|
+
*/
|
|
87
|
+
declare function domDocumentToXDocument(nativeNode: Document | Node): XDocument;
|
|
88
|
+
|
|
79
89
|
/**
|
|
80
90
|
* Escape XML special markup characters: tag delimiter <, >, and entity
|
|
81
91
|
* reference start delimiter &. The escaped string can be used in XML
|
|
@@ -878,6 +888,18 @@ declare class Xslt {
|
|
|
878
888
|
* @returns the processed document, as XML text in a string, JSON string if outputMethod is 'json', or text if outputMethod is 'text' or 'adaptive' (with text content).
|
|
879
889
|
*/
|
|
880
890
|
xsltProcess(xmlDoc: XDocument, stylesheet: XDocument): Promise<string>;
|
|
891
|
+
/**
|
|
892
|
+
* Processes the XSLT transformation and returns the output as an XDocument
|
|
893
|
+
* instead of a serialized string. This is useful for:
|
|
894
|
+
* - Working with the result tree programmatically
|
|
895
|
+
* - Converting to a different DOM representation (e.g., React elements)
|
|
896
|
+
* - Using browser-native serialization (XMLSerializer) if desired
|
|
897
|
+
*
|
|
898
|
+
* @param xmlDoc The input document root, as DOM node.
|
|
899
|
+
* @param stylesheet The stylesheet document root, as DOM node.
|
|
900
|
+
* @returns The processed document as an XDocument tree.
|
|
901
|
+
*/
|
|
902
|
+
xsltProcessToDocument(xmlDoc: XDocument, stylesheet: XDocument): Promise<XDocument>;
|
|
881
903
|
/**
|
|
882
904
|
* The main entry point of the XSL-T processor, as explained on the top of the file.
|
|
883
905
|
* @param context The input document root, as XPath `ExprContext`.
|
|
@@ -1471,6 +1493,15 @@ declare class Xslt {
|
|
|
1471
1493
|
* @returns The coerced value.
|
|
1472
1494
|
*/
|
|
1473
1495
|
protected coerceToType(value: NodeValue, type: string): NodeValue;
|
|
1496
|
+
/**
|
|
1497
|
+
* Converts a raw JavaScript value to the appropriate NodeValue type.
|
|
1498
|
+
* Detects NodeValue instances, DOM nodes, arrays, numbers, booleans,
|
|
1499
|
+
* and falls back to StringValue.
|
|
1500
|
+
*
|
|
1501
|
+
* @param value The raw value to convert.
|
|
1502
|
+
* @returns The wrapped NodeValue.
|
|
1503
|
+
*/
|
|
1504
|
+
protected toNodeValue(value: any): NodeValue;
|
|
1474
1505
|
/**
|
|
1475
1506
|
* Execute a user-defined xsl:function.
|
|
1476
1507
|
* Called when a function from userDefinedFunctions is invoked from XPath.
|
|
@@ -1733,4 +1764,4 @@ declare class Xslt {
|
|
|
1733
1764
|
protected isXsltElement(element: XNode, opt_wantedName?: string): boolean;
|
|
1734
1765
|
}
|
|
1735
1766
|
|
|
1736
|
-
export { ExprContext, XPath, XmlParser, Xslt, type XsltOptions, xmlEscapeText };
|
|
1767
|
+
export { ExprContext, XDocument, XNode, XPath, XmlParser, Xslt, type XsltOptions, domDocumentToXDocument, xmlEscapeText };
|
package/index.d.ts
CHANGED
|
@@ -76,6 +76,16 @@ declare class XDocument extends XNode {
|
|
|
76
76
|
createProcessingInstruction(target: string, data: any): XNode;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Converts a native browser DOM Document or Node into an XDocument/XNode tree
|
|
81
|
+
* compatible with the XSLT processor. This allows browser users who already
|
|
82
|
+
* have a parsed DOM to skip the string-based xmlParse() step.
|
|
83
|
+
*
|
|
84
|
+
* @param nativeNode A browser DOM Document, Element, or other Node.
|
|
85
|
+
* @returns An XDocument representing the same tree structure.
|
|
86
|
+
*/
|
|
87
|
+
declare function domDocumentToXDocument(nativeNode: Document | Node): XDocument;
|
|
88
|
+
|
|
79
89
|
/**
|
|
80
90
|
* Escape XML special markup characters: tag delimiter <, >, and entity
|
|
81
91
|
* reference start delimiter &. The escaped string can be used in XML
|
|
@@ -878,6 +888,18 @@ declare class Xslt {
|
|
|
878
888
|
* @returns the processed document, as XML text in a string, JSON string if outputMethod is 'json', or text if outputMethod is 'text' or 'adaptive' (with text content).
|
|
879
889
|
*/
|
|
880
890
|
xsltProcess(xmlDoc: XDocument, stylesheet: XDocument): Promise<string>;
|
|
891
|
+
/**
|
|
892
|
+
* Processes the XSLT transformation and returns the output as an XDocument
|
|
893
|
+
* instead of a serialized string. This is useful for:
|
|
894
|
+
* - Working with the result tree programmatically
|
|
895
|
+
* - Converting to a different DOM representation (e.g., React elements)
|
|
896
|
+
* - Using browser-native serialization (XMLSerializer) if desired
|
|
897
|
+
*
|
|
898
|
+
* @param xmlDoc The input document root, as DOM node.
|
|
899
|
+
* @param stylesheet The stylesheet document root, as DOM node.
|
|
900
|
+
* @returns The processed document as an XDocument tree.
|
|
901
|
+
*/
|
|
902
|
+
xsltProcessToDocument(xmlDoc: XDocument, stylesheet: XDocument): Promise<XDocument>;
|
|
881
903
|
/**
|
|
882
904
|
* The main entry point of the XSL-T processor, as explained on the top of the file.
|
|
883
905
|
* @param context The input document root, as XPath `ExprContext`.
|
|
@@ -1471,6 +1493,15 @@ declare class Xslt {
|
|
|
1471
1493
|
* @returns The coerced value.
|
|
1472
1494
|
*/
|
|
1473
1495
|
protected coerceToType(value: NodeValue, type: string): NodeValue;
|
|
1496
|
+
/**
|
|
1497
|
+
* Converts a raw JavaScript value to the appropriate NodeValue type.
|
|
1498
|
+
* Detects NodeValue instances, DOM nodes, arrays, numbers, booleans,
|
|
1499
|
+
* and falls back to StringValue.
|
|
1500
|
+
*
|
|
1501
|
+
* @param value The raw value to convert.
|
|
1502
|
+
* @returns The wrapped NodeValue.
|
|
1503
|
+
*/
|
|
1504
|
+
protected toNodeValue(value: any): NodeValue;
|
|
1474
1505
|
/**
|
|
1475
1506
|
* Execute a user-defined xsl:function.
|
|
1476
1507
|
* Called when a function from userDefinedFunctions is invoked from XPath.
|
|
@@ -1733,4 +1764,4 @@ declare class Xslt {
|
|
|
1733
1764
|
protected isXsltElement(element: XNode, opt_wantedName?: string): boolean;
|
|
1734
1765
|
}
|
|
1735
1766
|
|
|
1736
|
-
export { ExprContext, XPath, XmlParser, Xslt, type XsltOptions, xmlEscapeText };
|
|
1767
|
+
export { ExprContext, XDocument, XNode, XPath, XmlParser, Xslt, type XsltOptions, domDocumentToXDocument, xmlEscapeText };
|
package/index.js
CHANGED
|
@@ -7800,9 +7800,12 @@ var init_expressions = __esm({
|
|
|
7800
7800
|
var index_exports = {};
|
|
7801
7801
|
__export(index_exports, {
|
|
7802
7802
|
ExprContext: () => ExprContext,
|
|
7803
|
+
XDocument: () => XDocument,
|
|
7804
|
+
XNode: () => XNode,
|
|
7803
7805
|
XPath: () => XPath,
|
|
7804
7806
|
XmlParser: () => XmlParser,
|
|
7805
7807
|
Xslt: () => Xslt,
|
|
7808
|
+
domDocumentToXDocument: () => domDocumentToXDocument,
|
|
7806
7809
|
xmlEscapeText: () => xmlEscapeText
|
|
7807
7810
|
});
|
|
7808
7811
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -10279,38 +10282,6 @@ function createXPathParser(version = DEFAULT_XPATH_VERSION, options) {
|
|
|
10279
10282
|
// src/xpath/xpath.ts
|
|
10280
10283
|
init_expressions();
|
|
10281
10284
|
|
|
10282
|
-
// src/dom/functions.ts
|
|
10283
|
-
function domGetAttributeValue(node, name) {
|
|
10284
|
-
return node.getAttributeValue(name);
|
|
10285
|
-
}
|
|
10286
|
-
function domSetAttribute(node, name, value) {
|
|
10287
|
-
return node.setAttribute(name, value);
|
|
10288
|
-
}
|
|
10289
|
-
function domAppendChild(node, child) {
|
|
10290
|
-
return node.appendChild(child);
|
|
10291
|
-
}
|
|
10292
|
-
function domCreateTextNode(node, text) {
|
|
10293
|
-
return node.createTextNode(text);
|
|
10294
|
-
}
|
|
10295
|
-
function domCreateElement(doc, name) {
|
|
10296
|
-
return doc.createElement(name);
|
|
10297
|
-
}
|
|
10298
|
-
function domCreateCDATASection(doc, data2) {
|
|
10299
|
-
return doc.createCDATASection(data2);
|
|
10300
|
-
}
|
|
10301
|
-
function domCreateComment(doc, text) {
|
|
10302
|
-
return doc.createComment(text);
|
|
10303
|
-
}
|
|
10304
|
-
function domCreateDocumentFragment(doc) {
|
|
10305
|
-
return doc.createDocumentFragment();
|
|
10306
|
-
}
|
|
10307
|
-
function domCreateDTDSection(doc, data2) {
|
|
10308
|
-
return doc.createDTDSection(data2);
|
|
10309
|
-
}
|
|
10310
|
-
function domCreateProcessingInstruction(doc, target, data2) {
|
|
10311
|
-
return doc.createProcessingInstruction(target, data2);
|
|
10312
|
-
}
|
|
10313
|
-
|
|
10314
10285
|
// src/constants.ts
|
|
10315
10286
|
var DOM_ELEMENT_NODE = 1;
|
|
10316
10287
|
var DOM_ATTRIBUTE_NODE = 2;
|
|
@@ -10735,7 +10706,9 @@ var XDocument = class extends XNode {
|
|
|
10735
10706
|
}
|
|
10736
10707
|
appendChild(node) {
|
|
10737
10708
|
super.appendChild(node);
|
|
10738
|
-
|
|
10709
|
+
if (node.nodeType === DOM_ELEMENT_NODE && !this.documentElement) {
|
|
10710
|
+
this.documentElement = node;
|
|
10711
|
+
}
|
|
10739
10712
|
}
|
|
10740
10713
|
createElement(name) {
|
|
10741
10714
|
return XNode.create(DOM_ELEMENT_NODE, name, null, this);
|
|
@@ -10769,6 +10742,130 @@ var XDocument = class extends XNode {
|
|
|
10769
10742
|
}
|
|
10770
10743
|
};
|
|
10771
10744
|
|
|
10745
|
+
// src/dom/dom-to-xdocument.ts
|
|
10746
|
+
function domDocumentToXDocument(nativeNode) {
|
|
10747
|
+
if (nativeNode.nodeType === DOM_DOCUMENT_NODE) {
|
|
10748
|
+
const xDoc2 = new XDocument();
|
|
10749
|
+
const childNodes = nativeNode.childNodes;
|
|
10750
|
+
for (let i = 0; i < childNodes.length; i++) {
|
|
10751
|
+
const converted2 = convertNode(childNodes[i], xDoc2);
|
|
10752
|
+
if (converted2) {
|
|
10753
|
+
converted2.siblingPosition = xDoc2.childNodes.length;
|
|
10754
|
+
xDoc2.appendChild(converted2);
|
|
10755
|
+
}
|
|
10756
|
+
}
|
|
10757
|
+
return xDoc2;
|
|
10758
|
+
}
|
|
10759
|
+
const xDoc = new XDocument();
|
|
10760
|
+
const converted = convertNode(nativeNode, xDoc);
|
|
10761
|
+
if (converted) {
|
|
10762
|
+
converted.siblingPosition = 0;
|
|
10763
|
+
xDoc.appendChild(converted);
|
|
10764
|
+
}
|
|
10765
|
+
return xDoc;
|
|
10766
|
+
}
|
|
10767
|
+
function convertNode(nativeNode, ownerDoc) {
|
|
10768
|
+
switch (nativeNode.nodeType) {
|
|
10769
|
+
case DOM_ELEMENT_NODE: {
|
|
10770
|
+
const element = nativeNode;
|
|
10771
|
+
const xNode = XNode.create(
|
|
10772
|
+
DOM_ELEMENT_NODE,
|
|
10773
|
+
element.nodeName,
|
|
10774
|
+
null,
|
|
10775
|
+
ownerDoc,
|
|
10776
|
+
element.namespaceURI
|
|
10777
|
+
);
|
|
10778
|
+
xNode.prefix = element.prefix || null;
|
|
10779
|
+
xNode.localName = element.localName || element.nodeName;
|
|
10780
|
+
const attrs = element.attributes;
|
|
10781
|
+
for (let i = 0; i < attrs.length; i++) {
|
|
10782
|
+
const attr = attrs[i];
|
|
10783
|
+
const attrNode = XNode.create(
|
|
10784
|
+
DOM_ATTRIBUTE_NODE,
|
|
10785
|
+
attr.name,
|
|
10786
|
+
attr.value,
|
|
10787
|
+
xNode,
|
|
10788
|
+
attr.namespaceURI
|
|
10789
|
+
);
|
|
10790
|
+
attrNode.prefix = attr.prefix || null;
|
|
10791
|
+
attrNode.localName = attr.localName || attr.name;
|
|
10792
|
+
attrNode.parentNode = xNode;
|
|
10793
|
+
attrNode.siblingPosition = xNode.childNodes.length;
|
|
10794
|
+
xNode.appendChild(attrNode);
|
|
10795
|
+
}
|
|
10796
|
+
const childNodes = nativeNode.childNodes;
|
|
10797
|
+
for (let i = 0; i < childNodes.length; i++) {
|
|
10798
|
+
const converted = convertNode(childNodes[i], ownerDoc);
|
|
10799
|
+
if (converted) {
|
|
10800
|
+
converted.siblingPosition = xNode.childNodes.length;
|
|
10801
|
+
xNode.appendChild(converted);
|
|
10802
|
+
}
|
|
10803
|
+
}
|
|
10804
|
+
return xNode;
|
|
10805
|
+
}
|
|
10806
|
+
case DOM_TEXT_NODE:
|
|
10807
|
+
return XNode.create(DOM_TEXT_NODE, "#text", nativeNode.nodeValue || "", ownerDoc);
|
|
10808
|
+
case DOM_CDATA_SECTION_NODE:
|
|
10809
|
+
return XNode.create(DOM_CDATA_SECTION_NODE, "#cdata-section", nativeNode.nodeValue || "", ownerDoc);
|
|
10810
|
+
case DOM_COMMENT_NODE:
|
|
10811
|
+
return XNode.create(DOM_COMMENT_NODE, "#comment", nativeNode.nodeValue || "", ownerDoc);
|
|
10812
|
+
case DOM_PROCESSING_INSTRUCTION_NODE: {
|
|
10813
|
+
const pi2 = nativeNode;
|
|
10814
|
+
return XNode.create(DOM_PROCESSING_INSTRUCTION_NODE, pi2.target, pi2.data, ownerDoc);
|
|
10815
|
+
}
|
|
10816
|
+
case DOM_DOCUMENT_TYPE_NODE: {
|
|
10817
|
+
const dt = nativeNode;
|
|
10818
|
+
return XNode.create(DOM_DOCUMENT_TYPE_NODE, "#dtd-section", dt.name, ownerDoc);
|
|
10819
|
+
}
|
|
10820
|
+
case DOM_DOCUMENT_FRAGMENT_NODE: {
|
|
10821
|
+
const fragment = XNode.create(DOM_DOCUMENT_FRAGMENT_NODE, "#document-fragment", null, ownerDoc);
|
|
10822
|
+
const childNodes = nativeNode.childNodes;
|
|
10823
|
+
for (let i = 0; i < childNodes.length; i++) {
|
|
10824
|
+
const converted = convertNode(childNodes[i], ownerDoc);
|
|
10825
|
+
if (converted) {
|
|
10826
|
+
converted.siblingPosition = fragment.childNodes.length;
|
|
10827
|
+
fragment.appendChild(converted);
|
|
10828
|
+
}
|
|
10829
|
+
}
|
|
10830
|
+
return fragment;
|
|
10831
|
+
}
|
|
10832
|
+
default:
|
|
10833
|
+
return null;
|
|
10834
|
+
}
|
|
10835
|
+
}
|
|
10836
|
+
|
|
10837
|
+
// src/dom/functions.ts
|
|
10838
|
+
function domGetAttributeValue(node, name) {
|
|
10839
|
+
return node.getAttributeValue(name);
|
|
10840
|
+
}
|
|
10841
|
+
function domSetAttribute(node, name, value) {
|
|
10842
|
+
return node.setAttribute(name, value);
|
|
10843
|
+
}
|
|
10844
|
+
function domAppendChild(node, child) {
|
|
10845
|
+
return node.appendChild(child);
|
|
10846
|
+
}
|
|
10847
|
+
function domCreateTextNode(node, text) {
|
|
10848
|
+
return node.createTextNode(text);
|
|
10849
|
+
}
|
|
10850
|
+
function domCreateElement(doc, name) {
|
|
10851
|
+
return doc.createElement(name);
|
|
10852
|
+
}
|
|
10853
|
+
function domCreateCDATASection(doc, data2) {
|
|
10854
|
+
return doc.createCDATASection(data2);
|
|
10855
|
+
}
|
|
10856
|
+
function domCreateComment(doc, text) {
|
|
10857
|
+
return doc.createComment(text);
|
|
10858
|
+
}
|
|
10859
|
+
function domCreateDocumentFragment(doc) {
|
|
10860
|
+
return doc.createDocumentFragment();
|
|
10861
|
+
}
|
|
10862
|
+
function domCreateDTDSection(doc, data2) {
|
|
10863
|
+
return doc.createDTDSection(data2);
|
|
10864
|
+
}
|
|
10865
|
+
function domCreateProcessingInstruction(doc, target, data2) {
|
|
10866
|
+
return doc.createProcessingInstruction(target, data2);
|
|
10867
|
+
}
|
|
10868
|
+
|
|
10772
10869
|
// src/dom/html-entity-decoder.ts
|
|
10773
10870
|
var NAMED_ENTITIES = {
|
|
10774
10871
|
"amp": "&",
|
|
@@ -13931,16 +14028,7 @@ var Xslt = class {
|
|
|
13931
14028
|
*/
|
|
13932
14029
|
xsltProcess(xmlDoc, stylesheet) {
|
|
13933
14030
|
return __async(this, null, function* () {
|
|
13934
|
-
const outputDocument =
|
|
13935
|
-
this.outputDocument = outputDocument;
|
|
13936
|
-
const expressionContext = new ExprContext([xmlDoc]);
|
|
13937
|
-
expressionContext.warningsCallback = this.warningsCallback;
|
|
13938
|
-
if (this.options.parameters.length > 0) {
|
|
13939
|
-
for (const parameter of this.options.parameters) {
|
|
13940
|
-
expressionContext.setVariable(parameter.name, new StringValue(parameter.value));
|
|
13941
|
-
}
|
|
13942
|
-
}
|
|
13943
|
-
yield this.xsltProcessContext(expressionContext, stylesheet, this.outputDocument);
|
|
14031
|
+
const outputDocument = yield this.xsltProcessToDocument(xmlDoc, stylesheet);
|
|
13944
14032
|
if (this.outputMethod === "json") {
|
|
13945
14033
|
return xmlToJson(outputDocument);
|
|
13946
14034
|
}
|
|
@@ -13963,6 +14051,32 @@ var Xslt = class {
|
|
|
13963
14051
|
return transformedOutputXml;
|
|
13964
14052
|
});
|
|
13965
14053
|
}
|
|
14054
|
+
/**
|
|
14055
|
+
* Processes the XSLT transformation and returns the output as an XDocument
|
|
14056
|
+
* instead of a serialized string. This is useful for:
|
|
14057
|
+
* - Working with the result tree programmatically
|
|
14058
|
+
* - Converting to a different DOM representation (e.g., React elements)
|
|
14059
|
+
* - Using browser-native serialization (XMLSerializer) if desired
|
|
14060
|
+
*
|
|
14061
|
+
* @param xmlDoc The input document root, as DOM node.
|
|
14062
|
+
* @param stylesheet The stylesheet document root, as DOM node.
|
|
14063
|
+
* @returns The processed document as an XDocument tree.
|
|
14064
|
+
*/
|
|
14065
|
+
xsltProcessToDocument(xmlDoc, stylesheet) {
|
|
14066
|
+
return __async(this, null, function* () {
|
|
14067
|
+
const outputDocument = new XDocument();
|
|
14068
|
+
this.outputDocument = outputDocument;
|
|
14069
|
+
const expressionContext = new ExprContext([xmlDoc]);
|
|
14070
|
+
expressionContext.warningsCallback = this.warningsCallback;
|
|
14071
|
+
if (this.options.parameters.length > 0) {
|
|
14072
|
+
for (const parameter of this.options.parameters) {
|
|
14073
|
+
expressionContext.setVariable(parameter.name, this.toNodeValue(parameter.value));
|
|
14074
|
+
}
|
|
14075
|
+
}
|
|
14076
|
+
yield this.xsltProcessContext(expressionContext, stylesheet, this.outputDocument);
|
|
14077
|
+
return outputDocument;
|
|
14078
|
+
});
|
|
14079
|
+
}
|
|
13966
14080
|
/**
|
|
13967
14081
|
* The main entry point of the XSL-T processor, as explained on the top of the file.
|
|
13968
14082
|
* @param context The input document root, as XPath `ExprContext`.
|
|
@@ -17189,6 +17303,29 @@ var Xslt = class {
|
|
|
17189
17303
|
return value;
|
|
17190
17304
|
}
|
|
17191
17305
|
}
|
|
17306
|
+
/**
|
|
17307
|
+
* Converts a raw JavaScript value to the appropriate NodeValue type.
|
|
17308
|
+
* Detects NodeValue instances, DOM nodes, arrays, numbers, booleans,
|
|
17309
|
+
* and falls back to StringValue.
|
|
17310
|
+
*
|
|
17311
|
+
* @param value The raw value to convert.
|
|
17312
|
+
* @returns The wrapped NodeValue.
|
|
17313
|
+
*/
|
|
17314
|
+
toNodeValue(value) {
|
|
17315
|
+
if (value && typeof value === "object" && "stringValue" in value) {
|
|
17316
|
+
return value;
|
|
17317
|
+
} else if (value && typeof value === "object" && "nodeType" in value) {
|
|
17318
|
+
return new NodeSetValue([value]);
|
|
17319
|
+
} else if (Array.isArray(value)) {
|
|
17320
|
+
return new NodeSetValue(value);
|
|
17321
|
+
} else if (typeof value === "number") {
|
|
17322
|
+
return new NumberValue(value);
|
|
17323
|
+
} else if (typeof value === "boolean") {
|
|
17324
|
+
return new BooleanValue(value);
|
|
17325
|
+
} else {
|
|
17326
|
+
return new StringValue(String(value != null ? value : ""));
|
|
17327
|
+
}
|
|
17328
|
+
}
|
|
17192
17329
|
/**
|
|
17193
17330
|
* Execute a user-defined xsl:function.
|
|
17194
17331
|
* Called when a function from userDefinedFunctions is invoked from XPath.
|
|
@@ -17226,30 +17363,10 @@ var Xslt = class {
|
|
|
17226
17363
|
const paramName = xmlGetAttribute(params[i], "name");
|
|
17227
17364
|
if (paramName) {
|
|
17228
17365
|
if (i < args.length) {
|
|
17229
|
-
let argValue = args[i];
|
|
17230
17366
|
const paramType = xmlGetAttribute(params[i], "as");
|
|
17231
|
-
let paramValue;
|
|
17232
|
-
if (
|
|
17233
|
-
paramValue =
|
|
17234
|
-
if (paramType) {
|
|
17235
|
-
paramValue = this.coerceToType(paramValue, paramType);
|
|
17236
|
-
}
|
|
17237
|
-
} else if (argValue && typeof argValue === "object" && "nodeType" in argValue) {
|
|
17238
|
-
paramValue = new NodeSetValue([argValue]);
|
|
17239
|
-
if (paramType) {
|
|
17240
|
-
paramValue = this.coerceToType(paramValue, paramType);
|
|
17241
|
-
}
|
|
17242
|
-
} else if (Array.isArray(argValue)) {
|
|
17243
|
-
paramValue = new NodeSetValue(argValue);
|
|
17244
|
-
if (paramType) {
|
|
17245
|
-
paramValue = this.coerceToType(paramValue, paramType);
|
|
17246
|
-
}
|
|
17247
|
-
} else if (typeof argValue === "number") {
|
|
17248
|
-
paramValue = new NumberValue(argValue);
|
|
17249
|
-
} else if (typeof argValue === "boolean") {
|
|
17250
|
-
paramValue = new BooleanValue(argValue);
|
|
17251
|
-
} else {
|
|
17252
|
-
paramValue = new StringValue(String(argValue != null ? argValue : ""));
|
|
17367
|
+
let paramValue = this.toNodeValue(args[i]);
|
|
17368
|
+
if (paramType) {
|
|
17369
|
+
paramValue = this.coerceToType(paramValue, paramType);
|
|
17253
17370
|
}
|
|
17254
17371
|
functionContext.setVariable(paramName, paramValue);
|
|
17255
17372
|
} else {
|
|
@@ -17456,12 +17573,12 @@ var Xslt = class {
|
|
|
17456
17573
|
} else if (select) {
|
|
17457
17574
|
value = this.xPath.xPathEval(select, context);
|
|
17458
17575
|
} else {
|
|
17459
|
-
let parameterValue = "";
|
|
17460
17576
|
const filteredParameter = this.options.parameters.filter((p) => p.name === name);
|
|
17461
17577
|
if (filteredParameter.length > 0) {
|
|
17462
|
-
|
|
17578
|
+
value = this.toNodeValue(filteredParameter[0].value);
|
|
17579
|
+
} else {
|
|
17580
|
+
value = new StringValue("");
|
|
17463
17581
|
}
|
|
17464
|
-
value = new StringValue(parameterValue);
|
|
17465
17582
|
}
|
|
17466
17583
|
if (override || !context.getVariable(name)) {
|
|
17467
17584
|
context.setVariable(name, value);
|
|
@@ -18036,9 +18153,12 @@ var Xslt = class {
|
|
|
18036
18153
|
// Annotate the CommonJS export names for ESM import in node:
|
|
18037
18154
|
0 && (module.exports = {
|
|
18038
18155
|
ExprContext,
|
|
18156
|
+
XDocument,
|
|
18157
|
+
XNode,
|
|
18039
18158
|
XPath,
|
|
18040
18159
|
XmlParser,
|
|
18041
18160
|
Xslt,
|
|
18161
|
+
domDocumentToXDocument,
|
|
18042
18162
|
xmlEscapeText
|
|
18043
18163
|
});
|
|
18044
18164
|
//# sourceMappingURL=index.js.map
|