xslt-processor 5.0.3 → 5.0.5
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 +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +47 -103
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -103
- 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/dist/index.mjs
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
|
}
|
|
@@ -14526,7 +14529,7 @@ var Xslt = class {
|
|
|
14526
14529
|
return;
|
|
14527
14530
|
}
|
|
14528
14531
|
const childNodes = node.childNodes.filter(
|
|
14529
|
-
(n) => n.nodeType !== DOM_ATTRIBUTE_NODE
|
|
14532
|
+
(n) => n.nodeType !== DOM_ATTRIBUTE_NODE && n.nodeName !== "#dtd-section"
|
|
14530
14533
|
);
|
|
14531
14534
|
for (const childNode of childNodes) {
|
|
14532
14535
|
if (childNode.nodeType === DOM_TEXT_NODE) {
|
|
@@ -16212,23 +16215,36 @@ var Xslt = class {
|
|
|
16212
16215
|
errorMessage = errorMessage.slice(0, -2);
|
|
16213
16216
|
throw new Error(errorMessage);
|
|
16214
16217
|
}
|
|
16215
|
-
let keyContext;
|
|
16216
|
-
if (context.nodeList[context.position].nodeName === "#document") {
|
|
16217
|
-
keyContext = context.clone(context.nodeList[context.position].childNodes);
|
|
16218
|
-
} else {
|
|
16219
|
-
keyContext = context;
|
|
16220
|
-
}
|
|
16221
|
-
const nodes = this.xsltMatch(match, keyContext);
|
|
16222
16218
|
if (!(name in context.keys)) {
|
|
16223
16219
|
context.keys[name] = {};
|
|
16224
16220
|
}
|
|
16225
|
-
|
|
16226
|
-
|
|
16227
|
-
|
|
16228
|
-
|
|
16229
|
-
|
|
16221
|
+
const allNodes = this.collectAllDescendants(context.root);
|
|
16222
|
+
for (const node of allNodes) {
|
|
16223
|
+
if (nodeMatchesPattern(node, match, context, this.matchResolver, this.xPath)) {
|
|
16224
|
+
const nodeContext = context.clone([node]);
|
|
16225
|
+
const attribute = this.xPath.xPathEval(use, nodeContext);
|
|
16226
|
+
const attributeValue = attribute.stringValue();
|
|
16227
|
+
if (!(attributeValue in context.keys[name])) {
|
|
16228
|
+
context.keys[name][attributeValue] = new NodeSetValue([node]);
|
|
16229
|
+
} else {
|
|
16230
|
+
context.keys[name][attributeValue].nodeSetValue().push(node);
|
|
16231
|
+
}
|
|
16232
|
+
}
|
|
16230
16233
|
}
|
|
16231
16234
|
}
|
|
16235
|
+
/**
|
|
16236
|
+
* Returns all descendant nodes of the given node, depth-first.
|
|
16237
|
+
* @param node The root node to traverse from.
|
|
16238
|
+
* @returns All descendant nodes.
|
|
16239
|
+
*/
|
|
16240
|
+
collectAllDescendants(node) {
|
|
16241
|
+
const result = [];
|
|
16242
|
+
for (const child of node.childNodes || []) {
|
|
16243
|
+
result.push(child);
|
|
16244
|
+
result.push(...this.collectAllDescendants(child));
|
|
16245
|
+
}
|
|
16246
|
+
return result;
|
|
16247
|
+
}
|
|
16232
16248
|
/**
|
|
16233
16249
|
* Implements `xsl:message`.
|
|
16234
16250
|
* Outputs a message to the console. If terminate="yes", throws an error to stop processing.
|
|
@@ -16950,7 +16966,7 @@ var Xslt = class {
|
|
|
16950
16966
|
*/
|
|
16951
16967
|
xsltTransformOrStylesheet(context, template, output) {
|
|
16952
16968
|
return __async(this, null, function* () {
|
|
16953
|
-
var _a
|
|
16969
|
+
var _a;
|
|
16954
16970
|
const mainStylesheetMetadata = {
|
|
16955
16971
|
importDepth: 0,
|
|
16956
16972
|
href: "(main stylesheet)",
|
|
@@ -17041,80 +17057,8 @@ var Xslt = class {
|
|
|
17041
17057
|
this.currentTemplateStack.pop();
|
|
17042
17058
|
} else {
|
|
17043
17059
|
const rootNode = context.nodeList[context.position];
|
|
17044
|
-
if (rootNode
|
|
17045
|
-
|
|
17046
|
-
if (childNodes.length > 0) {
|
|
17047
|
-
const childContext = context.clone(childNodes);
|
|
17048
|
-
for (let j = 0; j < childContext.contextSize(); ++j) {
|
|
17049
|
-
const currentNode = childContext.nodeList[j];
|
|
17050
|
-
if (currentNode.nodeType === DOM_TEXT_NODE) {
|
|
17051
|
-
const textNodeContext = context.clone([currentNode], 0);
|
|
17052
|
-
this.commonLogicTextNode(textNodeContext, currentNode, output);
|
|
17053
|
-
} else {
|
|
17054
|
-
const clonedContext = childContext.clone([currentNode], 0);
|
|
17055
|
-
const selection = selectBestTemplate(
|
|
17056
|
-
expandedTemplates,
|
|
17057
|
-
clonedContext,
|
|
17058
|
-
this.matchResolver,
|
|
17059
|
-
this.xPath,
|
|
17060
|
-
this.warningsCallback
|
|
17061
|
-
);
|
|
17062
|
-
if (selection.selectedTemplate) {
|
|
17063
|
-
const templateContext = clonedContext.clone([currentNode], 0);
|
|
17064
|
-
templateContext.inApplyTemplates = true;
|
|
17065
|
-
const metadata = this.templateSourceMap.get(selection.selectedTemplate);
|
|
17066
|
-
const matchPattern = xmlGetAttribute(selection.selectedTemplate, "match");
|
|
17067
|
-
const modeAttr = xmlGetAttribute(selection.selectedTemplate, "mode");
|
|
17068
|
-
this.currentTemplateStack.push({
|
|
17069
|
-
template: selection.selectedTemplate,
|
|
17070
|
-
stylesheetDepth: (_b = metadata == null ? void 0 : metadata.importDepth) != null ? _b : 0,
|
|
17071
|
-
mode: modeAttr || null,
|
|
17072
|
-
match: matchPattern
|
|
17073
|
-
});
|
|
17074
|
-
yield this.xsltChildNodes(templateContext, selection.selectedTemplate, output);
|
|
17075
|
-
this.currentTemplateStack.pop();
|
|
17076
|
-
} else {
|
|
17077
|
-
if (currentNode.childNodes && currentNode.childNodes.length > 0) {
|
|
17078
|
-
const grandchildNodes = currentNode.childNodes.filter((n) => n.nodeName !== "#dtd-section");
|
|
17079
|
-
if (grandchildNodes.length > 0) {
|
|
17080
|
-
const grandchildContext = context.clone(grandchildNodes);
|
|
17081
|
-
for (let k = 0; k < grandchildContext.contextSize(); ++k) {
|
|
17082
|
-
const grandchildNode = grandchildContext.nodeList[k];
|
|
17083
|
-
if (grandchildNode.nodeType === DOM_TEXT_NODE) {
|
|
17084
|
-
const textNodeContext = context.clone([grandchildNode], 0);
|
|
17085
|
-
this.commonLogicTextNode(textNodeContext, grandchildNode, output);
|
|
17086
|
-
} else {
|
|
17087
|
-
const grandchildClonedContext = grandchildContext.clone([grandchildNode], 0);
|
|
17088
|
-
const grandchildSelection = selectBestTemplate(
|
|
17089
|
-
expandedTemplates,
|
|
17090
|
-
grandchildClonedContext,
|
|
17091
|
-
this.matchResolver,
|
|
17092
|
-
this.xPath,
|
|
17093
|
-
this.warningsCallback
|
|
17094
|
-
);
|
|
17095
|
-
if (grandchildSelection.selectedTemplate) {
|
|
17096
|
-
const grandchildTemplateContext = grandchildClonedContext.clone([grandchildNode], 0);
|
|
17097
|
-
grandchildTemplateContext.inApplyTemplates = true;
|
|
17098
|
-
const metadata = this.templateSourceMap.get(grandchildSelection.selectedTemplate);
|
|
17099
|
-
const matchPattern = xmlGetAttribute(grandchildSelection.selectedTemplate, "match");
|
|
17100
|
-
const modeAttr = xmlGetAttribute(grandchildSelection.selectedTemplate, "mode");
|
|
17101
|
-
this.currentTemplateStack.push({
|
|
17102
|
-
template: grandchildSelection.selectedTemplate,
|
|
17103
|
-
stylesheetDepth: (_c = metadata == null ? void 0 : metadata.importDepth) != null ? _c : 0,
|
|
17104
|
-
mode: modeAttr || null,
|
|
17105
|
-
match: matchPattern
|
|
17106
|
-
});
|
|
17107
|
-
yield this.xsltChildNodes(grandchildTemplateContext, grandchildSelection.selectedTemplate, output);
|
|
17108
|
-
this.currentTemplateStack.pop();
|
|
17109
|
-
}
|
|
17110
|
-
}
|
|
17111
|
-
}
|
|
17112
|
-
}
|
|
17113
|
-
}
|
|
17114
|
-
}
|
|
17115
|
-
}
|
|
17116
|
-
}
|
|
17117
|
-
}
|
|
17060
|
+
if (rootNode) {
|
|
17061
|
+
yield this.applyBuiltInTemplate(rootNode, expandedTemplates, null, context, output);
|
|
17118
17062
|
}
|
|
17119
17063
|
}
|
|
17120
17064
|
}
|