xslt-processor 3.0.0 → 3.0.2

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.
Files changed (224) hide show
  1. package/README.md +2 -2
  2. package/constants.d.ts +12 -12
  3. package/constants.js +16 -16
  4. package/dom/functions.d.ts +14 -14
  5. package/dom/functions.js +56 -57
  6. package/dom/functions.js.map +1 -1
  7. package/dom/index.d.ts +6 -6
  8. package/dom/index.js +22 -22
  9. package/dom/util.d.ts +7 -7
  10. package/dom/util.js +42 -43
  11. package/dom/util.js.map +1 -1
  12. package/dom/xdocument.d.ts +16 -16
  13. package/dom/xdocument.js +73 -74
  14. package/dom/xdocument.js.map +1 -1
  15. package/dom/xml-functions.d.ts +58 -58
  16. package/dom/xml-functions.js +369 -370
  17. package/dom/xml-functions.js.map +1 -1
  18. package/dom/xml-output-options.d.ts +6 -6
  19. package/dom/xml-output-options.js +2 -2
  20. package/dom/xml-parser.d.ts +47 -47
  21. package/dom/xml-parser.js +307 -307
  22. package/dom/xml-parser.js.map +1 -1
  23. package/dom/xmltoken.d.ts +12 -12
  24. package/dom/xmltoken.js +101 -101
  25. package/dom/xnode.d.ts +73 -73
  26. package/dom/xnode.js +450 -450
  27. package/dom/xnode.js.map +1 -1
  28. package/index.d.ts +4 -4
  29. package/index.js +12 -12
  30. package/package.json +11 -11
  31. package/test-without-jest.d.ts +1 -0
  32. package/test-without-jest.js +63 -0
  33. package/test-without-jest.js.map +1 -0
  34. package/umd/constants.d.ts +12 -12
  35. package/umd/dom/functions.d.ts +14 -14
  36. package/umd/dom/index.d.ts +6 -6
  37. package/umd/dom/util.d.ts +7 -7
  38. package/umd/dom/xdocument.d.ts +16 -16
  39. package/umd/dom/xml-functions.d.ts +58 -58
  40. package/umd/dom/xml-output-options.d.ts +6 -6
  41. package/umd/dom/xml-parser.d.ts +47 -47
  42. package/umd/dom/xmltoken.d.ts +12 -12
  43. package/umd/dom/xnode.d.ts +73 -73
  44. package/umd/index.d.ts +4 -4
  45. package/umd/test-without-jest.d.ts +1 -0
  46. package/umd/xpath/common-function.d.ts +8 -8
  47. package/umd/xpath/expr-context.d.ts +111 -111
  48. package/umd/xpath/expressions/binary-expr.d.ts +11 -11
  49. package/umd/xpath/expressions/expression.d.ts +4 -4
  50. package/umd/xpath/expressions/filter-expr.d.ts +9 -9
  51. package/umd/xpath/expressions/function-call-expr.d.ts +12 -12
  52. package/umd/xpath/expressions/index.d.ts +13 -13
  53. package/umd/xpath/expressions/literal-expr.d.ts +7 -7
  54. package/umd/xpath/expressions/location-expr.d.ts +15 -15
  55. package/umd/xpath/expressions/number-expr.d.ts +7 -7
  56. package/umd/xpath/expressions/path-expr.d.ts +9 -9
  57. package/umd/xpath/expressions/predicate-expr.d.ts +8 -8
  58. package/umd/xpath/expressions/step-expr.d.ts +25 -25
  59. package/umd/xpath/expressions/token-expr.d.ts +7 -7
  60. package/umd/xpath/expressions/unary-minus-expr.d.ts +8 -8
  61. package/umd/xpath/expressions/union-expr.d.ts +9 -9
  62. package/umd/xpath/expressions/variable-expr.d.ts +7 -7
  63. package/umd/xpath/functions/index.d.ts +2 -2
  64. package/umd/xpath/functions/internal-functions.d.ts +2 -2
  65. package/umd/xpath/functions/non-standard.d.ts +12 -12
  66. package/umd/xpath/functions/standard-20.d.ts +5 -5
  67. package/umd/xpath/functions/standard.d.ts +40 -40
  68. package/umd/xpath/grammar-rule-candidate.d.ts +8 -8
  69. package/umd/xpath/index.d.ts +3 -3
  70. package/umd/xpath/match-resolver.d.ts +55 -55
  71. package/umd/xpath/node-tests/index.d.ts +8 -8
  72. package/umd/xpath/node-tests/node-test-any.d.ts +6 -6
  73. package/umd/xpath/node-tests/node-test-comment.d.ts +6 -6
  74. package/umd/xpath/node-tests/node-test-element-or-attribute.d.ts +6 -6
  75. package/umd/xpath/node-tests/node-test-name.d.ts +10 -10
  76. package/umd/xpath/node-tests/node-test-nc.d.ts +9 -9
  77. package/umd/xpath/node-tests/node-test-pi.d.ts +8 -8
  78. package/umd/xpath/node-tests/node-test-text.d.ts +6 -6
  79. package/umd/xpath/node-tests/node-test.d.ts +5 -5
  80. package/umd/xpath/tokens.d.ts +62 -62
  81. package/umd/xpath/values/boolean-value.d.ts +11 -11
  82. package/umd/xpath/values/index.d.ts +5 -5
  83. package/umd/xpath/values/node-set-value.d.ts +11 -11
  84. package/umd/xpath/values/node-value.d.ts +7 -7
  85. package/umd/xpath/values/number-value.d.ts +11 -11
  86. package/umd/xpath/values/string-value.d.ts +11 -11
  87. package/umd/xpath/xpath-grammar-rules.d.ts +68 -68
  88. package/umd/xpath/xpath-token-rule.d.ts +7 -7
  89. package/umd/xpath/xpath.d.ts +174 -170
  90. package/umd/xpathdebug.d.ts +2 -2
  91. package/umd/xslt/index.d.ts +3 -3
  92. package/umd/xslt/xslt-decimal-format-settings.d.ts +28 -28
  93. package/umd/xslt/xslt-options.d.ts +7 -7
  94. package/umd/xslt/xslt-parameter.d.ts +5 -5
  95. package/umd/xslt/xslt.d.ts +207 -190
  96. package/umd/xslt-processor.js +1 -15
  97. package/umd/xslt-processor.js.map +1 -1
  98. package/xpath/common-function.d.ts +8 -8
  99. package/xpath/common-function.js +31 -32
  100. package/xpath/common-function.js.map +1 -1
  101. package/xpath/expr-context.d.ts +111 -111
  102. package/xpath/expr-context.js +189 -189
  103. package/xpath/expr-context.js.map +1 -1
  104. package/xpath/expressions/binary-expr.d.ts +11 -11
  105. package/xpath/expressions/binary-expr.js +165 -165
  106. package/xpath/expressions/binary-expr.js.map +1 -1
  107. package/xpath/expressions/expression.d.ts +4 -4
  108. package/xpath/expressions/expression.js +9 -9
  109. package/xpath/expressions/filter-expr.d.ts +9 -9
  110. package/xpath/expressions/filter-expr.js +52 -52
  111. package/xpath/expressions/filter-expr.js.map +1 -1
  112. package/xpath/expressions/function-call-expr.d.ts +12 -12
  113. package/xpath/expressions/function-call-expr.js +95 -95
  114. package/xpath/expressions/function-call-expr.js.map +1 -1
  115. package/xpath/expressions/index.d.ts +13 -13
  116. package/xpath/expressions/index.js +29 -29
  117. package/xpath/expressions/literal-expr.d.ts +7 -7
  118. package/xpath/expressions/literal-expr.js +33 -33
  119. package/xpath/expressions/literal-expr.js.map +1 -1
  120. package/xpath/expressions/location-expr.d.ts +15 -15
  121. package/xpath/expressions/location-expr.js +98 -98
  122. package/xpath/expressions/location-expr.js.map +1 -1
  123. package/xpath/expressions/number-expr.d.ts +7 -7
  124. package/xpath/expressions/number-expr.js +33 -33
  125. package/xpath/expressions/number-expr.js.map +1 -1
  126. package/xpath/expressions/path-expr.d.ts +9 -9
  127. package/xpath/expressions/path-expr.js +51 -51
  128. package/xpath/expressions/path-expr.js.map +1 -1
  129. package/xpath/expressions/predicate-expr.d.ts +8 -8
  130. package/xpath/expressions/predicate-expr.js +40 -40
  131. package/xpath/expressions/predicate-expr.js.map +1 -1
  132. package/xpath/expressions/step-expr.d.ts +25 -25
  133. package/xpath/expressions/step-expr.js +280 -280
  134. package/xpath/expressions/step-expr.js.map +1 -1
  135. package/xpath/expressions/token-expr.d.ts +7 -7
  136. package/xpath/expressions/token-expr.js +33 -33
  137. package/xpath/expressions/token-expr.js.map +1 -1
  138. package/xpath/expressions/unary-minus-expr.d.ts +8 -8
  139. package/xpath/expressions/unary-minus-expr.js +33 -33
  140. package/xpath/expressions/unary-minus-expr.js.map +1 -1
  141. package/xpath/expressions/union-expr.d.ts +9 -9
  142. package/xpath/expressions/union-expr.js +50 -50
  143. package/xpath/expressions/union-expr.js.map +1 -1
  144. package/xpath/expressions/variable-expr.d.ts +7 -7
  145. package/xpath/expressions/variable-expr.js +32 -32
  146. package/xpath/expressions/variable-expr.js.map +1 -1
  147. package/xpath/functions/index.d.ts +2 -2
  148. package/xpath/functions/index.js +18 -18
  149. package/xpath/functions/internal-functions.d.ts +2 -2
  150. package/xpath/functions/internal-functions.js +21 -22
  151. package/xpath/functions/internal-functions.js.map +1 -1
  152. package/xpath/functions/non-standard.d.ts +12 -12
  153. package/xpath/functions/non-standard.js +44 -45
  154. package/xpath/functions/non-standard.js.map +1 -1
  155. package/xpath/functions/standard-20.d.ts +5 -5
  156. package/xpath/functions/standard-20.js +25 -26
  157. package/xpath/functions/standard-20.js.map +1 -1
  158. package/xpath/functions/standard.d.ts +40 -40
  159. package/xpath/functions/standard.js +441 -442
  160. package/xpath/functions/standard.js.map +1 -1
  161. package/xpath/grammar-rule-candidate.d.ts +8 -8
  162. package/xpath/grammar-rule-candidate.js +2 -2
  163. package/xpath/index.d.ts +3 -3
  164. package/xpath/index.js +19 -19
  165. package/xpath/match-resolver.d.ts +55 -55
  166. package/xpath/match-resolver.js +136 -136
  167. package/xpath/match-resolver.js.map +1 -1
  168. package/xpath/node-tests/index.d.ts +8 -8
  169. package/xpath/node-tests/index.js +17 -17
  170. package/xpath/node-tests/node-test-any.d.ts +6 -6
  171. package/xpath/node-tests/node-test-any.js +14 -14
  172. package/xpath/node-tests/node-test-comment.d.ts +6 -6
  173. package/xpath/node-tests/node-test-comment.js +14 -14
  174. package/xpath/node-tests/node-test-element-or-attribute.d.ts +6 -6
  175. package/xpath/node-tests/node-test-element-or-attribute.js +15 -15
  176. package/xpath/node-tests/node-test-name.d.ts +10 -10
  177. package/xpath/node-tests/node-test-name.js +38 -38
  178. package/xpath/node-tests/node-test-name.js.map +1 -1
  179. package/xpath/node-tests/node-test-nc.d.ts +9 -9
  180. package/xpath/node-tests/node-test-nc.js +16 -16
  181. package/xpath/node-tests/node-test-pi.d.ts +8 -8
  182. package/xpath/node-tests/node-test-pi.js +16 -16
  183. package/xpath/node-tests/node-test-pi.js.map +1 -1
  184. package/xpath/node-tests/node-test-text.d.ts +6 -6
  185. package/xpath/node-tests/node-test-text.js +14 -14
  186. package/xpath/node-tests/node-test.d.ts +5 -5
  187. package/xpath/node-tests/node-test.js +2 -2
  188. package/xpath/tokens.d.ts +62 -62
  189. package/xpath/tokens.js +300 -300
  190. package/xpath/tokens.js.map +1 -1
  191. package/xpath/values/boolean-value.d.ts +11 -11
  192. package/xpath/values/boolean-value.js +23 -23
  193. package/xpath/values/index.d.ts +5 -5
  194. package/xpath/values/index.js +46 -46
  195. package/xpath/values/node-set-value.d.ts +11 -11
  196. package/xpath/values/node-set-value.js +27 -27
  197. package/xpath/values/node-set-value.js.map +1 -1
  198. package/xpath/values/node-value.d.ts +7 -7
  199. package/xpath/values/node-value.js +2 -2
  200. package/xpath/values/number-value.d.ts +11 -11
  201. package/xpath/values/number-value.js +23 -23
  202. package/xpath/values/string-value.d.ts +11 -11
  203. package/xpath/values/string-value.js +23 -23
  204. package/xpath/xpath-grammar-rules.d.ts +68 -68
  205. package/xpath/xpath-grammar-rules.js +74 -74
  206. package/xpath/xpath-token-rule.d.ts +7 -7
  207. package/xpath/xpath-token-rule.js +2 -2
  208. package/xpath/xpath.d.ts +174 -170
  209. package/xpath/xpath.js +911 -909
  210. package/xpath/xpath.js.map +1 -1
  211. package/xpathdebug.d.ts +2 -2
  212. package/xpathdebug.js +187 -187
  213. package/xpathdebug.js.map +1 -1
  214. package/xslt/index.d.ts +3 -3
  215. package/xslt/index.js +19 -19
  216. package/xslt/xslt-decimal-format-settings.d.ts +28 -28
  217. package/xslt/xslt-decimal-format-settings.js +2 -2
  218. package/xslt/xslt-options.d.ts +7 -7
  219. package/xslt/xslt-options.js +2 -2
  220. package/xslt/xslt-parameter.d.ts +5 -5
  221. package/xslt/xslt-parameter.js +2 -2
  222. package/xslt/xslt.d.ts +207 -190
  223. package/xslt/xslt.js +1135 -1079
  224. package/xslt/xslt.js.map +1 -1
@@ -1,371 +1,370 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.xmlOwnerDocument = exports.xmlGetAttribute = exports.xmlEscapeText = exports.xmlTransformedText = exports.xmlText = exports.xmlValue2 = exports.xmlValue = void 0;
7
- var he_1 = __importDefault(require("he"));
8
- var constants_1 = require("../constants");
9
- var functions_1 = require("./functions");
10
- /**
11
- * Returns the text value of a node; for nodes without children this
12
- * is the nodeValue, for nodes with children this is the concatenation
13
- * of the value of all children. Browser-specific optimizations are used by
14
- * default; they can be disabled by passing "true" in as the second parameter.
15
- * @param node The Node (not exactly a `XNode` here).
16
- * @param disallowBrowserSpecificOptimization A boolean, to avoid browser optimization.
17
- * @returns The XML value as a string.
18
- */
19
- function xmlValue(node, disallowBrowserSpecificOptimization) {
20
- if (disallowBrowserSpecificOptimization === void 0) { disallowBrowserSpecificOptimization = false; }
21
- if (!node) {
22
- return '';
23
- }
24
- var ret = '';
25
- switch (node.nodeType) {
26
- case constants_1.DOM_DOCUMENT_TYPE_NODE:
27
- return "<!DOCTYPE ".concat(node.nodeValue, ">");
28
- case constants_1.DOM_TEXT_NODE:
29
- case constants_1.DOM_CDATA_SECTION_NODE:
30
- case constants_1.DOM_ATTRIBUTE_NODE:
31
- return node.nodeValue;
32
- case constants_1.DOM_ELEMENT_NODE:
33
- case constants_1.DOM_DOCUMENT_NODE:
34
- case constants_1.DOM_DOCUMENT_FRAGMENT_NODE:
35
- if (!disallowBrowserSpecificOptimization) {
36
- // Only returns something if node has either `innerText` or `textContent` (not an XNode).
37
- // IE, Safari, Opera, and friends (`innerText`)
38
- var innerText = node.innerText;
39
- if (innerText != undefined) {
40
- return innerText;
41
- }
42
- // Firefox (`textContent`)
43
- var textContent = node.textContent;
44
- if (textContent != undefined) {
45
- return textContent;
46
- }
47
- }
48
- if (node.transformedChildNodes.length > 0) {
49
- var transformedTextNodes = node.transformedChildNodes.filter(function (n) { return n.nodeType !== constants_1.DOM_ATTRIBUTE_NODE; });
50
- for (var i = 0; i < transformedTextNodes.length; ++i) {
51
- ret += xmlValue(transformedTextNodes[i]);
52
- }
53
- }
54
- else {
55
- var textNodes = node.childNodes.filter(function (n) { return n.nodeType !== constants_1.DOM_ATTRIBUTE_NODE; });
56
- for (var i = 0; i < textNodes.length; ++i) {
57
- ret += xmlValue(textNodes[i]);
58
- }
59
- }
60
- return ret;
61
- }
62
- }
63
- exports.xmlValue = xmlValue;
64
- // TODO: Give a better name to this.
65
- function xmlValue2(node, disallowBrowserSpecificOptimization) {
66
- if (disallowBrowserSpecificOptimization === void 0) { disallowBrowserSpecificOptimization = false; }
67
- if (!node) {
68
- return '';
69
- }
70
- var returnedXmlString = '';
71
- switch (node.nodeType) {
72
- case constants_1.DOM_ATTRIBUTE_NODE:
73
- case constants_1.DOM_TEXT_NODE:
74
- returnedXmlString += node.nodeValue;
75
- break;
76
- case constants_1.DOM_CDATA_SECTION_NODE:
77
- returnedXmlString += node.nodeValue;
78
- break;
79
- case constants_1.DOM_DOCUMENT_NODE:
80
- case constants_1.DOM_DOCUMENT_FRAGMENT_NODE:
81
- case constants_1.DOM_ELEMENT_NODE:
82
- if (!disallowBrowserSpecificOptimization) {
83
- // IE, Safari, Opera, and friends
84
- var innerText = node.innerText;
85
- if (innerText != undefined) {
86
- return innerText;
87
- }
88
- // Firefox
89
- var textContent = node.textContent;
90
- if (textContent != undefined) {
91
- return textContent;
92
- }
93
- }
94
- var len = node.transformedChildNodes.length;
95
- for (var i = 0; i < len; ++i) {
96
- returnedXmlString += xmlValue(node.transformedChildNodes[i]);
97
- }
98
- break;
99
- }
100
- return returnedXmlString;
101
- }
102
- exports.xmlValue2 = xmlValue2;
103
- /**
104
- * Returns the representation of a node as XML text.
105
- * In general it is not used by XSLT, that uses `xmlTransformedText` instead.
106
- * @param {XNode} node The starting node.
107
- * @param {XmlOutputOptions} options XML output options.
108
- * @returns The XML string.
109
- * @see xmlTransformedText
110
- */
111
- function xmlText(node, options) {
112
- if (options === void 0) { options = {
113
- cData: true,
114
- escape: true,
115
- selfClosingTags: true,
116
- outputMethod: 'xml'
117
- }; }
118
- var buffer = [];
119
- xmlTextRecursive(node, buffer, options);
120
- return buffer.join('');
121
- }
122
- exports.xmlText = xmlText;
123
- function xmlTextRecursive(node, buffer, options) {
124
- if (node.nodeType == constants_1.DOM_TEXT_NODE) {
125
- buffer.push(xmlEscapeText(node.nodeValue));
126
- }
127
- else if (node.nodeType == constants_1.DOM_CDATA_SECTION_NODE) {
128
- if (options.cData) {
129
- buffer.push(node.nodeValue);
130
- }
131
- else {
132
- buffer.push("<![CDATA[".concat(node.nodeValue, "]]>"));
133
- }
134
- }
135
- else if (node.nodeType == constants_1.DOM_COMMENT_NODE) {
136
- buffer.push("<!--".concat(node.nodeValue, "-->"));
137
- }
138
- else if (node.nodeType == constants_1.DOM_ELEMENT_NODE) {
139
- buffer.push("<".concat(xmlFullNodeName(node)));
140
- for (var i = 0; i < node.childNodes.length; ++i) {
141
- var childNode = node.childNodes[i];
142
- if (!childNode || childNode.nodeType !== constants_1.DOM_ATTRIBUTE_NODE) {
143
- continue;
144
- }
145
- if (childNode.nodeName && childNode.nodeValue) {
146
- buffer.push(" ".concat(xmlFullNodeName(childNode), "=\"").concat(xmlEscapeAttr(childNode.nodeValue), "\""));
147
- }
148
- }
149
- if (node.childNodes.length === 0) {
150
- if (options.selfClosingTags || (options.outputMethod === 'html' && ['hr', 'link'].includes(node.nodeName))) {
151
- buffer.push('/>');
152
- }
153
- else {
154
- buffer.push("></".concat(xmlFullNodeName(node), ">"));
155
- }
156
- }
157
- else {
158
- buffer.push('>');
159
- for (var i = 0; i < node.childNodes.length; ++i) {
160
- xmlTextRecursive(node.childNodes[i], buffer, options);
161
- }
162
- buffer.push("</".concat(xmlFullNodeName(node), ">"));
163
- }
164
- }
165
- else if (node.nodeType == constants_1.DOM_DOCUMENT_NODE || node.nodeType == constants_1.DOM_DOCUMENT_FRAGMENT_NODE) {
166
- for (var i = 0; i < node.childNodes.length; ++i) {
167
- xmlTextRecursive(node.childNodes[i], buffer, options);
168
- }
169
- }
170
- }
171
- /**
172
- * Returns the representation of a node as XML text.
173
- * @param {XNode} node The starting node.
174
- * @param {XmlOutputOptions} options XML output options.
175
- * @returns The XML string.
176
- */
177
- function xmlTransformedText(node, options) {
178
- if (options === void 0) { options = {
179
- cData: true,
180
- escape: true,
181
- selfClosingTags: true,
182
- outputMethod: 'xml'
183
- }; }
184
- var buffer = [];
185
- xmlTransformedTextRecursive(node, buffer, options);
186
- return buffer.join('');
187
- }
188
- exports.xmlTransformedText = xmlTransformedText;
189
- function xmlTransformedTextRecursive(node, buffer, options) {
190
- if (node.visited)
191
- return;
192
- var nodeType = node.transformedNodeType || node.nodeType;
193
- var nodeValue = node.transformedNodeValue || node.nodeValue;
194
- if (nodeType === constants_1.DOM_TEXT_NODE) {
195
- if (node.transformedNodeValue && node.transformedNodeValue.trim() !== '') {
196
- var finalText = node.escape && options.escape ?
197
- xmlEscapeText(node.transformedNodeValue) :
198
- node.transformedNodeValue;
199
- buffer.push(finalText);
200
- }
201
- }
202
- else if (nodeType === constants_1.DOM_CDATA_SECTION_NODE) {
203
- if (options.cData) {
204
- buffer.push(xmlEscapeText(nodeValue));
205
- }
206
- else {
207
- buffer.push("<![CDATA[".concat(nodeValue, "]]>"));
208
- }
209
- }
210
- else if (nodeType == constants_1.DOM_COMMENT_NODE) {
211
- buffer.push("<!-- ".concat(nodeValue, " -->"));
212
- }
213
- else if (nodeType == constants_1.DOM_ELEMENT_NODE) {
214
- // If node didn't have a transformed name, but its children
215
- // had transformations, children should be present at output.
216
- // This is called here "muted logic".
217
- if (node.transformedNodeName !== null && node.transformedNodeName !== undefined) {
218
- xmlElementLogicTrivial(node, buffer, options);
219
- }
220
- else {
221
- xmlElementLogicMuted(node, buffer, options);
222
- }
223
- }
224
- else if (nodeType === constants_1.DOM_DOCUMENT_NODE || nodeType === constants_1.DOM_DOCUMENT_FRAGMENT_NODE) {
225
- var childNodes = node.transformedChildNodes.concat(node.childNodes);
226
- childNodes.sort(function (a, b) { return a.siblingPosition - b.siblingPosition; });
227
- for (var i = 0; i < childNodes.length; ++i) {
228
- xmlTransformedTextRecursive(childNodes[i], buffer, options);
229
- }
230
- }
231
- node.visited = true;
232
- }
233
- /**
234
- * XML element output, trivial logic.
235
- * @param node The XML node.
236
- * @param buffer The XML buffer.
237
- * @param cdata If using CDATA configuration.
238
- */
239
- function xmlElementLogicTrivial(node, buffer, options) {
240
- buffer.push("<".concat(xmlFullNodeName(node)));
241
- var attributes = node.transformedChildNodes.filter(function (n) { return n.nodeType === constants_1.DOM_ATTRIBUTE_NODE; });
242
- if (attributes.length === 0) {
243
- attributes = node.childNodes.filter(function (n) { return n.nodeType === constants_1.DOM_ATTRIBUTE_NODE; });
244
- }
245
- for (var i = 0; i < attributes.length; ++i) {
246
- var attribute = attributes[i];
247
- if (!attribute) {
248
- continue;
249
- }
250
- if (attribute.transformedNodeName && attribute.transformedNodeValue) {
251
- buffer.push(" ".concat(xmlFullNodeName(attribute), "=\"").concat(xmlEscapeAttr(attribute.transformedNodeValue), "\""));
252
- }
253
- }
254
- var childNodes = node.transformedChildNodes.filter(function (n) { return n.nodeType !== constants_1.DOM_ATTRIBUTE_NODE; });
255
- if (childNodes.length === 0) {
256
- childNodes = node.childNodes.filter(function (n) { return n.nodeType !== constants_1.DOM_ATTRIBUTE_NODE; });
257
- }
258
- childNodes = childNodes.sort(function (a, b) { return a.siblingPosition - b.siblingPosition; });
259
- if (childNodes.length === 0) {
260
- if (options.outputMethod === 'html' && ['hr', 'link', 'meta'].includes(node.nodeName)) {
261
- buffer.push('>');
262
- }
263
- else if (options.selfClosingTags) {
264
- buffer.push('/>');
265
- }
266
- else {
267
- buffer.push("></".concat(xmlFullNodeName(node), ">"));
268
- }
269
- }
270
- else {
271
- buffer.push('>');
272
- for (var i = 0; i < childNodes.length; ++i) {
273
- xmlTransformedTextRecursive(childNodes[i], buffer, options);
274
- }
275
- buffer.push("</".concat(xmlFullNodeName(node), ">"));
276
- }
277
- }
278
- /**
279
- * XML element output, muted logic.
280
- * In other words, this element should not be printed, but its
281
- * children can be printed if they have transformed values.
282
- * @param node The XML node.
283
- * @param buffer The XML buffer.
284
- * @param cdata If using CDATA configuration.
285
- */
286
- function xmlElementLogicMuted(node, buffer, options) {
287
- var childNodes = node.transformedChildNodes.length > 0 ? node.transformedChildNodes : node.childNodes;
288
- childNodes = childNodes.sort(function (a, b) { return a.siblingPosition - b.siblingPosition; });
289
- for (var i = 0; i < childNodes.length; ++i) {
290
- xmlTransformedTextRecursive(childNodes[i], buffer, options);
291
- }
292
- }
293
- /**
294
- * Gets the full node name.
295
- * When namespace is set, the node name is `namespace:node`.
296
- * @param node The node.
297
- * @returns The full node name as a string.
298
- */
299
- function xmlFullNodeName(node) {
300
- var nodeName = node.transformedNodeName || node.nodeName;
301
- if (node.transformedPrefix && nodeName.indexOf("".concat(node.transformedPrefix, ":")) != 0) {
302
- return "".concat(node.transformedPrefix, ":").concat(nodeName);
303
- }
304
- return nodeName;
305
- }
306
- /**
307
- * Escape XML special markup chracters: tag delimiter < > and entity
308
- * reference start delimiter &. The escaped string can be used in XML
309
- * text portions (i.e. between tags).
310
- * @param s The string to be escaped.
311
- * @returns The escaped string.
312
- */
313
- function xmlEscapeText(s) {
314
- return "".concat(s)
315
- .replace(/&/g, '&amp;')
316
- .replace(/&amp;amp;/g, '&amp;')
317
- .replace(/</g, '&lt;')
318
- .replace(/>/g, '&gt;');
319
- }
320
- exports.xmlEscapeText = xmlEscapeText;
321
- /**
322
- * Escape XML special markup characters: tag delimiter < > entity
323
- * reference start delimiter & and quotes ". The escaped string can be
324
- * used in double quoted XML attribute value portions (i.e. in
325
- * attributes within start tags).
326
- * @param s The string to be escaped.
327
- * @returns The escaped string.
328
- */
329
- function xmlEscapeAttr(s) {
330
- return xmlEscapeText(s).replace(/"/g, '&quot;');
331
- }
332
- /**
333
- * Wrapper function to access attribute values of template element
334
- * nodes. Currently this calls he.decode because in some DOM
335
- * implementations the return value of node.getAttributeValue()
336
- * contains unresolved XML entities, although the DOM spec requires
337
- * that entity references are resolved by the DOM.
338
- * @param node TODO
339
- * @param name TODO
340
- * @returns TODO
341
- */
342
- function xmlGetAttribute(node, name) {
343
- // TODO(mesch): This should not be necessary if the DOM is working
344
- // correctly. The DOM is responsible for resolving entities, not the
345
- // application.
346
- var value = (0, functions_1.domGetAttributeValue)(node, name);
347
- if (value) {
348
- return he_1.default.decode(value);
349
- }
350
- return value;
351
- }
352
- exports.xmlGetAttribute = xmlGetAttribute;
353
- /**
354
- * Wrapper function to access the owner document uniformly for document
355
- * and other nodes: for the document node, the owner document is the
356
- * node itself, for all others it's the ownerDocument property.
357
- *
358
- * @param {XNode} node
359
- * @return {XDocument}
360
- */
361
- function xmlOwnerDocument(node) {
362
- if (node === null || node === undefined) {
363
- throw new Error('Node has no valid owner document.');
364
- }
365
- if (node.nodeType === constants_1.DOM_DOCUMENT_NODE) {
366
- return node;
367
- }
368
- return xmlOwnerDocument(node.ownerDocument);
369
- }
370
- exports.xmlOwnerDocument = xmlOwnerDocument;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.xmlValue = xmlValue;
7
+ exports.xmlValue2 = xmlValue2;
8
+ exports.xmlText = xmlText;
9
+ exports.xmlTransformedText = xmlTransformedText;
10
+ exports.xmlEscapeText = xmlEscapeText;
11
+ exports.xmlGetAttribute = xmlGetAttribute;
12
+ exports.xmlOwnerDocument = xmlOwnerDocument;
13
+ var he_1 = __importDefault(require("he"));
14
+ var constants_1 = require("../constants");
15
+ var functions_1 = require("./functions");
16
+ /**
17
+ * Returns the text value of a node; for nodes without children this
18
+ * is the nodeValue, for nodes with children this is the concatenation
19
+ * of the value of all children. Browser-specific optimizations are used by
20
+ * default; they can be disabled by passing "true" in as the second parameter.
21
+ * @param node The Node (not exactly a `XNode` here).
22
+ * @param disallowBrowserSpecificOptimization A boolean, to avoid browser optimization.
23
+ * @returns The XML value as a string.
24
+ */
25
+ function xmlValue(node, disallowBrowserSpecificOptimization) {
26
+ if (disallowBrowserSpecificOptimization === void 0) { disallowBrowserSpecificOptimization = false; }
27
+ if (!node) {
28
+ return '';
29
+ }
30
+ var ret = '';
31
+ switch (node.nodeType) {
32
+ case constants_1.DOM_DOCUMENT_TYPE_NODE:
33
+ return "<!DOCTYPE ".concat(node.nodeValue, ">");
34
+ case constants_1.DOM_TEXT_NODE:
35
+ case constants_1.DOM_CDATA_SECTION_NODE:
36
+ case constants_1.DOM_ATTRIBUTE_NODE:
37
+ return node.nodeValue;
38
+ case constants_1.DOM_ELEMENT_NODE:
39
+ case constants_1.DOM_DOCUMENT_NODE:
40
+ case constants_1.DOM_DOCUMENT_FRAGMENT_NODE:
41
+ if (!disallowBrowserSpecificOptimization) {
42
+ // Only returns something if node has either `innerText` or `textContent` (not an XNode).
43
+ // IE, Safari, Opera, and friends (`innerText`)
44
+ var innerText = node.innerText;
45
+ if (innerText != undefined) {
46
+ return innerText;
47
+ }
48
+ // Firefox (`textContent`)
49
+ var textContent = node.textContent;
50
+ if (textContent != undefined) {
51
+ return textContent;
52
+ }
53
+ }
54
+ if (node.transformedChildNodes.length > 0) {
55
+ var transformedTextNodes = node.transformedChildNodes.filter(function (n) { return n.nodeType !== constants_1.DOM_ATTRIBUTE_NODE; });
56
+ for (var i = 0; i < transformedTextNodes.length; ++i) {
57
+ ret += xmlValue(transformedTextNodes[i]);
58
+ }
59
+ }
60
+ else {
61
+ var textNodes = node.childNodes.filter(function (n) { return n.nodeType !== constants_1.DOM_ATTRIBUTE_NODE; });
62
+ for (var i = 0; i < textNodes.length; ++i) {
63
+ ret += xmlValue(textNodes[i]);
64
+ }
65
+ }
66
+ return ret;
67
+ }
68
+ }
69
+ // TODO: Give a better name to this.
70
+ function xmlValue2(node, disallowBrowserSpecificOptimization) {
71
+ if (disallowBrowserSpecificOptimization === void 0) { disallowBrowserSpecificOptimization = false; }
72
+ if (!node) {
73
+ return '';
74
+ }
75
+ var returnedXmlString = '';
76
+ switch (node.nodeType) {
77
+ case constants_1.DOM_ATTRIBUTE_NODE:
78
+ case constants_1.DOM_TEXT_NODE:
79
+ returnedXmlString += node.nodeValue;
80
+ break;
81
+ case constants_1.DOM_CDATA_SECTION_NODE:
82
+ returnedXmlString += node.nodeValue;
83
+ break;
84
+ case constants_1.DOM_DOCUMENT_NODE:
85
+ case constants_1.DOM_DOCUMENT_FRAGMENT_NODE:
86
+ case constants_1.DOM_ELEMENT_NODE:
87
+ if (!disallowBrowserSpecificOptimization) {
88
+ // IE, Safari, Opera, and friends
89
+ var innerText = node.innerText;
90
+ if (innerText != undefined) {
91
+ return innerText;
92
+ }
93
+ // Firefox
94
+ var textContent = node.textContent;
95
+ if (textContent != undefined) {
96
+ return textContent;
97
+ }
98
+ }
99
+ var len = node.transformedChildNodes.length;
100
+ for (var i = 0; i < len; ++i) {
101
+ returnedXmlString += xmlValue(node.transformedChildNodes[i]);
102
+ }
103
+ break;
104
+ }
105
+ return returnedXmlString;
106
+ }
107
+ /**
108
+ * Returns the representation of a node as XML text.
109
+ * In general it is not used by XSLT, that uses `xmlTransformedText` instead.
110
+ * @param {XNode} node The starting node.
111
+ * @param {XmlOutputOptions} options XML output options.
112
+ * @returns The XML string.
113
+ * @see xmlTransformedText
114
+ */
115
+ function xmlText(node, options) {
116
+ if (options === void 0) { options = {
117
+ cData: true,
118
+ escape: true,
119
+ selfClosingTags: true,
120
+ outputMethod: 'xml'
121
+ }; }
122
+ var buffer = [];
123
+ xmlTextRecursive(node, buffer, options);
124
+ return buffer.join('');
125
+ }
126
+ function xmlTextRecursive(node, buffer, options) {
127
+ if (node.nodeType == constants_1.DOM_TEXT_NODE) {
128
+ buffer.push(xmlEscapeText(node.nodeValue));
129
+ }
130
+ else if (node.nodeType == constants_1.DOM_CDATA_SECTION_NODE) {
131
+ if (options.cData) {
132
+ buffer.push(node.nodeValue);
133
+ }
134
+ else {
135
+ buffer.push("<![CDATA[".concat(node.nodeValue, "]]>"));
136
+ }
137
+ }
138
+ else if (node.nodeType == constants_1.DOM_COMMENT_NODE) {
139
+ buffer.push("<!--".concat(node.nodeValue, "-->"));
140
+ }
141
+ else if (node.nodeType == constants_1.DOM_ELEMENT_NODE) {
142
+ buffer.push("<".concat(xmlFullNodeName(node)));
143
+ for (var i = 0; i < node.childNodes.length; ++i) {
144
+ var childNode = node.childNodes[i];
145
+ if (!childNode || childNode.nodeType !== constants_1.DOM_ATTRIBUTE_NODE) {
146
+ continue;
147
+ }
148
+ if (childNode.nodeName && childNode.nodeValue) {
149
+ buffer.push(" ".concat(xmlFullNodeName(childNode), "=\"").concat(xmlEscapeAttr(childNode.nodeValue), "\""));
150
+ }
151
+ }
152
+ if (node.childNodes.length === 0) {
153
+ if (options.selfClosingTags || (options.outputMethod === 'html' && ['hr', 'link'].includes(node.nodeName))) {
154
+ buffer.push('/>');
155
+ }
156
+ else {
157
+ buffer.push("></".concat(xmlFullNodeName(node), ">"));
158
+ }
159
+ }
160
+ else {
161
+ buffer.push('>');
162
+ for (var i = 0; i < node.childNodes.length; ++i) {
163
+ xmlTextRecursive(node.childNodes[i], buffer, options);
164
+ }
165
+ buffer.push("</".concat(xmlFullNodeName(node), ">"));
166
+ }
167
+ }
168
+ else if (node.nodeType == constants_1.DOM_DOCUMENT_NODE || node.nodeType == constants_1.DOM_DOCUMENT_FRAGMENT_NODE) {
169
+ for (var i = 0; i < node.childNodes.length; ++i) {
170
+ xmlTextRecursive(node.childNodes[i], buffer, options);
171
+ }
172
+ }
173
+ }
174
+ /**
175
+ * Returns the representation of a node as XML text.
176
+ * @param {XNode} node The starting node.
177
+ * @param {XmlOutputOptions} options XML output options.
178
+ * @returns The XML string.
179
+ */
180
+ function xmlTransformedText(node, options) {
181
+ if (options === void 0) { options = {
182
+ cData: true,
183
+ escape: true,
184
+ selfClosingTags: true,
185
+ outputMethod: 'xml'
186
+ }; }
187
+ var buffer = [];
188
+ xmlTransformedTextRecursive(node, buffer, options);
189
+ return buffer.join('');
190
+ }
191
+ function xmlTransformedTextRecursive(node, buffer, options) {
192
+ if (node.visited)
193
+ return;
194
+ var nodeType = node.transformedNodeType || node.nodeType;
195
+ var nodeValue = node.transformedNodeValue || node.nodeValue;
196
+ if (nodeType === constants_1.DOM_TEXT_NODE) {
197
+ if (node.transformedNodeValue && node.transformedNodeValue.trim() !== '') {
198
+ var finalText = node.escape && options.escape ?
199
+ xmlEscapeText(node.transformedNodeValue) :
200
+ node.transformedNodeValue;
201
+ buffer.push(finalText);
202
+ }
203
+ }
204
+ else if (nodeType === constants_1.DOM_CDATA_SECTION_NODE) {
205
+ if (options.cData) {
206
+ buffer.push(xmlEscapeText(nodeValue));
207
+ }
208
+ else {
209
+ buffer.push("<![CDATA[".concat(nodeValue, "]]>"));
210
+ }
211
+ }
212
+ else if (nodeType == constants_1.DOM_COMMENT_NODE) {
213
+ buffer.push("<!-- ".concat(nodeValue, " -->"));
214
+ }
215
+ else if (nodeType == constants_1.DOM_ELEMENT_NODE) {
216
+ // If node didn't have a transformed name, but its children
217
+ // had transformations, children should be present at output.
218
+ // This is called here "muted logic".
219
+ if (node.transformedNodeName !== null && node.transformedNodeName !== undefined) {
220
+ xmlElementLogicTrivial(node, buffer, options);
221
+ }
222
+ else {
223
+ xmlElementLogicMuted(node, buffer, options);
224
+ }
225
+ }
226
+ else if (nodeType === constants_1.DOM_DOCUMENT_NODE || nodeType === constants_1.DOM_DOCUMENT_FRAGMENT_NODE) {
227
+ var childNodes = node.transformedChildNodes.concat(node.childNodes);
228
+ childNodes.sort(function (a, b) { return a.siblingPosition - b.siblingPosition; });
229
+ for (var i = 0; i < childNodes.length; ++i) {
230
+ xmlTransformedTextRecursive(childNodes[i], buffer, options);
231
+ }
232
+ }
233
+ node.visited = true;
234
+ }
235
+ /**
236
+ * XML element output, trivial logic.
237
+ * @param node The XML node.
238
+ * @param buffer The XML buffer.
239
+ * @param cdata If using CDATA configuration.
240
+ */
241
+ function xmlElementLogicTrivial(node, buffer, options) {
242
+ buffer.push("<".concat(xmlFullNodeName(node)));
243
+ var attributes = node.transformedChildNodes.filter(function (n) { return n.nodeType === constants_1.DOM_ATTRIBUTE_NODE; });
244
+ if (attributes.length === 0) {
245
+ attributes = node.childNodes.filter(function (n) { return n.nodeType === constants_1.DOM_ATTRIBUTE_NODE; });
246
+ }
247
+ for (var i = 0; i < attributes.length; ++i) {
248
+ var attribute = attributes[i];
249
+ if (!attribute) {
250
+ continue;
251
+ }
252
+ if (attribute.transformedNodeName && attribute.transformedNodeValue) {
253
+ buffer.push(" ".concat(xmlFullNodeName(attribute), "=\"").concat(xmlEscapeAttr(attribute.transformedNodeValue), "\""));
254
+ }
255
+ }
256
+ var childNodes = node.transformedChildNodes.filter(function (n) { return n.nodeType !== constants_1.DOM_ATTRIBUTE_NODE; });
257
+ if (childNodes.length === 0) {
258
+ childNodes = node.childNodes.filter(function (n) { return n.nodeType !== constants_1.DOM_ATTRIBUTE_NODE; });
259
+ }
260
+ childNodes = childNodes.sort(function (a, b) { return a.siblingPosition - b.siblingPosition; });
261
+ if (childNodes.length === 0) {
262
+ if (options.outputMethod === 'html' && ['hr', 'link', 'meta'].includes(node.nodeName)) {
263
+ buffer.push('>');
264
+ }
265
+ else if (options.selfClosingTags) {
266
+ buffer.push('/>');
267
+ }
268
+ else {
269
+ buffer.push("></".concat(xmlFullNodeName(node), ">"));
270
+ }
271
+ }
272
+ else {
273
+ buffer.push('>');
274
+ for (var i = 0; i < childNodes.length; ++i) {
275
+ xmlTransformedTextRecursive(childNodes[i], buffer, options);
276
+ }
277
+ buffer.push("</".concat(xmlFullNodeName(node), ">"));
278
+ }
279
+ }
280
+ /**
281
+ * XML element output, muted logic.
282
+ * In other words, this element should not be printed, but its
283
+ * children can be printed if they have transformed values.
284
+ * @param node The XML node.
285
+ * @param buffer The XML buffer.
286
+ * @param cdata If using CDATA configuration.
287
+ */
288
+ function xmlElementLogicMuted(node, buffer, options) {
289
+ var childNodes = node.transformedChildNodes.length > 0 ? node.transformedChildNodes : node.childNodes;
290
+ childNodes = childNodes.sort(function (a, b) { return a.siblingPosition - b.siblingPosition; });
291
+ for (var i = 0; i < childNodes.length; ++i) {
292
+ xmlTransformedTextRecursive(childNodes[i], buffer, options);
293
+ }
294
+ }
295
+ /**
296
+ * Gets the full node name.
297
+ * When namespace is set, the node name is `namespace:node`.
298
+ * @param node The node.
299
+ * @returns The full node name as a string.
300
+ */
301
+ function xmlFullNodeName(node) {
302
+ var nodeName = node.transformedNodeName || node.nodeName;
303
+ if (node.transformedPrefix && nodeName.indexOf("".concat(node.transformedPrefix, ":")) != 0) {
304
+ return "".concat(node.transformedPrefix, ":").concat(nodeName);
305
+ }
306
+ return nodeName;
307
+ }
308
+ /**
309
+ * Escape XML special markup chracters: tag delimiter < > and entity
310
+ * reference start delimiter &. The escaped string can be used in XML
311
+ * text portions (i.e. between tags).
312
+ * @param s The string to be escaped.
313
+ * @returns The escaped string.
314
+ */
315
+ function xmlEscapeText(s) {
316
+ return "".concat(s)
317
+ .replace(/&/g, '&amp;')
318
+ .replace(/&amp;amp;/g, '&amp;')
319
+ .replace(/</g, '&lt;')
320
+ .replace(/>/g, '&gt;');
321
+ }
322
+ /**
323
+ * Escape XML special markup characters: tag delimiter < > entity
324
+ * reference start delimiter & and quotes ". The escaped string can be
325
+ * used in double quoted XML attribute value portions (i.e. in
326
+ * attributes within start tags).
327
+ * @param s The string to be escaped.
328
+ * @returns The escaped string.
329
+ */
330
+ function xmlEscapeAttr(s) {
331
+ return xmlEscapeText(s).replace(/"/g, '&quot;');
332
+ }
333
+ /**
334
+ * Wrapper function to access attribute values of template element
335
+ * nodes. Currently this calls he.decode because in some DOM
336
+ * implementations the return value of node.getAttributeValue()
337
+ * contains unresolved XML entities, although the DOM spec requires
338
+ * that entity references are resolved by the DOM.
339
+ * @param node TODO
340
+ * @param name TODO
341
+ * @returns TODO
342
+ */
343
+ function xmlGetAttribute(node, name) {
344
+ // TODO(mesch): This should not be necessary if the DOM is working
345
+ // correctly. The DOM is responsible for resolving entities, not the
346
+ // application.
347
+ var value = (0, functions_1.domGetAttributeValue)(node, name);
348
+ if (value) {
349
+ return he_1.default.decode(value);
350
+ }
351
+ return value;
352
+ }
353
+ /**
354
+ * Wrapper function to access the owner document uniformly for document
355
+ * and other nodes: for the document node, the owner document is the
356
+ * node itself, for all others it's the ownerDocument property.
357
+ *
358
+ * @param {XNode} node
359
+ * @return {XDocument}
360
+ */
361
+ function xmlOwnerDocument(node) {
362
+ if (node === null || node === undefined) {
363
+ throw new Error('Node has no valid owner document.');
364
+ }
365
+ if (node.nodeType === constants_1.DOM_DOCUMENT_NODE) {
366
+ return node;
367
+ }
368
+ return xmlOwnerDocument(node.ownerDocument);
369
+ }
371
370
  //# sourceMappingURL=xml-functions.js.map