xslt-processor 5.0.4 → 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 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.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 String(evaluatedArgs[0]).startsWith(String(evaluatedArgs[1]));
6331
+ return this.convertToString(evaluatedArgs[0]).startsWith(this.convertToString(evaluatedArgs[1]));
6332
6332
  case "contains":
6333
- return String(evaluatedArgs[0]).includes(String(evaluatedArgs[1]));
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, _c, _d;
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 (_d = (_c = value[0]) == null ? void 0 : _c.textContent) != null ? _d : String(value[0]);
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 String(args[0]).length;
6558
+ return this.convertToString(args[0]).length;
6556
6559
  }
6557
6560
  normalizeSpace(args, context) {
6558
- const str = args.length === 0 ? this.stringValue([], context) : String(args[0]);
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 = String(args[0]);
6563
- const search = String(args[1]);
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 = String(args[0]);
6569
- const search = String(args[1]);
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 = String(args[0]);
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 = String(args[0]);
6589
- const from = String(args[1]);
6590
- const to = String(args[2]);
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
  }
@@ -14540,7 +14543,7 @@ var Xslt = class {
14540
14543
  return;
14541
14544
  }
14542
14545
  const childNodes = node.childNodes.filter(
14543
- (n) => n.nodeType !== DOM_ATTRIBUTE_NODE
14546
+ (n) => n.nodeType !== DOM_ATTRIBUTE_NODE && n.nodeName !== "#dtd-section"
14544
14547
  );
14545
14548
  for (const childNode of childNodes) {
14546
14549
  if (childNode.nodeType === DOM_TEXT_NODE) {
@@ -16977,7 +16980,7 @@ var Xslt = class {
16977
16980
  */
16978
16981
  xsltTransformOrStylesheet(context, template, output) {
16979
16982
  return __async(this, null, function* () {
16980
- var _a, _b, _c;
16983
+ var _a;
16981
16984
  const mainStylesheetMetadata = {
16982
16985
  importDepth: 0,
16983
16986
  href: "(main stylesheet)",
@@ -17068,80 +17071,8 @@ var Xslt = class {
17068
17071
  this.currentTemplateStack.pop();
17069
17072
  } else {
17070
17073
  const rootNode = context.nodeList[context.position];
17071
- if (rootNode && rootNode.childNodes && rootNode.childNodes.length > 0) {
17072
- const childNodes = rootNode.childNodes.filter((n) => n.nodeName !== "#dtd-section");
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
- }
17074
+ if (rootNode) {
17075
+ yield this.applyBuiltInTemplate(rootNode, expandedTemplates, null, context, output);
17145
17076
  }
17146
17077
  }
17147
17078
  }