xslt-processor 4.2.0 → 4.2.1
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/index.js +87 -15
- package/index.js.map +1 -1
- package/index.mjs +87 -15
- package/index.mjs.map +1 -1
- package/package.json +1 -1
- package/umd/xslt-processor.global.js +3 -3
- package/umd/xslt-processor.global.js.map +1 -1
package/index.js
CHANGED
|
@@ -3446,24 +3446,31 @@ function nodeMatchesSinglePattern(node, pattern, context, matchResolver, xPath)
|
|
|
3446
3446
|
const patternLocalName = attrPattern.includes(":") ? attrPattern.substring(attrPattern.indexOf(":") + 1) : attrPattern;
|
|
3447
3447
|
return attrName === patternLocalName || node.nodeName === attrPattern;
|
|
3448
3448
|
}
|
|
3449
|
-
const nodeContext = context.clone([node], 0);
|
|
3450
|
-
try {
|
|
3451
|
-
const expr = xPath.xPathParse(pattern, "self-and-siblings");
|
|
3452
|
-
const nodes = matchResolver.expressionMatch(expr, nodeContext);
|
|
3453
|
-
if (nodes.some((n) => n.id === node.id)) {
|
|
3454
|
-
return true;
|
|
3455
|
-
}
|
|
3456
|
-
} catch (e) {
|
|
3457
|
-
}
|
|
3458
3449
|
if (pattern === "*" && node.nodeType === DOM_ELEMENT_NODE) {
|
|
3459
3450
|
return true;
|
|
3460
3451
|
}
|
|
3461
|
-
if (pattern.includes("
|
|
3452
|
+
if (!pattern.includes("/") && !pattern.includes("[") && !pattern.startsWith("@")) {
|
|
3453
|
+
if (pattern === node.nodeName || pattern === node.localName) {
|
|
3454
|
+
return true;
|
|
3455
|
+
}
|
|
3456
|
+
}
|
|
3457
|
+
if (pattern.includes("/") || pattern.includes("[")) {
|
|
3462
3458
|
try {
|
|
3459
|
+
const evaluationPattern = pattern.startsWith("/") ? pattern : "//" + pattern;
|
|
3463
3460
|
const rootContext = context.clone([context.root], 0);
|
|
3464
|
-
const
|
|
3465
|
-
const
|
|
3466
|
-
|
|
3461
|
+
const evalResult = xPath.xPathEval(evaluationPattern, rootContext);
|
|
3462
|
+
const nodes = evalResult.nodeSetValue();
|
|
3463
|
+
if (nodes.some((n) => n.id === node.id)) {
|
|
3464
|
+
return true;
|
|
3465
|
+
}
|
|
3466
|
+
} catch (e) {
|
|
3467
|
+
}
|
|
3468
|
+
}
|
|
3469
|
+
if (!pattern.includes("/") && !pattern.includes("[") && !pattern.startsWith("@")) {
|
|
3470
|
+
try {
|
|
3471
|
+
const nodeContext = context.clone([node], 0);
|
|
3472
|
+
const expr = xPath.xPathParse(pattern, "self-and-siblings");
|
|
3473
|
+
const nodes = matchResolver.expressionMatch(expr, nodeContext);
|
|
3467
3474
|
if (nodes.some((n) => n.id === node.id)) {
|
|
3468
3475
|
return true;
|
|
3469
3476
|
}
|
|
@@ -3741,7 +3748,9 @@ var Xslt = class {
|
|
|
3741
3748
|
const mode = xmlGetAttribute(template, "mode");
|
|
3742
3749
|
const top = template.ownerDocument.documentElement;
|
|
3743
3750
|
const expandedTemplates = collectAndExpandTemplates(top, mode, this.xPath);
|
|
3744
|
-
const
|
|
3751
|
+
const paramContext = context.clone();
|
|
3752
|
+
yield this.xsltWithParam(paramContext, template);
|
|
3753
|
+
const modifiedContext = paramContext.clone(nodes);
|
|
3745
3754
|
for (let j = 0; j < modifiedContext.contextSize(); ++j) {
|
|
3746
3755
|
const currentNode = modifiedContext.nodeList[j];
|
|
3747
3756
|
if (currentNode.nodeType === DOM_TEXT_NODE) {
|
|
@@ -4612,13 +4621,76 @@ var Xslt = class {
|
|
|
4612
4621
|
contextClone.baseTemplateMatched = true;
|
|
4613
4622
|
const templateContext = contextClone.clone(winner.matchedNodes, 0);
|
|
4614
4623
|
yield this.xsltChildNodes(templateContext, winner.priority.template, output);
|
|
4624
|
+
} else {
|
|
4625
|
+
const rootNode = context.nodeList[context.position];
|
|
4626
|
+
if (rootNode && rootNode.childNodes && rootNode.childNodes.length > 0) {
|
|
4627
|
+
const childNodes = rootNode.childNodes.filter((n) => n.nodeName !== "#dtd-section");
|
|
4628
|
+
if (childNodes.length > 0) {
|
|
4629
|
+
const childContext = context.clone(childNodes);
|
|
4630
|
+
for (let j = 0; j < childContext.contextSize(); ++j) {
|
|
4631
|
+
const currentNode = childContext.nodeList[j];
|
|
4632
|
+
if (currentNode.nodeType === DOM_TEXT_NODE) {
|
|
4633
|
+
const textNodeContext = context.clone([currentNode], 0);
|
|
4634
|
+
this.commonLogicTextNode(textNodeContext, currentNode, output);
|
|
4635
|
+
} else {
|
|
4636
|
+
const clonedContext = childContext.clone([currentNode], 0);
|
|
4637
|
+
const selection = selectBestTemplate(
|
|
4638
|
+
expandedTemplates,
|
|
4639
|
+
clonedContext,
|
|
4640
|
+
this.matchResolver,
|
|
4641
|
+
this.xPath
|
|
4642
|
+
);
|
|
4643
|
+
if (selection.selectedTemplate) {
|
|
4644
|
+
const templateContext = clonedContext.clone([currentNode], 0);
|
|
4645
|
+
templateContext.inApplyTemplates = true;
|
|
4646
|
+
yield this.xsltChildNodes(templateContext, selection.selectedTemplate, output);
|
|
4647
|
+
} else {
|
|
4648
|
+
if (currentNode.childNodes && currentNode.childNodes.length > 0) {
|
|
4649
|
+
const grandchildNodes = currentNode.childNodes.filter((n) => n.nodeName !== "#dtd-section");
|
|
4650
|
+
if (grandchildNodes.length > 0) {
|
|
4651
|
+
const grandchildContext = context.clone(grandchildNodes);
|
|
4652
|
+
for (let k = 0; k < grandchildContext.contextSize(); ++k) {
|
|
4653
|
+
const grandchildNode = grandchildContext.nodeList[k];
|
|
4654
|
+
if (grandchildNode.nodeType === DOM_TEXT_NODE) {
|
|
4655
|
+
const textNodeContext = context.clone([grandchildNode], 0);
|
|
4656
|
+
this.commonLogicTextNode(textNodeContext, grandchildNode, output);
|
|
4657
|
+
} else {
|
|
4658
|
+
const grandchildClonedContext = grandchildContext.clone([grandchildNode], 0);
|
|
4659
|
+
const grandchildSelection = selectBestTemplate(
|
|
4660
|
+
expandedTemplates,
|
|
4661
|
+
grandchildClonedContext,
|
|
4662
|
+
this.matchResolver,
|
|
4663
|
+
this.xPath
|
|
4664
|
+
);
|
|
4665
|
+
if (grandchildSelection.selectedTemplate) {
|
|
4666
|
+
const grandchildTemplateContext = grandchildClonedContext.clone([grandchildNode], 0);
|
|
4667
|
+
grandchildTemplateContext.inApplyTemplates = true;
|
|
4668
|
+
yield this.xsltChildNodes(grandchildTemplateContext, grandchildSelection.selectedTemplate, output);
|
|
4669
|
+
}
|
|
4670
|
+
}
|
|
4671
|
+
}
|
|
4672
|
+
}
|
|
4673
|
+
}
|
|
4674
|
+
}
|
|
4675
|
+
}
|
|
4676
|
+
}
|
|
4677
|
+
}
|
|
4678
|
+
}
|
|
4615
4679
|
}
|
|
4616
4680
|
}
|
|
4617
4681
|
});
|
|
4618
4682
|
}
|
|
4619
4683
|
xsltValueOf(context, template, output) {
|
|
4620
4684
|
const select = xmlGetAttribute(template, "select");
|
|
4621
|
-
const
|
|
4685
|
+
const current = context.nodeList[context.position];
|
|
4686
|
+
let attribute = this.xPath.xPathEval(select, context);
|
|
4687
|
+
if (current && current.nodeName === "#document" && (attribute.stringValue() === "" || attribute instanceof NodeSetValue && attribute.nodeSetValue().length === 0)) {
|
|
4688
|
+
const docChild = current.childNodes.find((c) => c.nodeName !== "#dtd-section");
|
|
4689
|
+
if (docChild) {
|
|
4690
|
+
const fallbackContext = context.clone([docChild], 0);
|
|
4691
|
+
attribute = this.xPath.xPathEval(select, fallbackContext);
|
|
4692
|
+
}
|
|
4693
|
+
}
|
|
4622
4694
|
const value = attribute.stringValue();
|
|
4623
4695
|
const node = domCreateTextNode(this.outputDocument, value);
|
|
4624
4696
|
const targetOutput = output || this.outputDocument;
|