xslt-processor 4.8.4 → 4.8.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/index.d.mts +11 -3
- package/index.d.ts +11 -3
- package/index.js +148 -16
- package/index.js.map +1 -1
- package/index.mjs +148 -16
- package/index.mjs.map +1 -1
- package/package.json +1 -1
- package/umd/xslt-processor.global.js +5 -5
- package/umd/xslt-processor.global.js.map +1 -1
package/index.mjs
CHANGED
|
@@ -10962,6 +10962,9 @@ function xmlElementLogicTrivial(node, buffer, options) {
|
|
|
10962
10962
|
if (!attribute) {
|
|
10963
10963
|
continue;
|
|
10964
10964
|
}
|
|
10965
|
+
if (options.outputMethod === "html" && (attribute.nodeName === "xmlns" || attribute.nodeName.startsWith("xmlns:"))) {
|
|
10966
|
+
continue;
|
|
10967
|
+
}
|
|
10965
10968
|
if (attribute.nodeName && attribute.nodeValue !== null && attribute.nodeValue !== void 0) {
|
|
10966
10969
|
buffer.push(` ${xmlFullNodeName(attribute)}="${xmlEscapeAttr(attribute.nodeValue)}"`);
|
|
10967
10970
|
}
|
|
@@ -14464,7 +14467,40 @@ var Xslt = class {
|
|
|
14464
14467
|
} = currentTemplateContext;
|
|
14465
14468
|
const currentNode = context.nodeList[context.position];
|
|
14466
14469
|
const top = template.ownerDocument.documentElement;
|
|
14467
|
-
const
|
|
14470
|
+
const stylesheetRoots = [];
|
|
14471
|
+
if (top) {
|
|
14472
|
+
stylesheetRoots.push(top);
|
|
14473
|
+
}
|
|
14474
|
+
this.importedStylesheets.forEach((doc) => {
|
|
14475
|
+
if (!doc) {
|
|
14476
|
+
return;
|
|
14477
|
+
}
|
|
14478
|
+
if (doc.nodeType === DOM_DOCUMENT_NODE) {
|
|
14479
|
+
const rootElement = doc.childNodes.find(
|
|
14480
|
+
(child) => child.nodeType === DOM_ELEMENT_NODE
|
|
14481
|
+
);
|
|
14482
|
+
if (rootElement) {
|
|
14483
|
+
stylesheetRoots.push(rootElement);
|
|
14484
|
+
}
|
|
14485
|
+
} else if (doc.nodeType === DOM_ELEMENT_NODE) {
|
|
14486
|
+
stylesheetRoots.push(doc);
|
|
14487
|
+
}
|
|
14488
|
+
});
|
|
14489
|
+
let allTemplates = [];
|
|
14490
|
+
let docOrderOffset = 0;
|
|
14491
|
+
for (const root2 of stylesheetRoots) {
|
|
14492
|
+
const templates = collectAndExpandTemplates(
|
|
14493
|
+
root2,
|
|
14494
|
+
currentMode,
|
|
14495
|
+
this.xPath,
|
|
14496
|
+
this.templateSourceMap
|
|
14497
|
+
);
|
|
14498
|
+
for (const templateEntry of templates) {
|
|
14499
|
+
templateEntry.documentOrder += docOrderOffset;
|
|
14500
|
+
}
|
|
14501
|
+
docOrderOffset += templates.length;
|
|
14502
|
+
allTemplates = allTemplates.concat(templates);
|
|
14503
|
+
}
|
|
14468
14504
|
const importedTemplates = allTemplates.filter((t) => {
|
|
14469
14505
|
const metadata2 = this.templateSourceMap.get(t.template);
|
|
14470
14506
|
return metadata2 && metadata2.importDepth > currentDepth;
|
|
@@ -14600,7 +14636,11 @@ var Xslt = class {
|
|
|
14600
14636
|
if (source.nodeType == DOM_ELEMENT_NODE) {
|
|
14601
14637
|
let node = domCreateElement(this.outputDocument, source.nodeName);
|
|
14602
14638
|
if (source.namespaceUri !== null && source.namespaceUri !== void 0) {
|
|
14603
|
-
|
|
14639
|
+
const prefix = source.prefix || (source.nodeName.includes(":") ? source.nodeName.split(":")[0] : null);
|
|
14640
|
+
const nsAttr = prefix ? `xmlns:${prefix}` : "xmlns";
|
|
14641
|
+
if (!this.isNamespaceDeclaredOnAncestor(destination, nsAttr, source.namespaceUri)) {
|
|
14642
|
+
domSetAttribute(node, nsAttr, source.namespaceUri);
|
|
14643
|
+
}
|
|
14604
14644
|
}
|
|
14605
14645
|
node.siblingPosition = destination.childNodes.length;
|
|
14606
14646
|
domAppendChild(destination, node);
|
|
@@ -16343,6 +16383,17 @@ var Xslt = class {
|
|
|
16343
16383
|
* @returns The formatted number string.
|
|
16344
16384
|
*/
|
|
16345
16385
|
xsltFormatNumber(number, format, groupingSeparator, groupingSize) {
|
|
16386
|
+
if (format.match(/^0+1$/)) {
|
|
16387
|
+
const width = format.length;
|
|
16388
|
+
let result2 = number.toString().padStart(width, "0");
|
|
16389
|
+
if (groupingSeparator && groupingSize) {
|
|
16390
|
+
const size = parseInt(groupingSize, 10);
|
|
16391
|
+
if (size > 0 && !isNaN(size)) {
|
|
16392
|
+
result2 = this.applyGrouping(result2, groupingSeparator, size);
|
|
16393
|
+
}
|
|
16394
|
+
}
|
|
16395
|
+
return result2;
|
|
16396
|
+
}
|
|
16346
16397
|
const formatChar = format.charAt(0);
|
|
16347
16398
|
let result;
|
|
16348
16399
|
switch (formatChar) {
|
|
@@ -16471,6 +16522,54 @@ var Xslt = class {
|
|
|
16471
16522
|
}
|
|
16472
16523
|
this.xPath.xPathSort(context, sort2);
|
|
16473
16524
|
}
|
|
16525
|
+
resolveNamespaceUriForPrefix(node, prefix) {
|
|
16526
|
+
const attrName = prefix ? `xmlns:${prefix}` : "xmlns";
|
|
16527
|
+
let current = node;
|
|
16528
|
+
while (current) {
|
|
16529
|
+
const attributes = current.childNodes.filter(
|
|
16530
|
+
(child) => child.nodeType === DOM_ATTRIBUTE_NODE
|
|
16531
|
+
);
|
|
16532
|
+
for (const attribute of attributes) {
|
|
16533
|
+
if (attribute.nodeName === attrName) {
|
|
16534
|
+
return attribute.nodeValue;
|
|
16535
|
+
}
|
|
16536
|
+
if (prefix && attribute.prefix === "xmlns" && attribute.localName === prefix) {
|
|
16537
|
+
return attribute.nodeValue;
|
|
16538
|
+
}
|
|
16539
|
+
if (!prefix && attribute.nodeName === "xmlns") {
|
|
16540
|
+
return attribute.nodeValue;
|
|
16541
|
+
}
|
|
16542
|
+
}
|
|
16543
|
+
current = current.parentNode;
|
|
16544
|
+
}
|
|
16545
|
+
return null;
|
|
16546
|
+
}
|
|
16547
|
+
isNamespaceDeclaredOnAncestor(node, nsAttr, nsUri) {
|
|
16548
|
+
let current = node;
|
|
16549
|
+
while (current) {
|
|
16550
|
+
const value = domGetAttributeValue(current, nsAttr);
|
|
16551
|
+
if (value === nsUri) {
|
|
16552
|
+
return true;
|
|
16553
|
+
}
|
|
16554
|
+
current = current.parentNode;
|
|
16555
|
+
}
|
|
16556
|
+
return false;
|
|
16557
|
+
}
|
|
16558
|
+
parseWhitespacePattern(pattern, template) {
|
|
16559
|
+
if (pattern === "*") {
|
|
16560
|
+
return { namespaceUri: null, localName: "*", isWildcard: true };
|
|
16561
|
+
}
|
|
16562
|
+
if (pattern.includes(":")) {
|
|
16563
|
+
const [prefix, localPart] = pattern.split(":");
|
|
16564
|
+
const namespaceUri = this.resolveNamespaceUriForPrefix(template, prefix);
|
|
16565
|
+
return {
|
|
16566
|
+
namespaceUri: namespaceUri != null ? namespaceUri : null,
|
|
16567
|
+
localName: localPart || "*",
|
|
16568
|
+
isWildcard: localPart === "*"
|
|
16569
|
+
};
|
|
16570
|
+
}
|
|
16571
|
+
return { namespaceUri: null, localName: pattern, isWildcard: false };
|
|
16572
|
+
}
|
|
16474
16573
|
/**
|
|
16475
16574
|
* Implements `xsl:strip-space`.
|
|
16476
16575
|
* Collects element name patterns for which whitespace-only text nodes should be stripped.
|
|
@@ -16480,7 +16579,9 @@ var Xslt = class {
|
|
|
16480
16579
|
const elements = xmlGetAttribute(template, "elements");
|
|
16481
16580
|
if (elements) {
|
|
16482
16581
|
const patterns = elements.trim().split(/\s+/);
|
|
16483
|
-
|
|
16582
|
+
for (const pattern of patterns) {
|
|
16583
|
+
this.stripSpacePatterns.push(this.parseWhitespacePattern(pattern, template));
|
|
16584
|
+
}
|
|
16484
16585
|
}
|
|
16485
16586
|
}
|
|
16486
16587
|
/**
|
|
@@ -16493,7 +16594,9 @@ var Xslt = class {
|
|
|
16493
16594
|
const elements = xmlGetAttribute(template, "elements");
|
|
16494
16595
|
if (elements) {
|
|
16495
16596
|
const patterns = elements.trim().split(/\s+/);
|
|
16496
|
-
|
|
16597
|
+
for (const pattern of patterns) {
|
|
16598
|
+
this.preserveSpacePatterns.push(this.parseWhitespacePattern(pattern, template));
|
|
16599
|
+
}
|
|
16497
16600
|
}
|
|
16498
16601
|
}
|
|
16499
16602
|
/**
|
|
@@ -16550,19 +16653,19 @@ var Xslt = class {
|
|
|
16550
16653
|
* @returns True if the element matches the pattern.
|
|
16551
16654
|
*/
|
|
16552
16655
|
matchesNamePattern(elementName, pattern, element) {
|
|
16553
|
-
|
|
16554
|
-
|
|
16555
|
-
|
|
16556
|
-
|
|
16557
|
-
|
|
16558
|
-
const elementPrefix = element.prefix || "";
|
|
16559
|
-
if (localPart === "*") {
|
|
16560
|
-
return elementPrefix === prefix;
|
|
16561
|
-
} else {
|
|
16562
|
-
return elementPrefix === prefix && elementName === localPart;
|
|
16656
|
+
var _a;
|
|
16657
|
+
const elementNamespace = (_a = element.namespaceUri) != null ? _a : this.resolveNamespaceUriForPrefix(element, element.prefix || null);
|
|
16658
|
+
if (pattern.namespaceUri !== null) {
|
|
16659
|
+
if (elementNamespace !== pattern.namespaceUri) {
|
|
16660
|
+
return false;
|
|
16563
16661
|
}
|
|
16662
|
+
} else if (!pattern.isWildcard && elementNamespace) {
|
|
16663
|
+
return false;
|
|
16664
|
+
}
|
|
16665
|
+
if (pattern.isWildcard) {
|
|
16666
|
+
return true;
|
|
16564
16667
|
}
|
|
16565
|
-
return elementName === pattern;
|
|
16668
|
+
return elementName === pattern.localName;
|
|
16566
16669
|
}
|
|
16567
16670
|
/**
|
|
16568
16671
|
* Implements `xsl:template`.
|
|
@@ -17448,9 +17551,38 @@ var Xslt = class {
|
|
|
17448
17551
|
let elementContext = context;
|
|
17449
17552
|
node = context.nodeList[context.position];
|
|
17450
17553
|
let newNode;
|
|
17451
|
-
|
|
17554
|
+
let qualifiedName = template.nodeName;
|
|
17555
|
+
let namespaceUri = template.namespaceUri;
|
|
17556
|
+
const templatePrefix = template.prefix || "";
|
|
17557
|
+
const aliasPrefix = this.namespaceAliases.get(templatePrefix);
|
|
17558
|
+
if (aliasPrefix) {
|
|
17559
|
+
const localName = template.localName || template.nodeName;
|
|
17560
|
+
if (aliasPrefix === "#default") {
|
|
17561
|
+
qualifiedName = localName;
|
|
17562
|
+
namespaceUri = this.resolveNamespaceUriForPrefix(template, null);
|
|
17563
|
+
} else {
|
|
17564
|
+
qualifiedName = `${aliasPrefix}:${localName}`;
|
|
17565
|
+
namespaceUri = this.resolveNamespaceUriForPrefix(template, aliasPrefix);
|
|
17566
|
+
}
|
|
17567
|
+
}
|
|
17568
|
+
newNode = domCreateElement(this.outputDocument, qualifiedName);
|
|
17452
17569
|
newNode.siblingPosition = (output || this.outputDocument).childNodes.length;
|
|
17453
17570
|
domAppendChild(output || this.outputDocument, newNode);
|
|
17571
|
+
if (aliasPrefix) {
|
|
17572
|
+
if (aliasPrefix === "#default") {
|
|
17573
|
+
if (namespaceUri) {
|
|
17574
|
+
domSetAttribute(newNode, "xmlns", namespaceUri);
|
|
17575
|
+
}
|
|
17576
|
+
} else if (namespaceUri) {
|
|
17577
|
+
domSetAttribute(newNode, `xmlns:${aliasPrefix}`, namespaceUri);
|
|
17578
|
+
}
|
|
17579
|
+
} else if (namespaceUri) {
|
|
17580
|
+
const prefix = templatePrefix || (qualifiedName.includes(":") ? qualifiedName.split(":")[0] : null);
|
|
17581
|
+
const nsAttr = prefix ? `xmlns:${prefix}` : "xmlns";
|
|
17582
|
+
if (!this.isNamespaceDeclaredOnAncestor(output, nsAttr, namespaceUri)) {
|
|
17583
|
+
domSetAttribute(newNode, nsAttr, namespaceUri);
|
|
17584
|
+
}
|
|
17585
|
+
}
|
|
17454
17586
|
const useAttributeSetsAttr = template.childNodes.find(
|
|
17455
17587
|
(a) => (a == null ? void 0 : a.nodeType) === DOM_ATTRIBUTE_NODE && a.nodeName === "use-attribute-sets"
|
|
17456
17588
|
);
|