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/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 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
  }
@@ -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) {
@@ -16963,7 +16966,7 @@ var Xslt = class {
16963
16966
  */
16964
16967
  xsltTransformOrStylesheet(context, template, output) {
16965
16968
  return __async(this, null, function* () {
16966
- var _a, _b, _c;
16969
+ var _a;
16967
16970
  const mainStylesheetMetadata = {
16968
16971
  importDepth: 0,
16969
16972
  href: "(main stylesheet)",
@@ -17054,80 +17057,8 @@ var Xslt = class {
17054
17057
  this.currentTemplateStack.pop();
17055
17058
  } else {
17056
17059
  const rootNode = context.nodeList[context.position];
17057
- if (rootNode && rootNode.childNodes && rootNode.childNodes.length > 0) {
17058
- const childNodes = rootNode.childNodes.filter((n) => n.nodeName !== "#dtd-section");
17059
- if (childNodes.length > 0) {
17060
- const childContext = context.clone(childNodes);
17061
- for (let j = 0; j < childContext.contextSize(); ++j) {
17062
- const currentNode = childContext.nodeList[j];
17063
- if (currentNode.nodeType === DOM_TEXT_NODE) {
17064
- const textNodeContext = context.clone([currentNode], 0);
17065
- this.commonLogicTextNode(textNodeContext, currentNode, output);
17066
- } else {
17067
- const clonedContext = childContext.clone([currentNode], 0);
17068
- const selection = selectBestTemplate(
17069
- expandedTemplates,
17070
- clonedContext,
17071
- this.matchResolver,
17072
- this.xPath,
17073
- this.warningsCallback
17074
- );
17075
- if (selection.selectedTemplate) {
17076
- const templateContext = clonedContext.clone([currentNode], 0);
17077
- templateContext.inApplyTemplates = true;
17078
- const metadata = this.templateSourceMap.get(selection.selectedTemplate);
17079
- const matchPattern = xmlGetAttribute(selection.selectedTemplate, "match");
17080
- const modeAttr = xmlGetAttribute(selection.selectedTemplate, "mode");
17081
- this.currentTemplateStack.push({
17082
- template: selection.selectedTemplate,
17083
- stylesheetDepth: (_b = metadata == null ? void 0 : metadata.importDepth) != null ? _b : 0,
17084
- mode: modeAttr || null,
17085
- match: matchPattern
17086
- });
17087
- yield this.xsltChildNodes(templateContext, selection.selectedTemplate, output);
17088
- this.currentTemplateStack.pop();
17089
- } else {
17090
- if (currentNode.childNodes && currentNode.childNodes.length > 0) {
17091
- const grandchildNodes = currentNode.childNodes.filter((n) => n.nodeName !== "#dtd-section");
17092
- if (grandchildNodes.length > 0) {
17093
- const grandchildContext = context.clone(grandchildNodes);
17094
- for (let k = 0; k < grandchildContext.contextSize(); ++k) {
17095
- const grandchildNode = grandchildContext.nodeList[k];
17096
- if (grandchildNode.nodeType === DOM_TEXT_NODE) {
17097
- const textNodeContext = context.clone([grandchildNode], 0);
17098
- this.commonLogicTextNode(textNodeContext, grandchildNode, output);
17099
- } else {
17100
- const grandchildClonedContext = grandchildContext.clone([grandchildNode], 0);
17101
- const grandchildSelection = selectBestTemplate(
17102
- expandedTemplates,
17103
- grandchildClonedContext,
17104
- this.matchResolver,
17105
- this.xPath,
17106
- this.warningsCallback
17107
- );
17108
- if (grandchildSelection.selectedTemplate) {
17109
- const grandchildTemplateContext = grandchildClonedContext.clone([grandchildNode], 0);
17110
- grandchildTemplateContext.inApplyTemplates = true;
17111
- const metadata = this.templateSourceMap.get(grandchildSelection.selectedTemplate);
17112
- const matchPattern = xmlGetAttribute(grandchildSelection.selectedTemplate, "match");
17113
- const modeAttr = xmlGetAttribute(grandchildSelection.selectedTemplate, "mode");
17114
- this.currentTemplateStack.push({
17115
- template: grandchildSelection.selectedTemplate,
17116
- stylesheetDepth: (_c = metadata == null ? void 0 : metadata.importDepth) != null ? _c : 0,
17117
- mode: modeAttr || null,
17118
- match: matchPattern
17119
- });
17120
- yield this.xsltChildNodes(grandchildTemplateContext, grandchildSelection.selectedTemplate, output);
17121
- this.currentTemplateStack.pop();
17122
- }
17123
- }
17124
- }
17125
- }
17126
- }
17127
- }
17128
- }
17129
- }
17130
- }
17060
+ if (rootNode) {
17061
+ yield this.applyBuiltInTemplate(rootNode, expandedTemplates, null, context, output);
17131
17062
  }
17132
17063
  }
17133
17064
  }