xslt-processor 5.0.5 → 5.0.7

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.d.mts CHANGED
@@ -86,6 +86,22 @@ declare class XDocument extends XNode {
86
86
  */
87
87
  declare function domDocumentToXDocument(nativeNode: Document | Node): XDocument;
88
88
 
89
+ type XmlOutputOptions = {
90
+ cData: boolean;
91
+ escape: boolean;
92
+ selfClosingTags: boolean;
93
+ outputMethod: 'xml' | 'html' | 'text' | 'name' | 'xhtml';
94
+ outputVersion?: string;
95
+ itemSeparator?: string;
96
+ };
97
+
98
+ /**
99
+ * Returns the representation of a node as XML text.
100
+ * @param {XNode} node The starting node.
101
+ * @param {XmlOutputOptions} options XML output options.
102
+ * @returns The XML string.
103
+ */
104
+ declare function xmlTransformedText(node: XNode, options?: XmlOutputOptions): string;
89
105
  /**
90
106
  * Escape XML special markup characters: tag delimiter <, >, and entity
91
107
  * reference start delimiter &. The escaped string can be used in XML
@@ -1771,4 +1787,4 @@ declare class Xslt {
1771
1787
  protected isXsltElement(element: XNode, opt_wantedName?: string): boolean;
1772
1788
  }
1773
1789
 
1774
- export { ExprContext, XDocument, XNode, XPath, XmlParser, Xslt, type XsltOptions, domDocumentToXDocument, xmlEscapeText };
1790
+ export { ExprContext, XDocument, XNode, XPath, XmlParser, Xslt, type XsltOptions, domDocumentToXDocument, xmlEscapeText, xmlTransformedText };
package/dist/index.d.ts CHANGED
@@ -86,6 +86,22 @@ declare class XDocument extends XNode {
86
86
  */
87
87
  declare function domDocumentToXDocument(nativeNode: Document | Node): XDocument;
88
88
 
89
+ type XmlOutputOptions = {
90
+ cData: boolean;
91
+ escape: boolean;
92
+ selfClosingTags: boolean;
93
+ outputMethod: 'xml' | 'html' | 'text' | 'name' | 'xhtml';
94
+ outputVersion?: string;
95
+ itemSeparator?: string;
96
+ };
97
+
98
+ /**
99
+ * Returns the representation of a node as XML text.
100
+ * @param {XNode} node The starting node.
101
+ * @param {XmlOutputOptions} options XML output options.
102
+ * @returns The XML string.
103
+ */
104
+ declare function xmlTransformedText(node: XNode, options?: XmlOutputOptions): string;
89
105
  /**
90
106
  * Escape XML special markup characters: tag delimiter <, >, and entity
91
107
  * reference start delimiter &. The escaped string can be used in XML
@@ -1771,4 +1787,4 @@ declare class Xslt {
1771
1787
  protected isXsltElement(element: XNode, opt_wantedName?: string): boolean;
1772
1788
  }
1773
1789
 
1774
- export { ExprContext, XDocument, XNode, XPath, XmlParser, Xslt, type XsltOptions, domDocumentToXDocument, xmlEscapeText };
1790
+ export { ExprContext, XDocument, XNode, XPath, XmlParser, Xslt, type XsltOptions, domDocumentToXDocument, xmlEscapeText, xmlTransformedText };
package/dist/index.js CHANGED
@@ -811,11 +811,45 @@ var init_filter_expression = __esm({
811
811
  }
812
812
  });
813
813
 
814
+ // src/xpath/lib/src/expressions/node-utils.ts
815
+ function getStringValueFromNode(node) {
816
+ var _a;
817
+ if (node === null || node === void 0) return null;
818
+ if (typeof node !== "object") return null;
819
+ if (typeof node.nodeType !== "number") return null;
820
+ if (node.nodeType === 3 || node.nodeType === 2) {
821
+ const v = node.nodeValue;
822
+ return v !== null && v !== void 0 && v !== "null" ? String(v) : "";
823
+ }
824
+ if (node.nodeType === 1 || node.nodeType === 9) {
825
+ const children = node.childNodes;
826
+ if (!children || children.length === 0) return "";
827
+ let text = "";
828
+ for (const child of children) {
829
+ if (child.nodeType === 3) {
830
+ const v = child.nodeValue;
831
+ if (v !== null && v !== void 0 && v !== "null") {
832
+ text += String(v);
833
+ }
834
+ } else if (child.nodeType === 1) {
835
+ text += (_a = getStringValueFromNode(child)) != null ? _a : "";
836
+ }
837
+ }
838
+ return text;
839
+ }
840
+ return null;
841
+ }
842
+ var init_node_utils = __esm({
843
+ "src/xpath/lib/src/expressions/node-utils.ts"() {
844
+ }
845
+ });
846
+
814
847
  // src/xpath/lib/src/expressions/unary-expression.ts
815
848
  var XPathUnaryExpression;
816
849
  var init_unary_expression = __esm({
817
850
  "src/xpath/lib/src/expressions/unary-expression.ts"() {
818
851
  init_expression();
852
+ init_node_utils();
819
853
  XPathUnaryExpression = class extends XPathExpression {
820
854
  constructor(operator, operand) {
821
855
  super();
@@ -843,12 +877,14 @@ var init_unary_expression = __esm({
843
877
  return null;
844
878
  }
845
879
  if (!Array.isArray(value)) {
880
+ const text = getStringValueFromNode(value);
881
+ if (text !== null) return text;
846
882
  return value;
847
883
  }
848
884
  if (value.length === 0) {
849
885
  return null;
850
886
  }
851
- return value[0];
887
+ return this.atomize(value[0]);
852
888
  }
853
889
  /**
854
890
  * Convert atomic value to number following XPath 2.0 rules
@@ -989,6 +1025,7 @@ var XPathArithmeticExpression;
989
1025
  var init_arithmetic_expression = __esm({
990
1026
  "src/xpath/lib/src/expressions/arithmetic-expression.ts"() {
991
1027
  init_expression();
1028
+ init_node_utils();
992
1029
  XPathArithmeticExpression = class extends XPathExpression {
993
1030
  constructor(left, right, operator) {
994
1031
  super();
@@ -1042,6 +1079,8 @@ var init_arithmetic_expression = __esm({
1042
1079
  return value.numberValue();
1043
1080
  }
1044
1081
  if (!Array.isArray(value)) {
1082
+ const text = getStringValueFromNode(value);
1083
+ if (text !== null) return text;
1045
1084
  return value;
1046
1085
  }
1047
1086
  if (value.length === 0) {
@@ -7819,7 +7858,8 @@ __export(index_exports, {
7819
7858
  XmlParser: () => XmlParser,
7820
7859
  Xslt: () => Xslt,
7821
7860
  domDocumentToXDocument: () => domDocumentToXDocument,
7822
- xmlEscapeText: () => xmlEscapeText
7861
+ xmlEscapeText: () => xmlEscapeText,
7862
+ xmlTransformedText: () => xmlTransformedText
7823
7863
  });
7824
7864
  module.exports = __toCommonJS(index_exports);
7825
7865
 
@@ -11027,7 +11067,7 @@ function xmlTransformedTextRecursive(node, buffer, options) {
11027
11067
  }
11028
11068
  } else if (nodeType == DOM_COMMENT_NODE) {
11029
11069
  if (options.outputMethod !== "text") {
11030
- buffer.push(`<!-- ${nodeValue} -->`);
11070
+ buffer.push(`<!--${nodeValue}-->`);
11031
11071
  }
11032
11072
  } else if (nodeType === DOM_PROCESSING_INSTRUCTION_NODE) {
11033
11073
  if (options.outputMethod !== "text") {
@@ -11465,14 +11505,14 @@ var XmlParser = class {
11465
11505
  }
11466
11506
  if (htmlText.slice(i + 1, i + 4) === "!--") {
11467
11507
  let endTagIndex = htmlText.slice(i + 4).indexOf("-->");
11468
- if (endTagIndex) {
11508
+ if (endTagIndex >= 0) {
11469
11509
  let node = domCreateComment(xmlDocument, htmlText.slice(i + 4, i + endTagIndex + 4));
11470
11510
  domAppendChild(parent, node);
11471
11511
  i += endTagIndex + 6;
11472
11512
  }
11473
11513
  } else if (htmlText.slice(i + 1, i + 9) === "!DOCTYPE") {
11474
11514
  let endTagIndex = htmlText.slice(i + 9).indexOf(">");
11475
- if (endTagIndex) {
11515
+ if (endTagIndex >= 0) {
11476
11516
  const dtdValue = htmlText.slice(i + 9, i + endTagIndex + 9).trimStart();
11477
11517
  const node = domCreateDTDSection(xmlDocument, dtdValue);
11478
11518
  domAppendChild(parent, node);
@@ -11571,21 +11611,21 @@ var XmlParser = class {
11571
11611
  }
11572
11612
  if (xml.slice(i + 1, i + 4) === "!--") {
11573
11613
  let endTagIndex = xml.slice(i + 4).indexOf("-->");
11574
- if (endTagIndex) {
11614
+ if (endTagIndex >= 0) {
11575
11615
  let node = domCreateComment(xmlDocument, xml.slice(i + 4, i + endTagIndex + 4));
11576
11616
  domAppendChild(parent, node);
11577
11617
  i += endTagIndex + 6;
11578
11618
  }
11579
11619
  } else if (xml.slice(i + 1, i + 9) === "![CDATA[") {
11580
11620
  let endTagIndex = xml.slice(i + 9).indexOf("]]>");
11581
- if (endTagIndex) {
11621
+ if (endTagIndex >= 0) {
11582
11622
  let node = domCreateCDATASection(xmlDocument, xml.slice(i + 9, i + endTagIndex + 9));
11583
11623
  domAppendChild(parent, node);
11584
11624
  i += endTagIndex + 11;
11585
11625
  }
11586
11626
  } else if (xml.slice(i + 1, i + 9) === "!DOCTYPE") {
11587
11627
  let endTagIndex = xml.slice(i + 9).indexOf(">");
11588
- if (endTagIndex) {
11628
+ if (endTagIndex >= 0) {
11589
11629
  const dtdValue = xml.slice(i + 9, i + endTagIndex + 9).trimStart();
11590
11630
  const node = domCreateDTDSection(xmlDocument, dtdValue);
11591
11631
  domAppendChild(parent, node);
@@ -18127,6 +18167,7 @@ var Xslt = class {
18127
18167
  XmlParser,
18128
18168
  Xslt,
18129
18169
  domDocumentToXDocument,
18130
- xmlEscapeText
18170
+ xmlEscapeText,
18171
+ xmlTransformedText
18131
18172
  });
18132
18173
  //# sourceMappingURL=index.js.map