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
package/xslt/xslt.js CHANGED
@@ -1,1080 +1,1136 @@
1
- "use strict";
2
- // Copyright 2023-2024 Design Liquido
3
- // Copyright 2018 Johannes Wilm
4
- // Copyright 2005 Google Inc.
5
- // All Rights Reserved
6
- //
7
- // TODO(mesch): add jsdoc comments. Use more coherent naming. Finish
8
- // remaining XSLT features.
9
- //
10
- // Original author: Steffen Meschkat <mesch@google.com>
11
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
12
- if (k2 === undefined) k2 = k;
13
- var desc = Object.getOwnPropertyDescriptor(m, k);
14
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
15
- desc = { enumerable: true, get: function() { return m[k]; } };
16
- }
17
- Object.defineProperty(o, k2, desc);
18
- }) : (function(o, m, k, k2) {
19
- if (k2 === undefined) k2 = k;
20
- o[k2] = m[k];
21
- }));
22
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
23
- Object.defineProperty(o, "default", { enumerable: true, value: v });
24
- }) : function(o, v) {
25
- o["default"] = v;
26
- });
27
- var __importStar = (this && this.__importStar) || function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
35
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
36
- return new (P || (P = Promise))(function (resolve, reject) {
37
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
38
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
39
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
40
- step((generator = generator.apply(thisArg, _arguments || [])).next());
41
- });
42
- };
43
- var __generator = (this && this.__generator) || function (thisArg, body) {
44
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
45
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
46
- function verb(n) { return function (v) { return step([n, v]); }; }
47
- function step(op) {
48
- if (f) throw new TypeError("Generator is already executing.");
49
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
50
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
51
- if (y = 0, t) op = [op[0] & 2, t.value];
52
- switch (op[0]) {
53
- case 0: case 1: t = op; break;
54
- case 4: _.label++; return { value: op[1], done: false };
55
- case 5: _.label++; y = op[1]; op = [0]; continue;
56
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
57
- default:
58
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
59
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
60
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
61
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
62
- if (t[2]) _.ops.pop();
63
- _.trys.pop(); continue;
64
- }
65
- op = body.call(thisArg, _);
66
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
67
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
68
- }
69
- };
70
- Object.defineProperty(exports, "__esModule", { value: true });
71
- exports.Xslt = void 0;
72
- var node_fetch_1 = __importStar(require("node-fetch"));
73
- var dom_1 = require("../dom");
74
- var xpath_1 = require("../xpath");
75
- var constants_1 = require("../constants");
76
- var values_1 = require("../xpath/values");
77
- var match_resolver_1 = require("../xpath/match-resolver");
78
- /**
79
- * The main class for XSL-T processing. The implementation is NOT
80
- * complete; some xsl element are left out.
81
- *
82
- * References:
83
- *
84
- * [XSLT] XSL-T Specification
85
- * <http://www.w3.org/TR/1999/REC-xslt-19991116>.
86
- *
87
- * [ECMA] ECMAScript Language Specification
88
- * <http://www.ecma-international.org/publications/standards/Ecma-262.htm>.
89
- *
90
- * The XSL processor API has one entry point, the function
91
- * xsltProcessContext(). It receives as arguments the starting point in the
92
- * input document as an XPath expression context, the DOM root node of
93
- * the XSL-T stylesheet, and a DOM node that receives the output.
94
- *
95
- * NOTE: Actually, XSL-T processing according to the specification is
96
- * defined as operation on text documents, not as operation on DOM
97
- * trees. So, strictly speaking, this implementation is not an XSL-T
98
- * processor, but the processing engine that needs to be complemented
99
- * by an XML parser and serializer in order to be complete. Those two
100
- * are found in the `dom` folder.
101
- */
102
- var Xslt = /** @class */ (function () {
103
- function Xslt(options) {
104
- if (options === void 0) { options = {
105
- cData: true,
106
- escape: true,
107
- selfClosingTags: true,
108
- parameters: []
109
- }; }
110
- this.xPath = new xpath_1.XPath();
111
- this.xmlParser = new dom_1.XmlParser();
112
- this.matchResolver = new match_resolver_1.MatchResolver();
113
- this.options = {
114
- cData: options.cData === true,
115
- escape: options.escape === true,
116
- selfClosingTags: options.selfClosingTags === true,
117
- parameters: options.parameters || []
118
- };
119
- this.outputMethod = 'xml';
120
- this.outputOmitXmlDeclaration = 'no';
121
- this.decimalFormatSettings = {
122
- decimalSeparator: '.',
123
- groupingSeparator: ',',
124
- infinity: 'Infinity',
125
- minusSign: '-',
126
- naN: 'NaN',
127
- percent: '%',
128
- perMille: '‰',
129
- zeroDigit: '0',
130
- digit: '#',
131
- patternSeparator: ';'
132
- };
133
- }
134
- /**
135
- * The exported entry point of the XSL-T processor.
136
- * @param xmlDoc The input document root, as DOM node.
137
- * @param stylesheet The stylesheet document root, as DOM node.
138
- * @returns the processed document, as XML text in a string.
139
- */
140
- Xslt.prototype.xsltProcess = function (xmlDoc, stylesheet) {
141
- return __awaiter(this, void 0, void 0, function () {
142
- var outputDocument, expressionContext, _i, _a, parameter, transformedOutputXml;
143
- return __generator(this, function (_b) {
144
- switch (_b.label) {
145
- case 0:
146
- outputDocument = new dom_1.XDocument();
147
- this.outputDocument = outputDocument;
148
- expressionContext = new xpath_1.ExprContext([xmlDoc], [outputDocument]);
149
- if (this.options.parameters.length > 0) {
150
- for (_i = 0, _a = this.options.parameters; _i < _a.length; _i++) {
151
- parameter = _a[_i];
152
- expressionContext.setVariable(parameter.name, new values_1.StringValue(parameter.value));
153
- }
154
- }
155
- return [4 /*yield*/, this.xsltProcessContext(expressionContext, stylesheet, this.outputDocument)];
156
- case 1:
157
- _b.sent();
158
- transformedOutputXml = (0, dom_1.xmlTransformedText)(outputDocument, {
159
- cData: this.options.cData,
160
- escape: this.options.escape,
161
- selfClosingTags: this.options.selfClosingTags,
162
- outputMethod: this.outputMethod
163
- });
164
- return [2 /*return*/, transformedOutputXml];
165
- }
166
- });
167
- });
168
- };
169
- /**
170
- * The main entry point of the XSL-T processor, as explained on the top of the file.
171
- * @param context The input document root, as XPath `ExprContext`.
172
- * @param template The stylesheet document root, as DOM node.
173
- * @param output If set, the output where the transformation should occur.
174
- */
175
- Xslt.prototype.xsltProcessContext = function (context, template, output) {
176
- return __awaiter(this, void 0, void 0, function () {
177
- var name_1, top_1, nameExpr, node, select, value, nodes, mode, templates, paramContext, commentData, commentNode, test_1, match, text, _a, _i, _b, element, templateAncestor, modifiedContext, i, j, textNodeContext, clonedContext_1, documentFragment, sourceNode, parentSourceNode, outputNode, sourceRootNode, newRootNode, i, childNode, destinationCopyNode, destinationNode, i, node_1, decimalSeparator, groupingSeparator, infinity, minusSign, naN, percent, perMille, zeroDigit, digit, patternSeparator, clonedContext, templateContext, disableOutputEscaping, destinationTextNode, attribute;
178
- var _this = this;
179
- return __generator(this, function (_c) {
180
- switch (_c.label) {
181
- case 0:
182
- if (!!this.isXsltElement(template)) return [3 /*break*/, 2];
183
- return [4 /*yield*/, this.xsltPassThrough(context, template, output)];
184
- case 1:
185
- _c.sent();
186
- return [3 /*break*/, 65];
187
- case 2:
188
- nameExpr = void 0, node = void 0, select = void 0, value = void 0, nodes = void 0, mode = void 0, templates = void 0, paramContext = void 0, commentData = void 0, commentNode = void 0, match = void 0, text = void 0;
189
- _a = template.localName;
190
- switch (_a) {
191
- case 'apply-imports': return [3 /*break*/, 3];
192
- case 'apply-templates': return [3 /*break*/, 4];
193
- case 'attribute': return [3 /*break*/, 12];
194
- case 'attribute-set': return [3 /*break*/, 14];
195
- case 'call-template': return [3 /*break*/, 15];
196
- case 'choose': return [3 /*break*/, 21];
197
- case 'comment': return [3 /*break*/, 23];
198
- case 'copy': return [3 /*break*/, 25];
199
- case 'copy-of': return [3 /*break*/, 28];
200
- case 'decimal-format': return [3 /*break*/, 29];
201
- case 'element': return [3 /*break*/, 30];
202
- case 'fallback': return [3 /*break*/, 32];
203
- case 'for-each': return [3 /*break*/, 33];
204
- case 'if': return [3 /*break*/, 35];
205
- case 'import': return [3 /*break*/, 38];
206
- case 'include': return [3 /*break*/, 39];
207
- case 'key': return [3 /*break*/, 41];
208
- case 'message': return [3 /*break*/, 42];
209
- case 'namespace-alias': return [3 /*break*/, 43];
210
- case 'number': return [3 /*break*/, 44];
211
- case 'otherwise': return [3 /*break*/, 45];
212
- case 'output': return [3 /*break*/, 46];
213
- case 'param': return [3 /*break*/, 47];
214
- case 'preserve-space': return [3 /*break*/, 49];
215
- case 'processing-instruction': return [3 /*break*/, 50];
216
- case 'sort': return [3 /*break*/, 51];
217
- case 'strip-space': return [3 /*break*/, 52];
218
- case 'stylesheet': return [3 /*break*/, 53];
219
- case 'transform': return [3 /*break*/, 53];
220
- case 'template': return [3 /*break*/, 55];
221
- case 'text': return [3 /*break*/, 58];
222
- case 'value-of': return [3 /*break*/, 59];
223
- case 'variable': return [3 /*break*/, 60];
224
- case 'when': return [3 /*break*/, 62];
225
- case 'with-param': return [3 /*break*/, 63];
226
- }
227
- return [3 /*break*/, 64];
228
- case 3: throw new Error("not implemented: ".concat(template.localName));
229
- case 4:
230
- select = (0, dom_1.xmlGetAttribute)(template, 'select');
231
- if (select) {
232
- nodes = this.xPath.xPathEval(select, context).nodeSetValue();
233
- }
234
- else {
235
- nodes = context.nodeList[context.position].childNodes;
236
- }
237
- // TODO: Check why apply-templates was sorting and filing parameters
238
- // automatically.
239
- /* this.xsltWithParam(sortContext, template);
240
- this.xsltSort(sortContext, template); */
241
- mode = (0, dom_1.xmlGetAttribute)(template, 'mode');
242
- top_1 = template.ownerDocument.documentElement;
243
- templates = [];
244
- for (_i = 0, _b = top_1.childNodes.filter(function (c) { return c.nodeType == constants_1.DOM_ELEMENT_NODE && _this.isXsltElement(c, 'template'); }); _i < _b.length; _i++) {
245
- element = _b[_i];
246
- templateAncestor = template.getAncestorByLocalName('template');
247
- if (templateAncestor === undefined) {
248
- continue;
249
- }
250
- if (templateAncestor.id === element.id) {
251
- continue;
252
- }
253
- if (!mode || element.getAttributeValue('mode') === mode) {
254
- templates.push(element);
255
- }
256
- }
257
- modifiedContext = context.clone(nodes);
258
- i = 0;
259
- _c.label = 5;
260
- case 5:
261
- if (!(i < templates.length)) return [3 /*break*/, 11];
262
- j = 0;
263
- _c.label = 6;
264
- case 6:
265
- if (!(j < modifiedContext.contextSize())) return [3 /*break*/, 10];
266
- if (!(modifiedContext.nodeList[j].nodeType === constants_1.DOM_TEXT_NODE)) return [3 /*break*/, 7];
267
- textNodeContext = context.clone([modifiedContext.nodeList[j]], undefined, 0, undefined);
268
- // TODO: verify if it is okay to pass the own text node as template.
269
- this.commonLogicTextNode(textNodeContext, modifiedContext.nodeList[j], output);
270
- return [3 /*break*/, 9];
271
- case 7:
272
- clonedContext_1 = modifiedContext.clone([modifiedContext.nodeList[j]], undefined, 0, undefined);
273
- clonedContext_1.inApplyTemplates = true;
274
- // The output depth should be restarted, since
275
- // another template is being applied from this point.
276
- clonedContext_1.outputDepth = 0;
277
- return [4 /*yield*/, this.xsltProcessContext(clonedContext_1, templates[i], output)];
278
- case 8:
279
- _c.sent();
280
- _c.label = 9;
281
- case 9:
282
- ++j;
283
- return [3 /*break*/, 6];
284
- case 10:
285
- ++i;
286
- return [3 /*break*/, 5];
287
- case 11: return [3 /*break*/, 65];
288
- case 12:
289
- nameExpr = (0, dom_1.xmlGetAttribute)(template, 'name');
290
- name_1 = this.xsltAttributeValue(nameExpr, context);
291
- documentFragment = (0, dom_1.domCreateDocumentFragment)(this.outputDocument);
292
- return [4 /*yield*/, this.xsltChildNodes(context, template, documentFragment)];
293
- case 13:
294
- _c.sent();
295
- value = (0, dom_1.xmlValue2)(documentFragment);
296
- if (output.nodeType === constants_1.DOM_DOCUMENT_FRAGMENT_NODE) {
297
- (0, dom_1.domSetTransformedAttribute)(output, name_1, value);
298
- }
299
- else {
300
- sourceNode = context.nodeList[context.position];
301
- parentSourceNode = sourceNode.parentNode;
302
- outputNode = sourceNode.outputNode;
303
- // At this point, the output node should exist.
304
- // If not, a new node is created.
305
- if (outputNode === null || outputNode === undefined) {
306
- outputNode = new dom_1.XNode(sourceNode.nodeType, sourceNode.nodeName, sourceNode.nodeValue, context.outputNodeList[context.outputPosition], sourceNode.namespaceUri);
307
- sourceNode.outputNode = outputNode;
308
- }
309
- // Corner case:
310
- // It can happen here that we don't have the root node set.
311
- // In this case we need to append a copy of the root
312
- // source node to receive the attribute.
313
- if (outputNode.localName === '#document') {
314
- sourceRootNode = context.root.childNodes[0];
315
- newRootNode = (0, dom_1.domCreateElement)(this.outputDocument, sourceRootNode.nodeName);
316
- newRootNode.transformedNodeName = sourceRootNode.nodeName;
317
- newRootNode.transformedLocalName = sourceRootNode.localName;
318
- (0, dom_1.domAppendTransformedChild)(outputNode, newRootNode);
319
- outputNode = newRootNode;
320
- parentSourceNode = newRootNode;
321
- }
322
- // If the parent transformation is something like `xsl:element`, we should
323
- // add a copy of the attribute to this element.
324
- (0, dom_1.domSetTransformedAttribute)(output, name_1, value);
325
- // Some operations start by the tag attributes, and not by the tag itself.
326
- // When this is the case, the output node is not set yet, so
327
- // we add the transformed attributes into the original tag.
328
- if (parentSourceNode && parentSourceNode.outputNode) {
329
- (0, dom_1.domSetTransformedAttribute)(parentSourceNode.outputNode, name_1, value);
330
- }
331
- else {
332
- (0, dom_1.domSetTransformedAttribute)(parentSourceNode, name_1, value);
333
- }
334
- }
335
- return [3 /*break*/, 65];
336
- case 14: throw new Error("not implemented: ".concat(template.localName));
337
- case 15:
338
- name_1 = (0, dom_1.xmlGetAttribute)(template, 'name');
339
- top_1 = template.ownerDocument.documentElement;
340
- paramContext = context.clone();
341
- return [4 /*yield*/, this.xsltWithParam(paramContext, template)];
342
- case 16:
343
- _c.sent();
344
- i = 0;
345
- _c.label = 17;
346
- case 17:
347
- if (!(i < top_1.childNodes.length)) return [3 /*break*/, 20];
348
- childNode = top_1.childNodes[i];
349
- if (!(childNode.nodeType === constants_1.DOM_ELEMENT_NODE &&
350
- this.isXsltElement(childNode, 'template') &&
351
- (0, dom_1.domGetAttributeValue)(childNode, 'name') == name_1)) return [3 /*break*/, 19];
352
- return [4 /*yield*/, this.xsltChildNodes(paramContext, childNode, output)];
353
- case 18:
354
- _c.sent();
355
- return [3 /*break*/, 20];
356
- case 19:
357
- ++i;
358
- return [3 /*break*/, 17];
359
- case 20: return [3 /*break*/, 65];
360
- case 21: return [4 /*yield*/, this.xsltChoose(context, template, output)];
361
- case 22:
362
- _c.sent();
363
- return [3 /*break*/, 65];
364
- case 23:
365
- node = (0, dom_1.domCreateDocumentFragment)(this.outputDocument);
366
- return [4 /*yield*/, this.xsltChildNodes(context, template, node)];
367
- case 24:
368
- _c.sent();
369
- commentData = (0, dom_1.xmlValue)(node);
370
- commentNode = (0, dom_1.domCreateComment)(this.outputDocument, commentData);
371
- output.appendChild(commentNode);
372
- return [3 /*break*/, 65];
373
- case 25:
374
- destinationCopyNode = output || context.outputNodeList[context.outputPosition];
375
- node = this.xsltCopy(destinationCopyNode, context.nodeList[context.position]);
376
- if (!node) return [3 /*break*/, 27];
377
- return [4 /*yield*/, this.xsltChildNodes(context, template, node)];
378
- case 26:
379
- _c.sent();
380
- _c.label = 27;
381
- case 27: return [3 /*break*/, 65];
382
- case 28:
383
- select = (0, dom_1.xmlGetAttribute)(template, 'select');
384
- value = this.xPath.xPathEval(select, context);
385
- destinationNode = context.outputNodeList[context.outputPosition] || output;
386
- if (value.type === 'node-set') {
387
- nodes = value.nodeSetValue();
388
- for (i = 0; i < nodes.length; ++i) {
389
- this.xsltCopyOf(destinationNode, nodes[i]);
390
- }
391
- }
392
- else {
393
- node_1 = (0, dom_1.domCreateTextNode)(this.outputDocument, value.stringValue());
394
- (0, dom_1.domAppendChild)(destinationNode, node_1);
395
- }
396
- return [3 /*break*/, 65];
397
- case 29:
398
- name_1 = (0, dom_1.xmlGetAttribute)(template, 'name');
399
- decimalSeparator = (0, dom_1.xmlGetAttribute)(template, 'decimal-separator');
400
- groupingSeparator = (0, dom_1.xmlGetAttribute)(template, 'grouping-separator');
401
- infinity = (0, dom_1.xmlGetAttribute)(template, 'infinity');
402
- minusSign = (0, dom_1.xmlGetAttribute)(template, 'minus-sign');
403
- naN = (0, dom_1.xmlGetAttribute)(template, 'NaN');
404
- percent = (0, dom_1.xmlGetAttribute)(template, 'percent');
405
- perMille = (0, dom_1.xmlGetAttribute)(template, 'per-mille');
406
- zeroDigit = (0, dom_1.xmlGetAttribute)(template, 'zero-digit');
407
- digit = (0, dom_1.xmlGetAttribute)(template, 'digit');
408
- patternSeparator = (0, dom_1.xmlGetAttribute)(template, 'pattern-separator');
409
- this.decimalFormatSettings = {
410
- name: name_1 || this.decimalFormatSettings.name,
411
- decimalSeparator: decimalSeparator || this.decimalFormatSettings.decimalSeparator,
412
- groupingSeparator: groupingSeparator || this.decimalFormatSettings.groupingSeparator,
413
- infinity: infinity || this.decimalFormatSettings.infinity,
414
- minusSign: minusSign || this.decimalFormatSettings.minusSign,
415
- naN: naN || this.decimalFormatSettings.naN,
416
- percent: percent || this.decimalFormatSettings.percent,
417
- perMille: perMille || this.decimalFormatSettings.perMille,
418
- zeroDigit: zeroDigit || this.decimalFormatSettings.zeroDigit,
419
- digit: digit || this.decimalFormatSettings.digit,
420
- patternSeparator: patternSeparator || this.decimalFormatSettings.patternSeparator
421
- };
422
- context.decimalFormatSettings = this.decimalFormatSettings;
423
- return [3 /*break*/, 65];
424
- case 30:
425
- nameExpr = (0, dom_1.xmlGetAttribute)(template, 'name');
426
- name_1 = this.xsltAttributeValue(nameExpr, context);
427
- node = (0, dom_1.domCreateElement)(this.outputDocument, name_1);
428
- node.transformedNodeName = name_1;
429
- (0, dom_1.domAppendTransformedChild)(context.outputNodeList[context.outputPosition], node);
430
- clonedContext = context.clone(undefined, [node], undefined, 0);
431
- return [4 /*yield*/, this.xsltChildNodes(clonedContext, template, node)];
432
- case 31:
433
- _c.sent();
434
- return [3 /*break*/, 65];
435
- case 32: throw new Error("not implemented: ".concat(template.localName));
436
- case 33: return [4 /*yield*/, this.xsltForEach(context, template, output)];
437
- case 34:
438
- _c.sent();
439
- return [3 /*break*/, 65];
440
- case 35:
441
- test_1 = (0, dom_1.xmlGetAttribute)(template, 'test');
442
- if (!this.xPath.xPathEval(test_1, context).booleanValue()) return [3 /*break*/, 37];
443
- return [4 /*yield*/, this.xsltChildNodes(context, template, output)];
444
- case 36:
445
- _c.sent();
446
- _c.label = 37;
447
- case 37: return [3 /*break*/, 65];
448
- case 38: throw new Error("not implemented: ".concat(template.localName));
449
- case 39: return [4 /*yield*/, this.xsltInclude(context, template, output)];
450
- case 40:
451
- _c.sent();
452
- return [3 /*break*/, 65];
453
- case 41: throw new Error("not implemented: ".concat(template.localName));
454
- case 42: throw new Error("not implemented: ".concat(template.localName));
455
- case 43: throw new Error("not implemented: ".concat(template.localName));
456
- case 44: throw new Error("not implemented: ".concat(template.localName));
457
- case 45: throw "error if here: ".concat(template.localName);
458
- case 46:
459
- this.outputMethod = (0, dom_1.xmlGetAttribute)(template, 'method');
460
- this.outputOmitXmlDeclaration = (0, dom_1.xmlGetAttribute)(template, 'omit-xml-declaration');
461
- return [3 /*break*/, 65];
462
- case 47: return [4 /*yield*/, this.xsltVariable(context, template, false)];
463
- case 48:
464
- _c.sent();
465
- return [3 /*break*/, 65];
466
- case 49: throw new Error("not implemented: ".concat(template.localName));
467
- case 50: throw new Error("not implemented: ".concat(template.localName));
468
- case 51:
469
- this.xsltSort(context, template);
470
- return [3 /*break*/, 65];
471
- case 52: throw new Error("not implemented: ".concat(template.localName));
472
- case 53: return [4 /*yield*/, this.xsltTransformOrStylesheet(template, context, output)];
473
- case 54:
474
- _c.sent();
475
- return [3 /*break*/, 65];
476
- case 55:
477
- // If `<xsl:template>` is executed outside `<xsl:apply-templates>`,
478
- // only one match is accepted per level (or per context here).
479
- if (!context.inApplyTemplates && context.baseTemplateMatched) {
480
- return [3 /*break*/, 65];
481
- }
482
- match = (0, dom_1.xmlGetAttribute)(template, 'match');
483
- if (!match)
484
- return [3 /*break*/, 65];
485
- // XPath doesn't have an axis to select "self and siblings", and
486
- // the default axis is "child", so to select the correct children
487
- // in relative path, we force a 'self-and-siblings' axis.
488
- nodes = this.xsltMatch(match, context, 'self-and-siblings');
489
- if (!(nodes.length > 0)) return [3 /*break*/, 57];
490
- if (!context.inApplyTemplates) {
491
- context.baseTemplateMatched = true;
492
- }
493
- templateContext = context.clone(nodes, undefined, 0);
494
- return [4 /*yield*/, this.xsltChildNodes(templateContext, template, output)];
495
- case 56:
496
- _c.sent();
497
- _c.label = 57;
498
- case 57: return [3 /*break*/, 65];
499
- case 58:
500
- text = (0, dom_1.xmlValue)(template);
501
- node = (0, dom_1.domCreateTransformedTextNode)(this.outputDocument, text);
502
- disableOutputEscaping = template.childNodes.filter(function (a) { return a.nodeType === constants_1.DOM_ATTRIBUTE_NODE && a.nodeName === 'disable-output-escaping'; });
503
- if (disableOutputEscaping.length > 0 && disableOutputEscaping[0].nodeValue === 'yes') {
504
- node.escape = false;
505
- }
506
- destinationTextNode = output || context.outputNodeList[context.outputPosition];
507
- destinationTextNode.appendTransformedChild(node);
508
- return [3 /*break*/, 65];
509
- case 59:
510
- select = (0, dom_1.xmlGetAttribute)(template, 'select');
511
- attribute = this.xPath.xPathEval(select, context);
512
- value = attribute.stringValue();
513
- node = (0, dom_1.domCreateTransformedTextNode)(this.outputDocument, value);
514
- node.siblingPosition = context.nodeList[context.position].siblingPosition;
515
- if (output.nodeType === constants_1.DOM_DOCUMENT_FRAGMENT_NODE) {
516
- output.appendTransformedChild(node);
517
- }
518
- else {
519
- context.outputNodeList[context.outputPosition].appendTransformedChild(node);
520
- }
521
- return [3 /*break*/, 65];
522
- case 60: return [4 /*yield*/, this.xsltVariable(context, template, true)];
523
- case 61:
524
- _c.sent();
525
- return [3 /*break*/, 65];
526
- case 62: throw new Error("error if here: ".concat(template.localName));
527
- case 63: throw new Error("error if here: ".concat(template.localName));
528
- case 64: throw new Error("error if here: ".concat(template.localName));
529
- case 65: return [2 /*return*/];
530
- }
531
- });
532
- });
533
- };
534
- /**
535
- * Implements `xsl:choose`, its child nodes `xsl:when`, and
536
- * `xsl:otherwise`.
537
- * @param context The Expression Context.
538
- * @param template The template.
539
- * @param output The output. Only used if there's no corresponding output node already defined.
540
- */
541
- Xslt.prototype.xsltChoose = function (context, template, output) {
542
- return __awaiter(this, void 0, void 0, function () {
543
- var _i, _a, childNode, test_2, outputNode, outputNode;
544
- return __generator(this, function (_b) {
545
- switch (_b.label) {
546
- case 0:
547
- _i = 0, _a = template.childNodes;
548
- _b.label = 1;
549
- case 1:
550
- if (!(_i < _a.length)) return [3 /*break*/, 7];
551
- childNode = _a[_i];
552
- if (childNode.nodeType !== constants_1.DOM_ELEMENT_NODE) {
553
- return [3 /*break*/, 6];
554
- }
555
- if (!this.isXsltElement(childNode, 'when')) return [3 /*break*/, 4];
556
- test_2 = (0, dom_1.xmlGetAttribute)(childNode, 'test');
557
- if (!this.xPath.xPathEval(test_2, context).booleanValue()) return [3 /*break*/, 3];
558
- outputNode = context.outputNodeList[context.outputPosition] || output;
559
- return [4 /*yield*/, this.xsltChildNodes(context, childNode, outputNode)];
560
- case 2:
561
- _b.sent();
562
- return [3 /*break*/, 7];
563
- case 3: return [3 /*break*/, 6];
564
- case 4:
565
- if (!this.isXsltElement(childNode, 'otherwise')) return [3 /*break*/, 6];
566
- outputNode = context.outputNodeList[context.outputPosition] || output;
567
- return [4 /*yield*/, this.xsltChildNodes(context, childNode, outputNode)];
568
- case 5:
569
- _b.sent();
570
- return [3 /*break*/, 7];
571
- case 6:
572
- _i++;
573
- return [3 /*break*/, 1];
574
- case 7: return [2 /*return*/];
575
- }
576
- });
577
- });
578
- };
579
- /**
580
- * Implements `xsl:copy` for all node types.
581
- * @param {XNode} destination the node being copied to, part of output document.
582
- * @param {XNode} source the node being copied, part in input document.
583
- * @returns {XNode|null} If an element node was created, the element node. Otherwise, null.
584
- */
585
- Xslt.prototype.xsltCopy = function (destination, source) {
586
- if (source.nodeType == constants_1.DOM_ELEMENT_NODE) {
587
- var node = (0, dom_1.domCreateElement)(this.outputDocument, source.nodeName);
588
- node.transformedNodeName = source.nodeName;
589
- if (source.namespaceUri !== null && source.namespaceUri !== undefined) {
590
- (0, dom_1.domSetTransformedAttribute)(node, 'xmlns', source.namespaceUri);
591
- }
592
- (0, dom_1.domAppendTransformedChild)(destination, node);
593
- return node;
594
- }
595
- if (source.nodeType == constants_1.DOM_TEXT_NODE) {
596
- var node = (0, dom_1.domCreateTransformedTextNode)(this.outputDocument, source.nodeValue);
597
- (0, dom_1.domAppendTransformedChild)(destination, node);
598
- }
599
- else if (source.nodeType == constants_1.DOM_CDATA_SECTION_NODE) {
600
- var node = (0, dom_1.domCreateCDATASection)(this.outputDocument, source.nodeValue);
601
- (0, dom_1.domAppendTransformedChild)(destination, node);
602
- }
603
- else if (source.nodeType == constants_1.DOM_COMMENT_NODE) {
604
- var node = (0, dom_1.domCreateComment)(this.outputDocument, source.nodeValue);
605
- (0, dom_1.domAppendTransformedChild)(destination, node);
606
- }
607
- else if (source.nodeType == constants_1.DOM_ATTRIBUTE_NODE) {
608
- (0, dom_1.domSetTransformedAttribute)(destination, source.nodeName, source.nodeValue);
609
- }
610
- return null;
611
- };
612
- /**
613
- * Implements `xsl:copy-of` for node-set values of the select
614
- * expression. Recurses down the source node tree, which is part of
615
- * the input document.
616
- * @param {XNode} destination the node being copied to, part of output document.
617
- * @param {XNode} source the node being copied, part in input document.
618
- */
619
- Xslt.prototype.xsltCopyOf = function (destination, source) {
620
- if (source.nodeType == constants_1.DOM_DOCUMENT_FRAGMENT_NODE || source.nodeType == constants_1.DOM_DOCUMENT_NODE) {
621
- for (var i = 0; i < source.childNodes.length; ++i) {
622
- this.xsltCopyOf(destination, source.childNodes[i]);
623
- }
624
- }
625
- else {
626
- var node = this.xsltCopy(destination, source);
627
- if (node) {
628
- for (var i = 0; i < source.childNodes.length; ++i) {
629
- this.xsltCopyOf(node, source.childNodes[i]);
630
- }
631
- }
632
- }
633
- };
634
- /**
635
- * Implements `xsl:for-each`.
636
- * @param input The Expression Context.
637
- * @param template The template.
638
- * @param output The output.
639
- */
640
- Xslt.prototype.xsltForEach = function (context, template, output) {
641
- return __awaiter(this, void 0, void 0, function () {
642
- var select, nodes, sortContext, nodesWithParent, i;
643
- return __generator(this, function (_a) {
644
- switch (_a.label) {
645
- case 0:
646
- select = (0, dom_1.xmlGetAttribute)(template, 'select');
647
- nodes = this.xPath.xPathEval(select, context).nodeSetValue();
648
- if (nodes.length === 0) {
649
- return [2 /*return*/];
650
- }
651
- sortContext = context.clone(nodes);
652
- this.xsltSort(sortContext, template);
653
- nodesWithParent = sortContext.nodeList.filter(function (n) { return n.parentNode !== null && n.parentNode !== undefined; });
654
- if (nodesWithParent.length <= 0) {
655
- throw new Error('Nodes with no parents defined.');
656
- }
657
- i = 0;
658
- _a.label = 1;
659
- case 1:
660
- if (!(i < sortContext.contextSize())) return [3 /*break*/, 4];
661
- return [4 /*yield*/, this.xsltChildNodes(sortContext.clone(sortContext.nodeList, undefined, i), template, output)];
662
- case 2:
663
- _a.sent();
664
- _a.label = 3;
665
- case 3:
666
- ++i;
667
- return [3 /*break*/, 1];
668
- case 4: return [2 /*return*/];
669
- }
670
- });
671
- });
672
- };
673
- /**
674
- * Implements `xsl:include`.
675
- * @param input The Expression Context.
676
- * @param template The template.
677
- * @param output The output.
678
- */
679
- Xslt.prototype.xsltInclude = function (context, template, output) {
680
- return __awaiter(this, void 0, void 0, function () {
681
- var hrefAttributeFind, hrefAttribute, fetchTest, fetchResponse, includedXslt;
682
- return __generator(this, function (_a) {
683
- switch (_a.label) {
684
- case 0:
685
- // We need to test here whether `window.fetch` is available or not.
686
- // If it is a browser environemnt, it should be.
687
- // Otherwise, we will need to import an equivalent library, like 'node-fetch'.
688
- if (!global.globalThis.fetch) {
689
- global.globalThis.fetch = node_fetch_1.default;
690
- global.globalThis.Headers = node_fetch_1.Headers;
691
- global.globalThis.Request = node_fetch_1.Request;
692
- global.globalThis.Response = node_fetch_1.Response;
693
- }
694
- hrefAttributeFind = template.childNodes.filter(function (n) { return n.nodeName === 'href'; });
695
- if (hrefAttributeFind.length <= 0) {
696
- throw new Error('<xsl:include> with no href attribute defined.');
697
- }
698
- hrefAttribute = hrefAttributeFind[0];
699
- return [4 /*yield*/, global.globalThis.fetch(hrefAttribute.nodeValue)];
700
- case 1:
701
- fetchTest = _a.sent();
702
- return [4 /*yield*/, fetchTest.text()];
703
- case 2:
704
- fetchResponse = _a.sent();
705
- includedXslt = this.xmlParser.xmlParse(fetchResponse);
706
- return [4 /*yield*/, this.xsltChildNodes(context, includedXslt.childNodes[0], output)];
707
- case 3:
708
- _a.sent();
709
- return [2 /*return*/];
710
- }
711
- });
712
- });
713
- };
714
- /**
715
- * Orders the current node list in the input context according to the
716
- * sort order specified by xsl:sort child nodes of the current
717
- * template node. This happens before the operation specified by the
718
- * current template node is executed.
719
- * @param context The expression context.
720
- * @param template The template node.
721
- * @todo case-order is not implemented.
722
- */
723
- Xslt.prototype.xsltSort = function (context, template) {
724
- var sort = [];
725
- for (var _i = 0, _a = template.childNodes; _i < _a.length; _i++) {
726
- var childNode = _a[_i];
727
- if (childNode.nodeType == constants_1.DOM_ELEMENT_NODE && this.isXsltElement(childNode, 'sort')) {
728
- var select = (0, dom_1.xmlGetAttribute)(childNode, 'select');
729
- var expression = this.xPath.xPathParse(select);
730
- var type = (0, dom_1.xmlGetAttribute)(childNode, 'data-type') || 'text';
731
- var order = (0, dom_1.xmlGetAttribute)(childNode, 'order') || 'ascending';
732
- sort.push({
733
- expr: expression,
734
- type: type,
735
- order: order
736
- });
737
- }
738
- }
739
- this.xPath.xPathSort(context, sort);
740
- };
741
- /**
742
- * Implements `<xsl:stylesheet>` and `<xsl:transform>`, and its corresponding
743
- * validations.
744
- * @param template The `<xsl:stylesheet>` or `<xsl:transform>` node.
745
- * @param context The Expression Context.
746
- * @param output The output XML.
747
- */
748
- Xslt.prototype.xsltTransformOrStylesheet = function (template, context, output) {
749
- return __awaiter(this, void 0, void 0, function () {
750
- var _i, _a, stylesheetAttribute;
751
- return __generator(this, function (_b) {
752
- switch (_b.label) {
753
- case 0:
754
- for (_i = 0, _a = template.childNodes.filter(function (n) { return n.nodeType === constants_1.DOM_ATTRIBUTE_NODE; }); _i < _a.length; _i++) {
755
- stylesheetAttribute = _a[_i];
756
- switch (stylesheetAttribute.nodeName) {
757
- case 'version':
758
- this.version = stylesheetAttribute.nodeValue;
759
- if (!['1.0', '2.0', '3.0'].includes(this.version)) {
760
- throw new Error("XSLT version not defined or invalid. Actual resolved version: ".concat(this.version || '(none)', "."));
761
- }
762
- context.xsltVersion = this.version;
763
- break;
764
- default:
765
- if (stylesheetAttribute.prefix === 'xmlns') {
766
- context.knownNamespaces[stylesheetAttribute.localName] = stylesheetAttribute.nodeValue;
767
- }
768
- break;
769
- }
770
- }
771
- return [4 /*yield*/, this.xsltChildNodes(context, template, output)];
772
- case 1:
773
- _b.sent();
774
- return [2 /*return*/];
775
- }
776
- });
777
- });
778
- };
779
- /**
780
- * Evaluates a variable or parameter and set it in the current input
781
- * context. Implements `xsl:variable`, `xsl:param`, and `xsl:with-param`.
782
- *
783
- * @param context The expression context.
784
- * @param template The template node.
785
- * @param override flag that defines if the value computed here
786
- * overrides the one already in the input context if that is the
787
- * case. I.e. decides if this is a default value or a local
788
- * value. `xsl:variable` and `xsl:with-param` override; `xsl:param` doesn't.
789
- */
790
- Xslt.prototype.xsltVariable = function (context, template, override) {
791
- return __awaiter(this, void 0, void 0, function () {
792
- var name, select, value, nonAttributeChildren, root, parameterValue, filteredParameter;
793
- return __generator(this, function (_a) {
794
- switch (_a.label) {
795
- case 0:
796
- name = (0, dom_1.xmlGetAttribute)(template, 'name');
797
- select = (0, dom_1.xmlGetAttribute)(template, 'select');
798
- nonAttributeChildren = template.childNodes.filter(function (n) { return n.nodeType !== constants_1.DOM_ATTRIBUTE_NODE; });
799
- if (!(nonAttributeChildren.length > 0)) return [3 /*break*/, 2];
800
- root = (0, dom_1.domCreateDocumentFragment)(template.ownerDocument);
801
- return [4 /*yield*/, this.xsltChildNodes(context, template, root)];
802
- case 1:
803
- _a.sent();
804
- value = new values_1.NodeSetValue([root]);
805
- return [3 /*break*/, 3];
806
- case 2:
807
- if (select) {
808
- value = this.xPath.xPathEval(select, context);
809
- }
810
- else {
811
- parameterValue = '';
812
- filteredParameter = this.options.parameters.filter(function (p) { return p.name === name; });
813
- if (filteredParameter.length > 0) {
814
- parameterValue = filteredParameter[0].value;
815
- }
816
- value = new values_1.StringValue(parameterValue);
817
- }
818
- _a.label = 3;
819
- case 3:
820
- if (override || !context.getVariable(name)) {
821
- context.setVariable(name, value);
822
- }
823
- return [2 /*return*/];
824
- }
825
- });
826
- });
827
- };
828
- /**
829
- * Traverses the template node tree. Calls the main processing
830
- * function with the current input context for every child node of the
831
- * current template node.
832
- * @param context Normally the Expression Context.
833
- * @param template The XSL-T definition.
834
- * @param output If set, the output where the transformation should occur.
835
- */
836
- Xslt.prototype.xsltChildNodes = function (context, template, output) {
837
- return __awaiter(this, void 0, void 0, function () {
838
- var contextClone, i;
839
- return __generator(this, function (_a) {
840
- switch (_a.label) {
841
- case 0:
842
- contextClone = context.clone();
843
- i = 0;
844
- _a.label = 1;
845
- case 1:
846
- if (!(i < template.childNodes.length)) return [3 /*break*/, 4];
847
- return [4 /*yield*/, this.xsltProcessContext(contextClone, template.childNodes[i], output)];
848
- case 2:
849
- _a.sent();
850
- _a.label = 3;
851
- case 3:
852
- ++i;
853
- return [3 /*break*/, 1];
854
- case 4: return [2 /*return*/];
855
- }
856
- });
857
- });
858
- };
859
- /**
860
- * This logic is used in two different places:
861
- * - `xsltPassThrough`, if the template asks this library to write a text node;
862
- * - `xsltProcessContext`, `apply-templates` operation, when the current node is text.
863
- * @param context The Expression Context.
864
- * @param template The template, that contains the node value to be written.
865
- */
866
- Xslt.prototype.commonLogicTextNode = function (context, template, output) {
867
- if (output.nodeType === constants_1.DOM_DOCUMENT_FRAGMENT_NODE) {
868
- var node = (0, dom_1.domCreateTransformedTextNode)(this.outputDocument, template.nodeValue);
869
- (0, dom_1.domAppendTransformedChild)(output, node);
870
- }
871
- else {
872
- var textNodeList = context.outputNodeList[context.outputPosition].transformedChildNodes.filter(function (n) { return n.nodeType === constants_1.DOM_TEXT_NODE; });
873
- if (textNodeList.length > 0) {
874
- var node = textNodeList[0];
875
- node.transformedNodeValue = template.nodeValue;
876
- }
877
- else {
878
- var node = (0, dom_1.domCreateTransformedTextNode)(this.outputDocument, template.nodeValue);
879
- node.transformedParentNode = context.outputNodeList[context.outputPosition];
880
- (0, dom_1.domAppendTransformedChild)(context.outputNodeList[context.outputPosition], node);
881
- }
882
- }
883
- };
884
- /**
885
- * Passes template text to the output. The current template node does
886
- * not specify an XSL-T operation and therefore is appended to the
887
- * output with all its attributes. Then continues traversing the
888
- * template node tree.
889
- * @param context The Expression Context.
890
- * @param template The XSLT stylesheet or transformation.
891
- * @param output The output.
892
- */
893
- Xslt.prototype.xsltPassThrough = function (context, template, output) {
894
- return __awaiter(this, void 0, void 0, function () {
895
- var node, elementContext, newNode, transformedAttributes, _i, transformedAttributes_1, previouslyTransformedAttribute, name_2, value, templateAttributes, _a, templateAttributes_1, attribute, name_3, value, outputNode, clonedContext;
896
- return __generator(this, function (_b) {
897
- switch (_b.label) {
898
- case 0:
899
- if (!(template.nodeType == constants_1.DOM_TEXT_NODE)) return [3 /*break*/, 1];
900
- if (this.xsltPassText(template)) {
901
- this.commonLogicTextNode(context, template, output);
902
- }
903
- return [3 /*break*/, 5];
904
- case 1:
905
- if (!(template.nodeType == constants_1.DOM_ELEMENT_NODE)) return [3 /*break*/, 3];
906
- node = void 0;
907
- elementContext = context;
908
- if (context.nodeList[context.position].nodeName === '#document') {
909
- node = context.nodeList[context.position].childNodes.find(function (c) { return c.nodeName !== '#dtd-section'; });
910
- elementContext = context.clone([node]);
911
- }
912
- else {
913
- node = context.nodeList[context.position];
914
- }
915
- newNode = void 0;
916
- if (node.outputNode === undefined || node.outputNode === null || context.outputDepth > 0) {
917
- newNode = (0, dom_1.domCreateElement)(this.outputDocument, template.nodeName);
918
- newNode.siblingPosition = node.siblingPosition;
919
- if (context.outputDepth === 0) {
920
- node.outputNode = newNode;
921
- }
922
- }
923
- else {
924
- newNode = node.outputNode;
925
- }
926
- newNode.transformedNodeName = template.nodeName;
927
- newNode.transformedLocalName = template.localName;
928
- transformedAttributes = node.transformedChildNodes.filter(function (n) { return n.nodeType === constants_1.DOM_ATTRIBUTE_NODE; });
929
- for (_i = 0, transformedAttributes_1 = transformedAttributes; _i < transformedAttributes_1.length; _i++) {
930
- previouslyTransformedAttribute = transformedAttributes_1[_i];
931
- name_2 = previouslyTransformedAttribute.transformedNodeName;
932
- value = previouslyTransformedAttribute.transformedNodeValue;
933
- (0, dom_1.domSetTransformedAttribute)(newNode, name_2, value);
934
- }
935
- templateAttributes = template.childNodes.filter(function (a) { return (a === null || a === void 0 ? void 0 : a.nodeType) === constants_1.DOM_ATTRIBUTE_NODE; });
936
- for (_a = 0, templateAttributes_1 = templateAttributes; _a < templateAttributes_1.length; _a++) {
937
- attribute = templateAttributes_1[_a];
938
- name_3 = attribute.nodeName;
939
- value = this.xsltAttributeValue(attribute.nodeValue, elementContext);
940
- (0, dom_1.domSetTransformedAttribute)(newNode, name_3, value);
941
- }
942
- outputNode = context.outputNodeList[context.outputPosition];
943
- (0, dom_1.domAppendTransformedChild)(outputNode, newNode);
944
- clonedContext = elementContext.cloneByOutput(outputNode.transformedChildNodes, outputNode.transformedChildNodes.length - 1, ++elementContext.outputDepth);
945
- return [4 /*yield*/, this.xsltChildNodes(clonedContext, template, output)];
946
- case 2:
947
- _b.sent();
948
- return [3 /*break*/, 5];
949
- case 3:
950
- // This applies also to the DOCUMENT_NODE of the XSL stylesheet,
951
- // so we don't have to treat it specially.
952
- return [4 /*yield*/, this.xsltChildNodes(context, template, output)];
953
- case 4:
954
- // This applies also to the DOCUMENT_NODE of the XSL stylesheet,
955
- // so we don't have to treat it specially.
956
- _b.sent();
957
- _b.label = 5;
958
- case 5: return [2 /*return*/];
959
- }
960
- });
961
- });
962
- };
963
- /**
964
- * Determines if a text node in the XSLT template document is to be
965
- * stripped according to XSLT whitespace stripping rules.
966
- * @see [XSLT], section 3.4.
967
- * @param template The XSLT template.
968
- * @returns TODO
969
- * @todo Whitespace stripping on the input document is
970
- * currently not implemented.
971
- */
972
- Xslt.prototype.xsltPassText = function (template) {
973
- if (!template.nodeValue.match(/^\s*$/)) {
974
- return true;
975
- }
976
- var element = template.parentNode;
977
- if (this.isXsltElement(element, 'text')) {
978
- return true;
979
- }
980
- while (element && element.nodeType == constants_1.DOM_ELEMENT_NODE) {
981
- var xmlspace = (0, dom_1.domGetAttributeValue)(element, 'xml:space');
982
- if (xmlspace) {
983
- if (xmlspace == 'default') {
984
- return false;
985
- }
986
- if (xmlspace == 'preserve') {
987
- return true;
988
- }
989
- }
990
- element = element.parentNode;
991
- }
992
- return false;
993
- };
994
- Xslt.prototype.xsltAttribute = function (attributeName, context) {
995
- return context.nodeList[context.position].childNodes.find(function (a) { return a.nodeType === constants_1.DOM_ATTRIBUTE_NODE && a.nodeName === attributeName; });
996
- };
997
- /**
998
- * Evaluates an XSL-T attribute value template. Attribute value
999
- * templates are attributes on XSL-T elements that contain XPath
1000
- * expressions in braces {}. The XSL-T expressions are evaluated in
1001
- * the current input context.
1002
- * @param value TODO
1003
- * @param context TODO
1004
- * @returns TODO
1005
- */
1006
- Xslt.prototype.xsltAttributeValue = function (value, context) {
1007
- var parts = value.split('{');
1008
- if (parts.length === 1) {
1009
- return value;
1010
- }
1011
- var ret = '';
1012
- for (var i = 0; i < parts.length; ++i) {
1013
- var rp = parts[i].split('}');
1014
- if (rp.length != 2) {
1015
- // first literal part of the value
1016
- ret += parts[i];
1017
- continue;
1018
- }
1019
- var val = this.xPath.xPathEval(rp[0], context).stringValue();
1020
- ret += val + rp[1];
1021
- }
1022
- return ret;
1023
- };
1024
- /**
1025
- * Evaluates an XPath expression in the current input context as a
1026
- * match.
1027
- * @see [XSLT] section 5.2, paragraph 1
1028
- * @param match TODO
1029
- * @param context The Expression Context.
1030
- * @param axis The XPath axis. Used when the match does not start with the parent.
1031
- * @returns {XNode[]} A list of the found nodes.
1032
- */
1033
- Xslt.prototype.xsltMatch = function (match, context, axis) {
1034
- var expression = this.xPath.xPathParse(match, axis);
1035
- return this.matchResolver.expressionMatch(expression, context);
1036
- };
1037
- /**
1038
- * Sets parameters defined by xsl:with-param child nodes of the
1039
- * current template node, in the current input context. This happens
1040
- * before the operation specified by the current template node is
1041
- * executed.
1042
- * @param context The Expression Context.
1043
- * @param template The template node.
1044
- */
1045
- Xslt.prototype.xsltWithParam = function (context, template) {
1046
- return __awaiter(this, void 0, void 0, function () {
1047
- var _i, _a, childNode;
1048
- return __generator(this, function (_b) {
1049
- switch (_b.label) {
1050
- case 0:
1051
- _i = 0, _a = template.childNodes;
1052
- _b.label = 1;
1053
- case 1:
1054
- if (!(_i < _a.length)) return [3 /*break*/, 4];
1055
- childNode = _a[_i];
1056
- if (!(childNode.nodeType === constants_1.DOM_ELEMENT_NODE && this.isXsltElement(childNode, 'with-param'))) return [3 /*break*/, 3];
1057
- return [4 /*yield*/, this.xsltVariable(context, childNode, true)];
1058
- case 2:
1059
- _b.sent();
1060
- _b.label = 3;
1061
- case 3:
1062
- _i++;
1063
- return [3 /*break*/, 1];
1064
- case 4: return [2 /*return*/];
1065
- }
1066
- });
1067
- });
1068
- };
1069
- // Test if the given element is an XSLT element, optionally the one with the given name
1070
- Xslt.prototype.isXsltElement = function (element, opt_wantedName) {
1071
- if (opt_wantedName && element.localName != opt_wantedName)
1072
- return false;
1073
- if (element.namespaceUri)
1074
- return element.namespaceUri === 'http://www.w3.org/1999/XSL/Transform';
1075
- return element.prefix === 'xsl'; // backwards compatibility with earlier versions of xslt-processor
1076
- };
1077
- return Xslt;
1078
- }());
1079
- exports.Xslt = Xslt;
1
+ "use strict";
2
+ // Copyright 2023-2024 Design Liquido
3
+ // Copyright 2018 Johannes Wilm
4
+ // Copyright 2005 Google Inc.
5
+ // All Rights Reserved
6
+ //
7
+ // TODO(mesch): add jsdoc comments. Use more coherent naming. Finish
8
+ // remaining XSLT features.
9
+ //
10
+ // Original author: Steffen Meschkat <mesch@google.com>
11
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ var desc = Object.getOwnPropertyDescriptor(m, k);
14
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
15
+ desc = { enumerable: true, get: function() { return m[k]; } };
16
+ }
17
+ Object.defineProperty(o, k2, desc);
18
+ }) : (function(o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ o[k2] = m[k];
21
+ }));
22
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
23
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
24
+ }) : function(o, v) {
25
+ o["default"] = v;
26
+ });
27
+ var __importStar = (this && this.__importStar) || function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
35
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
36
+ return new (P || (P = Promise))(function (resolve, reject) {
37
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
38
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
39
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
40
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
41
+ });
42
+ };
43
+ var __generator = (this && this.__generator) || function (thisArg, body) {
44
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
45
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
46
+ function verb(n) { return function (v) { return step([n, v]); }; }
47
+ function step(op) {
48
+ if (f) throw new TypeError("Generator is already executing.");
49
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
50
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
51
+ if (y = 0, t) op = [op[0] & 2, t.value];
52
+ switch (op[0]) {
53
+ case 0: case 1: t = op; break;
54
+ case 4: _.label++; return { value: op[1], done: false };
55
+ case 5: _.label++; y = op[1]; op = [0]; continue;
56
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
57
+ default:
58
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
59
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
60
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
61
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
62
+ if (t[2]) _.ops.pop();
63
+ _.trys.pop(); continue;
64
+ }
65
+ op = body.call(thisArg, _);
66
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
67
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
68
+ }
69
+ };
70
+ Object.defineProperty(exports, "__esModule", { value: true });
71
+ exports.Xslt = void 0;
72
+ var node_fetch_1 = __importStar(require("node-fetch"));
73
+ var dom_1 = require("../dom");
74
+ var xpath_1 = require("../xpath");
75
+ var constants_1 = require("../constants");
76
+ var values_1 = require("../xpath/values");
77
+ var match_resolver_1 = require("../xpath/match-resolver");
78
+ /**
79
+ * The main class for XSL-T processing. The implementation is NOT
80
+ * complete; some xsl element are left out.
81
+ *
82
+ * References:
83
+ *
84
+ * [XSLT] XSL-T Specification
85
+ * <http://www.w3.org/TR/1999/REC-xslt-19991116>.
86
+ *
87
+ * [ECMA] ECMAScript Language Specification
88
+ * <http://www.ecma-international.org/publications/standards/Ecma-262.htm>.
89
+ *
90
+ * The XSL processor API has one entry point, the function
91
+ * xsltProcessContext(). It receives as arguments the starting point in the
92
+ * input document as an XPath expression context, the DOM root node of
93
+ * the XSL-T stylesheet, and a DOM node that receives the output.
94
+ *
95
+ * NOTE: Actually, XSL-T processing according to the specification is
96
+ * defined as operation on text documents, not as operation on DOM
97
+ * trees. So, strictly speaking, this implementation is not an XSL-T
98
+ * processor, but the processing engine that needs to be complemented
99
+ * by an XML parser and serializer in order to be complete. Those two
100
+ * are found in the `dom` folder.
101
+ */
102
+ var Xslt = /** @class */ (function () {
103
+ function Xslt(options) {
104
+ if (options === void 0) { options = {
105
+ cData: true,
106
+ escape: true,
107
+ selfClosingTags: true,
108
+ parameters: []
109
+ }; }
110
+ this.xPath = new xpath_1.XPath();
111
+ this.xmlParser = new dom_1.XmlParser();
112
+ this.matchResolver = new match_resolver_1.MatchResolver();
113
+ this.options = {
114
+ cData: options.cData === true,
115
+ escape: options.escape === true,
116
+ selfClosingTags: options.selfClosingTags === true,
117
+ parameters: options.parameters || []
118
+ };
119
+ this.outputMethod = 'xml';
120
+ this.outputOmitXmlDeclaration = 'no';
121
+ this.decimalFormatSettings = {
122
+ decimalSeparator: '.',
123
+ groupingSeparator: ',',
124
+ infinity: 'Infinity',
125
+ minusSign: '-',
126
+ naN: 'NaN',
127
+ percent: '%',
128
+ perMille: '‰',
129
+ zeroDigit: '0',
130
+ digit: '#',
131
+ patternSeparator: ';'
132
+ };
133
+ }
134
+ /**
135
+ * The exported entry point of the XSL-T processor.
136
+ * @param xmlDoc The input document root, as DOM node.
137
+ * @param stylesheet The stylesheet document root, as DOM node.
138
+ * @returns the processed document, as XML text in a string.
139
+ */
140
+ Xslt.prototype.xsltProcess = function (xmlDoc, stylesheet) {
141
+ return __awaiter(this, void 0, void 0, function () {
142
+ var outputDocument, expressionContext, _i, _a, parameter, transformedOutputXml;
143
+ return __generator(this, function (_b) {
144
+ switch (_b.label) {
145
+ case 0:
146
+ outputDocument = new dom_1.XDocument();
147
+ this.outputDocument = outputDocument;
148
+ expressionContext = new xpath_1.ExprContext([xmlDoc], [outputDocument]);
149
+ if (this.options.parameters.length > 0) {
150
+ for (_i = 0, _a = this.options.parameters; _i < _a.length; _i++) {
151
+ parameter = _a[_i];
152
+ expressionContext.setVariable(parameter.name, new values_1.StringValue(parameter.value));
153
+ }
154
+ }
155
+ return [4 /*yield*/, this.xsltProcessContext(expressionContext, stylesheet, this.outputDocument)];
156
+ case 1:
157
+ _b.sent();
158
+ transformedOutputXml = (0, dom_1.xmlTransformedText)(outputDocument, {
159
+ cData: this.options.cData,
160
+ escape: this.options.escape,
161
+ selfClosingTags: this.options.selfClosingTags,
162
+ outputMethod: this.outputMethod
163
+ });
164
+ return [2 /*return*/, transformedOutputXml];
165
+ }
166
+ });
167
+ });
168
+ };
169
+ /**
170
+ * The main entry point of the XSL-T processor, as explained on the top of the file.
171
+ * @param context The input document root, as XPath `ExprContext`.
172
+ * @param template The stylesheet document root, as DOM node.
173
+ * @param output If set, the output where the transformation should occur.
174
+ */
175
+ Xslt.prototype.xsltProcessContext = function (context, template, output) {
176
+ return __awaiter(this, void 0, void 0, function () {
177
+ var name_1, top_1, nameExpr, node, select, value, nodes, paramContext, commentData, commentNode, test_1, match, text, _a, i, childNode, destinationCopyNode, destinationNode, i, node_1, decimalSeparator, groupingSeparator, infinity, minusSign, naN, percent, perMille, zeroDigit, digit, patternSeparator, clonedContext, templateContext, disableOutputEscaping, destinationTextNode, attribute;
178
+ return __generator(this, function (_b) {
179
+ switch (_b.label) {
180
+ case 0:
181
+ if (!!this.isXsltElement(template)) return [3 /*break*/, 2];
182
+ return [4 /*yield*/, this.xsltPassThrough(context, template, output)];
183
+ case 1:
184
+ _b.sent();
185
+ return [3 /*break*/, 59];
186
+ case 2:
187
+ nameExpr = void 0, node = void 0, select = void 0, value = void 0, nodes = void 0, paramContext = void 0, commentData = void 0, commentNode = void 0, match = void 0, text = void 0;
188
+ _a = template.localName;
189
+ switch (_a) {
190
+ case 'apply-imports': return [3 /*break*/, 3];
191
+ case 'apply-templates': return [3 /*break*/, 4];
192
+ case 'attribute': return [3 /*break*/, 6];
193
+ case 'attribute-set': return [3 /*break*/, 8];
194
+ case 'call-template': return [3 /*break*/, 9];
195
+ case 'choose': return [3 /*break*/, 15];
196
+ case 'comment': return [3 /*break*/, 17];
197
+ case 'copy': return [3 /*break*/, 19];
198
+ case 'copy-of': return [3 /*break*/, 22];
199
+ case 'decimal-format': return [3 /*break*/, 23];
200
+ case 'element': return [3 /*break*/, 24];
201
+ case 'fallback': return [3 /*break*/, 26];
202
+ case 'for-each': return [3 /*break*/, 27];
203
+ case 'if': return [3 /*break*/, 29];
204
+ case 'import': return [3 /*break*/, 32];
205
+ case 'include': return [3 /*break*/, 33];
206
+ case 'key': return [3 /*break*/, 35];
207
+ case 'message': return [3 /*break*/, 36];
208
+ case 'namespace-alias': return [3 /*break*/, 37];
209
+ case 'number': return [3 /*break*/, 38];
210
+ case 'otherwise': return [3 /*break*/, 39];
211
+ case 'output': return [3 /*break*/, 40];
212
+ case 'param': return [3 /*break*/, 41];
213
+ case 'preserve-space': return [3 /*break*/, 43];
214
+ case 'processing-instruction': return [3 /*break*/, 44];
215
+ case 'sort': return [3 /*break*/, 45];
216
+ case 'strip-space': return [3 /*break*/, 46];
217
+ case 'stylesheet': return [3 /*break*/, 47];
218
+ case 'transform': return [3 /*break*/, 47];
219
+ case 'template': return [3 /*break*/, 49];
220
+ case 'text': return [3 /*break*/, 52];
221
+ case 'value-of': return [3 /*break*/, 53];
222
+ case 'variable': return [3 /*break*/, 54];
223
+ case 'when': return [3 /*break*/, 56];
224
+ case 'with-param': return [3 /*break*/, 57];
225
+ }
226
+ return [3 /*break*/, 58];
227
+ case 3: throw new Error("not implemented: ".concat(template.localName));
228
+ case 4: return [4 /*yield*/, this.xsltApplyTemplates(context, template, output)];
229
+ case 5:
230
+ _b.sent();
231
+ return [3 /*break*/, 59];
232
+ case 6: return [4 /*yield*/, this.xsltAttribute(context, template, output)];
233
+ case 7:
234
+ _b.sent();
235
+ return [3 /*break*/, 59];
236
+ case 8: throw new Error("not implemented: ".concat(template.localName));
237
+ case 9:
238
+ name_1 = (0, dom_1.xmlGetAttribute)(template, 'name');
239
+ top_1 = template.ownerDocument.documentElement;
240
+ paramContext = context.clone();
241
+ return [4 /*yield*/, this.xsltWithParam(paramContext, template)];
242
+ case 10:
243
+ _b.sent();
244
+ i = 0;
245
+ _b.label = 11;
246
+ case 11:
247
+ if (!(i < top_1.childNodes.length)) return [3 /*break*/, 14];
248
+ childNode = top_1.childNodes[i];
249
+ if (!(childNode.nodeType === constants_1.DOM_ELEMENT_NODE &&
250
+ this.isXsltElement(childNode, 'template') &&
251
+ (0, dom_1.domGetAttributeValue)(childNode, 'name') == name_1)) return [3 /*break*/, 13];
252
+ return [4 /*yield*/, this.xsltChildNodes(paramContext, childNode, output)];
253
+ case 12:
254
+ _b.sent();
255
+ return [3 /*break*/, 14];
256
+ case 13:
257
+ ++i;
258
+ return [3 /*break*/, 11];
259
+ case 14: return [3 /*break*/, 59];
260
+ case 15: return [4 /*yield*/, this.xsltChoose(context, template, output)];
261
+ case 16:
262
+ _b.sent();
263
+ return [3 /*break*/, 59];
264
+ case 17:
265
+ node = (0, dom_1.domCreateDocumentFragment)(this.outputDocument);
266
+ return [4 /*yield*/, this.xsltChildNodes(context, template, node)];
267
+ case 18:
268
+ _b.sent();
269
+ commentData = (0, dom_1.xmlValue)(node);
270
+ commentNode = (0, dom_1.domCreateComment)(this.outputDocument, commentData);
271
+ output.appendChild(commentNode);
272
+ return [3 /*break*/, 59];
273
+ case 19:
274
+ destinationCopyNode = output || context.outputNodeList[context.outputPosition];
275
+ node = this.xsltCopy(destinationCopyNode, context.nodeList[context.position]);
276
+ if (!node) return [3 /*break*/, 21];
277
+ return [4 /*yield*/, this.xsltChildNodes(context, template, node)];
278
+ case 20:
279
+ _b.sent();
280
+ _b.label = 21;
281
+ case 21: return [3 /*break*/, 59];
282
+ case 22:
283
+ select = (0, dom_1.xmlGetAttribute)(template, 'select');
284
+ value = this.xPath.xPathEval(select, context);
285
+ destinationNode = context.outputNodeList[context.outputPosition] || output;
286
+ if (value.type === 'node-set') {
287
+ nodes = value.nodeSetValue();
288
+ for (i = 0; i < nodes.length; ++i) {
289
+ this.xsltCopyOf(destinationNode, nodes[i]);
290
+ }
291
+ }
292
+ else {
293
+ node_1 = (0, dom_1.domCreateTextNode)(this.outputDocument, value.stringValue());
294
+ (0, dom_1.domAppendChild)(destinationNode, node_1);
295
+ }
296
+ return [3 /*break*/, 59];
297
+ case 23:
298
+ name_1 = (0, dom_1.xmlGetAttribute)(template, 'name');
299
+ decimalSeparator = (0, dom_1.xmlGetAttribute)(template, 'decimal-separator');
300
+ groupingSeparator = (0, dom_1.xmlGetAttribute)(template, 'grouping-separator');
301
+ infinity = (0, dom_1.xmlGetAttribute)(template, 'infinity');
302
+ minusSign = (0, dom_1.xmlGetAttribute)(template, 'minus-sign');
303
+ naN = (0, dom_1.xmlGetAttribute)(template, 'NaN');
304
+ percent = (0, dom_1.xmlGetAttribute)(template, 'percent');
305
+ perMille = (0, dom_1.xmlGetAttribute)(template, 'per-mille');
306
+ zeroDigit = (0, dom_1.xmlGetAttribute)(template, 'zero-digit');
307
+ digit = (0, dom_1.xmlGetAttribute)(template, 'digit');
308
+ patternSeparator = (0, dom_1.xmlGetAttribute)(template, 'pattern-separator');
309
+ this.decimalFormatSettings = {
310
+ name: name_1 || this.decimalFormatSettings.name,
311
+ decimalSeparator: decimalSeparator || this.decimalFormatSettings.decimalSeparator,
312
+ groupingSeparator: groupingSeparator || this.decimalFormatSettings.groupingSeparator,
313
+ infinity: infinity || this.decimalFormatSettings.infinity,
314
+ minusSign: minusSign || this.decimalFormatSettings.minusSign,
315
+ naN: naN || this.decimalFormatSettings.naN,
316
+ percent: percent || this.decimalFormatSettings.percent,
317
+ perMille: perMille || this.decimalFormatSettings.perMille,
318
+ zeroDigit: zeroDigit || this.decimalFormatSettings.zeroDigit,
319
+ digit: digit || this.decimalFormatSettings.digit,
320
+ patternSeparator: patternSeparator || this.decimalFormatSettings.patternSeparator
321
+ };
322
+ context.decimalFormatSettings = this.decimalFormatSettings;
323
+ return [3 /*break*/, 59];
324
+ case 24:
325
+ nameExpr = (0, dom_1.xmlGetAttribute)(template, 'name');
326
+ name_1 = this.xsltAttributeValue(nameExpr, context);
327
+ node = (0, dom_1.domCreateElement)(this.outputDocument, name_1);
328
+ node.transformedNodeName = name_1;
329
+ (0, dom_1.domAppendTransformedChild)(context.outputNodeList[context.outputPosition], node);
330
+ // The element becomes the output node of the source node.
331
+ context.nodeList[context.position].outputNode = node;
332
+ clonedContext = context.clone(undefined, [node], undefined, 0);
333
+ return [4 /*yield*/, this.xsltChildNodes(clonedContext, template)];
334
+ case 25:
335
+ _b.sent();
336
+ return [3 /*break*/, 59];
337
+ case 26: throw new Error("not implemented: ".concat(template.localName));
338
+ case 27: return [4 /*yield*/, this.xsltForEach(context, template, output)];
339
+ case 28:
340
+ _b.sent();
341
+ return [3 /*break*/, 59];
342
+ case 29:
343
+ test_1 = (0, dom_1.xmlGetAttribute)(template, 'test');
344
+ if (!this.xPath.xPathEval(test_1, context).booleanValue()) return [3 /*break*/, 31];
345
+ return [4 /*yield*/, this.xsltChildNodes(context, template, output)];
346
+ case 30:
347
+ _b.sent();
348
+ _b.label = 31;
349
+ case 31: return [3 /*break*/, 59];
350
+ case 32: throw new Error("not implemented: ".concat(template.localName));
351
+ case 33: return [4 /*yield*/, this.xsltInclude(context, template, output)];
352
+ case 34:
353
+ _b.sent();
354
+ return [3 /*break*/, 59];
355
+ case 35: throw new Error("not implemented: ".concat(template.localName));
356
+ case 36: throw new Error("not implemented: ".concat(template.localName));
357
+ case 37: throw new Error("not implemented: ".concat(template.localName));
358
+ case 38: throw new Error("not implemented: ".concat(template.localName));
359
+ case 39: throw "error if here: ".concat(template.localName);
360
+ case 40:
361
+ this.outputMethod = (0, dom_1.xmlGetAttribute)(template, 'method');
362
+ this.outputOmitXmlDeclaration = (0, dom_1.xmlGetAttribute)(template, 'omit-xml-declaration');
363
+ return [3 /*break*/, 59];
364
+ case 41: return [4 /*yield*/, this.xsltVariable(context, template, false)];
365
+ case 42:
366
+ _b.sent();
367
+ return [3 /*break*/, 59];
368
+ case 43: throw new Error("not implemented: ".concat(template.localName));
369
+ case 44: throw new Error("not implemented: ".concat(template.localName));
370
+ case 45:
371
+ this.xsltSort(context, template);
372
+ return [3 /*break*/, 59];
373
+ case 46: throw new Error("not implemented: ".concat(template.localName));
374
+ case 47: return [4 /*yield*/, this.xsltTransformOrStylesheet(template, context, output)];
375
+ case 48:
376
+ _b.sent();
377
+ return [3 /*break*/, 59];
378
+ case 49:
379
+ // If `<xsl:template>` is executed outside `<xsl:apply-templates>`,
380
+ // only one match is accepted per level (or per context here).
381
+ if (!context.inApplyTemplates && context.baseTemplateMatched) {
382
+ return [3 /*break*/, 59];
383
+ }
384
+ match = (0, dom_1.xmlGetAttribute)(template, 'match');
385
+ if (!match)
386
+ return [3 /*break*/, 59];
387
+ // XPath doesn't have an axis to select "self and siblings", and
388
+ // the default axis is "child", so to select the correct children
389
+ // in relative path, we force a 'self-and-siblings' axis.
390
+ nodes = this.xsltMatch(match, context, 'self-and-siblings');
391
+ if (!(nodes.length > 0)) return [3 /*break*/, 51];
392
+ if (!context.inApplyTemplates) {
393
+ context.baseTemplateMatched = true;
394
+ }
395
+ templateContext = context.clone(nodes, undefined, 0);
396
+ return [4 /*yield*/, this.xsltChildNodes(templateContext, template, output)];
397
+ case 50:
398
+ _b.sent();
399
+ _b.label = 51;
400
+ case 51: return [3 /*break*/, 59];
401
+ case 52:
402
+ text = (0, dom_1.xmlValue)(template);
403
+ node = (0, dom_1.domCreateTransformedTextNode)(this.outputDocument, text);
404
+ disableOutputEscaping = template.childNodes.filter(function (a) { return a.nodeType === constants_1.DOM_ATTRIBUTE_NODE && a.nodeName === 'disable-output-escaping'; });
405
+ if (disableOutputEscaping.length > 0 && disableOutputEscaping[0].nodeValue === 'yes') {
406
+ node.escape = false;
407
+ }
408
+ destinationTextNode = output || context.outputNodeList[context.outputPosition];
409
+ destinationTextNode.appendTransformedChild(node);
410
+ return [3 /*break*/, 59];
411
+ case 53:
412
+ select = (0, dom_1.xmlGetAttribute)(template, 'select');
413
+ attribute = this.xPath.xPathEval(select, context);
414
+ value = attribute.stringValue();
415
+ node = (0, dom_1.domCreateTransformedTextNode)(this.outputDocument, value);
416
+ node.siblingPosition = context.nodeList[context.position].siblingPosition;
417
+ if (output && output.nodeType === constants_1.DOM_DOCUMENT_FRAGMENT_NODE) {
418
+ output.appendTransformedChild(node);
419
+ }
420
+ else {
421
+ context.outputNodeList[context.outputPosition].appendTransformedChild(node);
422
+ }
423
+ return [3 /*break*/, 59];
424
+ case 54: return [4 /*yield*/, this.xsltVariable(context, template, true)];
425
+ case 55:
426
+ _b.sent();
427
+ return [3 /*break*/, 59];
428
+ case 56: throw new Error("error if here: ".concat(template.localName));
429
+ case 57: throw new Error("error if here: ".concat(template.localName));
430
+ case 58: throw new Error("error if here: ".concat(template.localName));
431
+ case 59: return [2 /*return*/];
432
+ }
433
+ });
434
+ });
435
+ };
436
+ /**
437
+ * Implements `xsl:apply-templates`.
438
+ * @param context The Expression Context.
439
+ * @param template The template.
440
+ * @param output The output. Only used if there's no corresponding output node already defined.
441
+ * @protected
442
+ */
443
+ Xslt.prototype.xsltApplyTemplates = function (context, template, output) {
444
+ return __awaiter(this, void 0, void 0, function () {
445
+ var getAllTemplates, select, nodes, mode, top, templates, modifiedContext, i, j, textNodeContext, clonedContext;
446
+ var _this = this;
447
+ return __generator(this, function (_a) {
448
+ switch (_a.label) {
449
+ case 0:
450
+ getAllTemplates = function (top, template, mode) {
451
+ var templates = [];
452
+ for (var _i = 0, _a = top.childNodes.filter(function (c) { return c.nodeType == constants_1.DOM_ELEMENT_NODE && _this.isXsltElement(c, 'template'); }); _i < _a.length; _i++) {
453
+ var element = _a[_i];
454
+ // TODO: Remember why this logic was here.
455
+ // In the past the idea was to avoid executing the same matcher repeatedly,
456
+ // but this proved to be a *terrible* idea some time later.
457
+ // Will keep this code for a few more versions, then remove it.
458
+ /* const templateAncestor = template.getAncestorByLocalName('template');
459
+ if (templateAncestor === undefined) {
460
+ continue;
461
+ }
462
+
463
+ if (templateAncestor.id === element.id) {
464
+ continue;
465
+ } */
466
+ if (!mode || element.getAttributeValue('mode') === mode) {
467
+ templates.push(element);
468
+ }
469
+ }
470
+ return templates;
471
+ };
472
+ select = (0, dom_1.xmlGetAttribute)(template, 'select');
473
+ nodes = [];
474
+ if (select) {
475
+ nodes = this.xPath.xPathEval(select, context).nodeSetValue();
476
+ }
477
+ else {
478
+ nodes = context.nodeList[context.position].childNodes;
479
+ }
480
+ mode = (0, dom_1.xmlGetAttribute)(template, 'mode');
481
+ top = template.ownerDocument.documentElement;
482
+ templates = getAllTemplates(top, template, mode);
483
+ modifiedContext = context.clone(nodes);
484
+ i = 0;
485
+ _a.label = 1;
486
+ case 1:
487
+ if (!(i < templates.length)) return [3 /*break*/, 7];
488
+ j = 0;
489
+ _a.label = 2;
490
+ case 2:
491
+ if (!(j < modifiedContext.contextSize())) return [3 /*break*/, 6];
492
+ if (!(modifiedContext.nodeList[j].nodeType === constants_1.DOM_TEXT_NODE)) return [3 /*break*/, 3];
493
+ textNodeContext = context.clone([modifiedContext.nodeList[j]], undefined, 0, undefined);
494
+ // TODO: verify if it is okay to pass the own text node as template.
495
+ this.commonLogicTextNode(textNodeContext, modifiedContext.nodeList[j], output);
496
+ return [3 /*break*/, 5];
497
+ case 3:
498
+ clonedContext = modifiedContext.clone([modifiedContext.nodeList[j]], undefined, 0, undefined);
499
+ clonedContext.inApplyTemplates = true;
500
+ // The output depth should be restarted, since
501
+ // another template is being applied from this point.
502
+ clonedContext.outputDepth = 0;
503
+ return [4 /*yield*/, this.xsltProcessContext(clonedContext, templates[i], output)];
504
+ case 4:
505
+ _a.sent();
506
+ _a.label = 5;
507
+ case 5:
508
+ ++j;
509
+ return [3 /*break*/, 2];
510
+ case 6:
511
+ ++i;
512
+ return [3 /*break*/, 1];
513
+ case 7: return [2 /*return*/];
514
+ }
515
+ });
516
+ });
517
+ };
518
+ /**
519
+ * Implements `xsl:attribute`.
520
+ * @param context The Expression Context.
521
+ * @param template The template.
522
+ * @param output The output. Only used if there's no corresponding output node already defined.
523
+ * @protected
524
+ */
525
+ Xslt.prototype.xsltAttribute = function (context, template, output) {
526
+ return __awaiter(this, void 0, void 0, function () {
527
+ var nameExpr, name, documentFragment, value, sourceNode, parentSourceNode, outputNode, sourceRootNode, newRootNode;
528
+ return __generator(this, function (_a) {
529
+ switch (_a.label) {
530
+ case 0:
531
+ nameExpr = (0, dom_1.xmlGetAttribute)(template, 'name');
532
+ name = this.xsltAttributeValue(nameExpr, context);
533
+ documentFragment = (0, dom_1.domCreateDocumentFragment)(this.outputDocument);
534
+ return [4 /*yield*/, this.xsltChildNodes(context, template, documentFragment)];
535
+ case 1:
536
+ _a.sent();
537
+ value = (0, dom_1.xmlValue2)(documentFragment);
538
+ if (output && output.nodeType === constants_1.DOM_DOCUMENT_FRAGMENT_NODE) {
539
+ (0, dom_1.domSetTransformedAttribute)(output, name, value);
540
+ }
541
+ else {
542
+ sourceNode = context.nodeList[context.position];
543
+ parentSourceNode = sourceNode.parentNode;
544
+ outputNode = sourceNode.outputNode;
545
+ // At this point, the output node should exist.
546
+ // If not, a new node is created.
547
+ if (outputNode === null || outputNode === undefined) {
548
+ outputNode = new dom_1.XNode(sourceNode.nodeType, sourceNode.nodeName, sourceNode.nodeValue, context.outputNodeList[context.outputPosition], sourceNode.namespaceUri);
549
+ sourceNode.outputNode = outputNode;
550
+ }
551
+ // Corner case:
552
+ // It can happen here that we don't have the root node set.
553
+ // In this case we need to append a copy of the root
554
+ // source node to receive the attribute.
555
+ if (outputNode.localName === '#document') {
556
+ sourceRootNode = context.root.childNodes[0];
557
+ newRootNode = (0, dom_1.domCreateElement)(this.outputDocument, sourceRootNode.nodeName);
558
+ newRootNode.transformedNodeName = sourceRootNode.nodeName;
559
+ newRootNode.transformedLocalName = sourceRootNode.localName;
560
+ (0, dom_1.domAppendTransformedChild)(outputNode, newRootNode);
561
+ outputNode = newRootNode;
562
+ parentSourceNode = newRootNode;
563
+ }
564
+ // If the parent transformation is something like `xsl:element`, we should
565
+ // add a copy of the attribute to this element.
566
+ (0, dom_1.domSetTransformedAttribute)(outputNode, name, value);
567
+ if (sourceNode.nodeType === constants_1.DOM_ATTRIBUTE_NODE) {
568
+ sourceNode.transformedNodeType = constants_1.DOM_ATTRIBUTE_NODE;
569
+ sourceNode.transformedNodeName = name;
570
+ sourceNode.transformedNodeValue = value;
571
+ }
572
+ // Some operations start by the tag attributes, and not by the tag itself.
573
+ // When this is the case, the output node is not set yet, so
574
+ // we add the transformed attributes into the original tag.
575
+ if (parentSourceNode && parentSourceNode.outputNode) {
576
+ (0, dom_1.domSetTransformedAttribute)(parentSourceNode.outputNode, name, value);
577
+ }
578
+ }
579
+ return [2 /*return*/];
580
+ }
581
+ });
582
+ });
583
+ };
584
+ /**
585
+ * Implements `xsl:choose`, its child nodes `xsl:when`, and
586
+ * `xsl:otherwise`.
587
+ * @param context The Expression Context.
588
+ * @param template The template.
589
+ * @param output The output. Only used if there's no corresponding output node already defined.
590
+ */
591
+ Xslt.prototype.xsltChoose = function (context, template, output) {
592
+ return __awaiter(this, void 0, void 0, function () {
593
+ var _i, _a, childNode, test_2;
594
+ return __generator(this, function (_b) {
595
+ switch (_b.label) {
596
+ case 0:
597
+ _i = 0, _a = template.childNodes;
598
+ _b.label = 1;
599
+ case 1:
600
+ if (!(_i < _a.length)) return [3 /*break*/, 7];
601
+ childNode = _a[_i];
602
+ if (childNode.nodeType !== constants_1.DOM_ELEMENT_NODE) {
603
+ return [3 /*break*/, 6];
604
+ }
605
+ if (!this.isXsltElement(childNode, 'when')) return [3 /*break*/, 4];
606
+ test_2 = (0, dom_1.xmlGetAttribute)(childNode, 'test');
607
+ if (!this.xPath.xPathEval(test_2, context).booleanValue()) return [3 /*break*/, 3];
608
+ return [4 /*yield*/, this.xsltChildNodes(context, childNode, output)];
609
+ case 2:
610
+ _b.sent();
611
+ return [3 /*break*/, 7];
612
+ case 3: return [3 /*break*/, 6];
613
+ case 4:
614
+ if (!this.isXsltElement(childNode, 'otherwise')) return [3 /*break*/, 6];
615
+ return [4 /*yield*/, this.xsltChildNodes(context, childNode, output)];
616
+ case 5:
617
+ _b.sent();
618
+ return [3 /*break*/, 7];
619
+ case 6:
620
+ _i++;
621
+ return [3 /*break*/, 1];
622
+ case 7: return [2 /*return*/];
623
+ }
624
+ });
625
+ });
626
+ };
627
+ /**
628
+ * Implements `xsl:copy` for all node types.
629
+ * @param {XNode} destination the node being copied to, part of output document.
630
+ * @param {XNode} source the node being copied, part in input document.
631
+ * @returns {XNode|null} If an element node was created, the element node. Otherwise, null.
632
+ */
633
+ Xslt.prototype.xsltCopy = function (destination, source) {
634
+ if (source.nodeType == constants_1.DOM_ELEMENT_NODE) {
635
+ var node = (0, dom_1.domCreateElement)(this.outputDocument, source.nodeName);
636
+ node.transformedNodeName = source.nodeName;
637
+ if (source.namespaceUri !== null && source.namespaceUri !== undefined) {
638
+ (0, dom_1.domSetTransformedAttribute)(node, 'xmlns', source.namespaceUri);
639
+ }
640
+ (0, dom_1.domAppendTransformedChild)(destination, node);
641
+ return node;
642
+ }
643
+ if (source.nodeType == constants_1.DOM_TEXT_NODE) {
644
+ var node = (0, dom_1.domCreateTransformedTextNode)(this.outputDocument, source.nodeValue);
645
+ (0, dom_1.domAppendTransformedChild)(destination, node);
646
+ }
647
+ else if (source.nodeType == constants_1.DOM_CDATA_SECTION_NODE) {
648
+ var node = (0, dom_1.domCreateCDATASection)(this.outputDocument, source.nodeValue);
649
+ (0, dom_1.domAppendTransformedChild)(destination, node);
650
+ }
651
+ else if (source.nodeType == constants_1.DOM_COMMENT_NODE) {
652
+ var node = (0, dom_1.domCreateComment)(this.outputDocument, source.nodeValue);
653
+ (0, dom_1.domAppendTransformedChild)(destination, node);
654
+ }
655
+ else if (source.nodeType == constants_1.DOM_ATTRIBUTE_NODE) {
656
+ (0, dom_1.domSetTransformedAttribute)(destination, source.nodeName, source.nodeValue);
657
+ }
658
+ return null;
659
+ };
660
+ /**
661
+ * Implements `xsl:copy-of` for node-set values of the select
662
+ * expression. Recurses down the source node tree, which is part of
663
+ * the input document.
664
+ * @param {XNode} destination the node being copied to, part of output document.
665
+ * @param {XNode} source the node being copied, part in input document.
666
+ */
667
+ Xslt.prototype.xsltCopyOf = function (destination, source) {
668
+ if (source.nodeType == constants_1.DOM_DOCUMENT_FRAGMENT_NODE || source.nodeType == constants_1.DOM_DOCUMENT_NODE) {
669
+ for (var i = 0; i < source.childNodes.length; ++i) {
670
+ this.xsltCopyOf(destination, source.childNodes[i]);
671
+ }
672
+ }
673
+ else {
674
+ var node = this.xsltCopy(destination, source);
675
+ if (node) {
676
+ for (var i = 0; i < source.childNodes.length; ++i) {
677
+ this.xsltCopyOf(node, source.childNodes[i]);
678
+ }
679
+ }
680
+ }
681
+ };
682
+ /**
683
+ * Implements `xsl:for-each`.
684
+ * @param context The Expression Context.
685
+ * @param template The template.
686
+ * @param output The output.
687
+ */
688
+ Xslt.prototype.xsltForEach = function (context, template, output) {
689
+ return __awaiter(this, void 0, void 0, function () {
690
+ var select, nodes, sortContext, nodesWithParent, i;
691
+ return __generator(this, function (_a) {
692
+ switch (_a.label) {
693
+ case 0:
694
+ select = (0, dom_1.xmlGetAttribute)(template, 'select');
695
+ nodes = this.xPath.xPathEval(select, context).nodeSetValue();
696
+ if (nodes.length === 0) {
697
+ return [2 /*return*/];
698
+ }
699
+ sortContext = context.clone(nodes);
700
+ this.xsltSort(sortContext, template);
701
+ nodesWithParent = sortContext.nodeList.filter(function (n) { return n.parentNode !== null && n.parentNode !== undefined; });
702
+ if (nodesWithParent.length <= 0) {
703
+ throw new Error('Nodes with no parents defined.');
704
+ }
705
+ i = 0;
706
+ _a.label = 1;
707
+ case 1:
708
+ if (!(i < sortContext.contextSize())) return [3 /*break*/, 4];
709
+ return [4 /*yield*/, this.xsltChildNodes(sortContext.clone(sortContext.nodeList, undefined, i), template, output)];
710
+ case 2:
711
+ _a.sent();
712
+ _a.label = 3;
713
+ case 3:
714
+ ++i;
715
+ return [3 /*break*/, 1];
716
+ case 4: return [2 /*return*/];
717
+ }
718
+ });
719
+ });
720
+ };
721
+ /**
722
+ * Implements `xsl:include`.
723
+ * @param context The Expression Context.
724
+ * @param template The template.
725
+ * @param output The output.
726
+ */
727
+ Xslt.prototype.xsltInclude = function (context, template, output) {
728
+ return __awaiter(this, void 0, void 0, function () {
729
+ var hrefAttributeFind, hrefAttribute, fetchTest, fetchResponse, includedXslt;
730
+ return __generator(this, function (_a) {
731
+ switch (_a.label) {
732
+ case 0:
733
+ // We need to test here whether `window.fetch` is available or not.
734
+ // If it is a browser environemnt, it should be.
735
+ // Otherwise, we will need to import an equivalent library, like 'node-fetch'.
736
+ if (!global.globalThis.fetch) {
737
+ global.globalThis.fetch = node_fetch_1.default;
738
+ global.globalThis.Headers = node_fetch_1.Headers;
739
+ global.globalThis.Request = node_fetch_1.Request;
740
+ global.globalThis.Response = node_fetch_1.Response;
741
+ }
742
+ hrefAttributeFind = template.childNodes.filter(function (n) { return n.nodeName === 'href'; });
743
+ if (hrefAttributeFind.length <= 0) {
744
+ throw new Error('<xsl:include> with no href attribute defined.');
745
+ }
746
+ hrefAttribute = hrefAttributeFind[0];
747
+ return [4 /*yield*/, global.globalThis.fetch(hrefAttribute.nodeValue)];
748
+ case 1:
749
+ fetchTest = _a.sent();
750
+ return [4 /*yield*/, fetchTest.text()];
751
+ case 2:
752
+ fetchResponse = _a.sent();
753
+ includedXslt = this.xmlParser.xmlParse(fetchResponse);
754
+ return [4 /*yield*/, this.xsltChildNodes(context, includedXslt.childNodes[0], output)];
755
+ case 3:
756
+ _a.sent();
757
+ return [2 /*return*/];
758
+ }
759
+ });
760
+ });
761
+ };
762
+ /**
763
+ * Orders the current node list in the input context according to the
764
+ * sort order specified by xsl:sort child nodes of the current
765
+ * template node. This happens before the operation specified by the
766
+ * current template node is executed.
767
+ * @param context The expression context.
768
+ * @param template The template node.
769
+ * @todo case-order is not implemented.
770
+ */
771
+ Xslt.prototype.xsltSort = function (context, template) {
772
+ var sort = [];
773
+ for (var _i = 0, _a = template.childNodes; _i < _a.length; _i++) {
774
+ var childNode = _a[_i];
775
+ if (childNode.nodeType == constants_1.DOM_ELEMENT_NODE && this.isXsltElement(childNode, 'sort')) {
776
+ var select = (0, dom_1.xmlGetAttribute)(childNode, 'select');
777
+ var expression = this.xPath.xPathParse(select);
778
+ var type = (0, dom_1.xmlGetAttribute)(childNode, 'data-type') || 'text';
779
+ var order = (0, dom_1.xmlGetAttribute)(childNode, 'order') || 'ascending';
780
+ sort.push({
781
+ expr: expression,
782
+ type: type,
783
+ order: order
784
+ });
785
+ }
786
+ }
787
+ this.xPath.xPathSort(context, sort);
788
+ };
789
+ /**
790
+ * Implements `<xsl:stylesheet>` and `<xsl:transform>`, and its corresponding
791
+ * validations.
792
+ * @param template The `<xsl:stylesheet>` or `<xsl:transform>` node.
793
+ * @param context The Expression Context.
794
+ * @param output The output XML.
795
+ */
796
+ Xslt.prototype.xsltTransformOrStylesheet = function (template, context, output) {
797
+ return __awaiter(this, void 0, void 0, function () {
798
+ var _i, _a, stylesheetAttribute;
799
+ return __generator(this, function (_b) {
800
+ switch (_b.label) {
801
+ case 0:
802
+ for (_i = 0, _a = template.childNodes.filter(function (n) { return n.nodeType === constants_1.DOM_ATTRIBUTE_NODE; }); _i < _a.length; _i++) {
803
+ stylesheetAttribute = _a[_i];
804
+ switch (stylesheetAttribute.nodeName) {
805
+ case 'version':
806
+ this.version = stylesheetAttribute.nodeValue;
807
+ if (!['1.0', '2.0', '3.0'].includes(this.version)) {
808
+ throw new Error("XSLT version not defined or invalid. Actual resolved version: ".concat(this.version || '(none)', "."));
809
+ }
810
+ context.xsltVersion = this.version;
811
+ break;
812
+ default:
813
+ if (stylesheetAttribute.prefix === 'xmlns') {
814
+ context.knownNamespaces[stylesheetAttribute.localName] = stylesheetAttribute.nodeValue;
815
+ }
816
+ break;
817
+ }
818
+ }
819
+ return [4 /*yield*/, this.xsltChildNodes(context, template, output)];
820
+ case 1:
821
+ _b.sent();
822
+ return [2 /*return*/];
823
+ }
824
+ });
825
+ });
826
+ };
827
+ /**
828
+ * Evaluates a variable or parameter and set it in the current input
829
+ * context. Implements `xsl:variable`, `xsl:param`, and `xsl:with-param`.
830
+ *
831
+ * @param context The expression context.
832
+ * @param template The template node.
833
+ * @param override flag that defines if the value computed here
834
+ * overrides the one already in the input context if that is the
835
+ * case. I.e. decides if this is a default value or a local
836
+ * value. `xsl:variable` and `xsl:with-param` override; `xsl:param` doesn't.
837
+ */
838
+ Xslt.prototype.xsltVariable = function (context, template, override) {
839
+ return __awaiter(this, void 0, void 0, function () {
840
+ var name, select, value, nonAttributeChildren, fragment, parameterValue, filteredParameter;
841
+ return __generator(this, function (_a) {
842
+ switch (_a.label) {
843
+ case 0:
844
+ name = (0, dom_1.xmlGetAttribute)(template, 'name');
845
+ select = (0, dom_1.xmlGetAttribute)(template, 'select');
846
+ nonAttributeChildren = template.childNodes.filter(function (n) { return n.nodeType !== constants_1.DOM_ATTRIBUTE_NODE; });
847
+ if (!(nonAttributeChildren.length > 0)) return [3 /*break*/, 2];
848
+ fragment = (0, dom_1.domCreateDocumentFragment)(template.ownerDocument);
849
+ return [4 /*yield*/, this.xsltChildNodes(context, template, fragment)];
850
+ case 1:
851
+ _a.sent();
852
+ value = new values_1.NodeSetValue([fragment]);
853
+ return [3 /*break*/, 3];
854
+ case 2:
855
+ if (select) {
856
+ value = this.xPath.xPathEval(select, context);
857
+ }
858
+ else {
859
+ parameterValue = '';
860
+ filteredParameter = this.options.parameters.filter(function (p) { return p.name === name; });
861
+ if (filteredParameter.length > 0) {
862
+ parameterValue = filteredParameter[0].value;
863
+ }
864
+ value = new values_1.StringValue(parameterValue);
865
+ }
866
+ _a.label = 3;
867
+ case 3:
868
+ if (override || !context.getVariable(name)) {
869
+ context.setVariable(name, value);
870
+ }
871
+ return [2 /*return*/];
872
+ }
873
+ });
874
+ });
875
+ };
876
+ /**
877
+ * Traverses the template node tree. Calls the main processing
878
+ * function with the current input context for every child node of the
879
+ * current template node.
880
+ * @param context Normally the Expression Context.
881
+ * @param template The XSL-T definition.
882
+ * @param output If set, the output where the transformation should occur.
883
+ */
884
+ Xslt.prototype.xsltChildNodes = function (context, template, output) {
885
+ return __awaiter(this, void 0, void 0, function () {
886
+ var contextClone, i;
887
+ return __generator(this, function (_a) {
888
+ switch (_a.label) {
889
+ case 0:
890
+ contextClone = context.clone();
891
+ i = 0;
892
+ _a.label = 1;
893
+ case 1:
894
+ if (!(i < template.childNodes.length)) return [3 /*break*/, 4];
895
+ return [4 /*yield*/, this.xsltProcessContext(contextClone, template.childNodes[i], output)];
896
+ case 2:
897
+ _a.sent();
898
+ _a.label = 3;
899
+ case 3:
900
+ ++i;
901
+ return [3 /*break*/, 1];
902
+ case 4: return [2 /*return*/];
903
+ }
904
+ });
905
+ });
906
+ };
907
+ /**
908
+ * This logic is used in two different places:
909
+ * - `xsltPassThrough`, if the template asks this library to write a text node;
910
+ * - `xsltProcessContext`, `apply-templates` operation, when the current node is text.
911
+ * @param context The Expression Context.
912
+ * @param template The template, that contains the node value to be written.
913
+ * @param output The output.
914
+ */
915
+ Xslt.prototype.commonLogicTextNode = function (context, template, output) {
916
+ if (output && output.nodeType === constants_1.DOM_DOCUMENT_FRAGMENT_NODE) {
917
+ var node = (0, dom_1.domCreateTransformedTextNode)(this.outputDocument, template.nodeValue);
918
+ (0, dom_1.domAppendTransformedChild)(output, node);
919
+ }
920
+ else {
921
+ var textNodeList = context.outputNodeList[context.outputPosition].transformedChildNodes.filter(function (n) { return n.nodeType === constants_1.DOM_TEXT_NODE; });
922
+ if (textNodeList.length > 0) {
923
+ var node = textNodeList[0];
924
+ node.transformedNodeValue = template.nodeValue;
925
+ }
926
+ else {
927
+ var node = (0, dom_1.domCreateTransformedTextNode)(this.outputDocument, template.nodeValue);
928
+ node.transformedParentNode = context.outputNodeList[context.outputPosition];
929
+ (0, dom_1.domAppendTransformedChild)(context.outputNodeList[context.outputPosition], node);
930
+ }
931
+ }
932
+ };
933
+ /**
934
+ * Passes template text to the output. The current template node does
935
+ * not specify an XSL-T operation and therefore is appended to the
936
+ * output with all its attributes. Then continues traversing the
937
+ * template node tree.
938
+ * @param context The Expression Context.
939
+ * @param template The XSLT stylesheet or transformation.
940
+ * @param output The output.
941
+ */
942
+ Xslt.prototype.xsltPassThrough = function (context, template, output) {
943
+ return __awaiter(this, void 0, void 0, function () {
944
+ var node, elementContext, newNode, transformedChildNodes, _i, transformedChildNodes_1, previouslyTransformedAttribute, name_2, value, transformedAttributes, _a, transformedAttributes_1, previouslyTransformedAttribute, name_3, value, templateAttributes, _b, templateAttributes_1, attribute, name_4, value, outputNode, clonedContext;
945
+ return __generator(this, function (_c) {
946
+ switch (_c.label) {
947
+ case 0:
948
+ if (!(template.nodeType == constants_1.DOM_TEXT_NODE)) return [3 /*break*/, 1];
949
+ if (this.xsltPassText(template)) {
950
+ this.commonLogicTextNode(context, template, output);
951
+ }
952
+ return [3 /*break*/, 5];
953
+ case 1:
954
+ if (!(template.nodeType == constants_1.DOM_ELEMENT_NODE)) return [3 /*break*/, 3];
955
+ node = void 0;
956
+ elementContext = context;
957
+ if (context.nodeList[context.position].nodeName === '#document') {
958
+ node = context.nodeList[context.position].childNodes.find(function (c) { return c.nodeName !== '#dtd-section'; });
959
+ elementContext = context.clone([node]);
960
+ }
961
+ else {
962
+ node = context.nodeList[context.position];
963
+ }
964
+ newNode = void 0;
965
+ if (node.outputNode === undefined || node.outputNode === null || context.outputDepth > 0) {
966
+ newNode = (0, dom_1.domCreateElement)(this.outputDocument, template.nodeName);
967
+ newNode.siblingPosition = node.siblingPosition;
968
+ if (context.outputDepth === 0) {
969
+ node.outputNode = newNode;
970
+ }
971
+ }
972
+ else {
973
+ newNode = node.outputNode;
974
+ }
975
+ newNode.transformedNodeName = template.nodeName;
976
+ newNode.transformedLocalName = template.localName;
977
+ transformedChildNodes = node.transformedChildNodes.filter(function (n) { return n.nodeType === constants_1.DOM_ATTRIBUTE_NODE; });
978
+ for (_i = 0, transformedChildNodes_1 = transformedChildNodes; _i < transformedChildNodes_1.length; _i++) {
979
+ previouslyTransformedAttribute = transformedChildNodes_1[_i];
980
+ name_2 = previouslyTransformedAttribute.transformedNodeName;
981
+ value = previouslyTransformedAttribute.transformedNodeValue;
982
+ (0, dom_1.domSetTransformedAttribute)(newNode, name_2, value);
983
+ }
984
+ transformedAttributes = node.childNodes.filter(function (n) { return n.nodeType === constants_1.DOM_ATTRIBUTE_NODE && n.transformedNodeName; });
985
+ for (_a = 0, transformedAttributes_1 = transformedAttributes; _a < transformedAttributes_1.length; _a++) {
986
+ previouslyTransformedAttribute = transformedAttributes_1[_a];
987
+ name_3 = previouslyTransformedAttribute.transformedNodeName;
988
+ value = previouslyTransformedAttribute.transformedNodeValue;
989
+ (0, dom_1.domSetTransformedAttribute)(newNode, name_3, value);
990
+ }
991
+ templateAttributes = template.childNodes.filter(function (a) { return (a === null || a === void 0 ? void 0 : a.nodeType) === constants_1.DOM_ATTRIBUTE_NODE; });
992
+ for (_b = 0, templateAttributes_1 = templateAttributes; _b < templateAttributes_1.length; _b++) {
993
+ attribute = templateAttributes_1[_b];
994
+ name_4 = attribute.nodeName;
995
+ value = this.xsltAttributeValue(attribute.nodeValue, elementContext);
996
+ (0, dom_1.domSetTransformedAttribute)(newNode, name_4, value);
997
+ }
998
+ outputNode = context.outputNodeList[context.outputPosition];
999
+ (0, dom_1.domAppendTransformedChild)(outputNode, newNode);
1000
+ clonedContext = elementContext.cloneByOutput(outputNode.transformedChildNodes, outputNode.transformedChildNodes.length - 1, ++elementContext.outputDepth);
1001
+ return [4 /*yield*/, this.xsltChildNodes(clonedContext, template)];
1002
+ case 2:
1003
+ _c.sent();
1004
+ return [3 /*break*/, 5];
1005
+ case 3:
1006
+ // This applies also to the DOCUMENT_NODE of the XSL stylesheet,
1007
+ // so we don't have to treat it specially.
1008
+ return [4 /*yield*/, this.xsltChildNodes(context, template, output)];
1009
+ case 4:
1010
+ // This applies also to the DOCUMENT_NODE of the XSL stylesheet,
1011
+ // so we don't have to treat it specially.
1012
+ _c.sent();
1013
+ _c.label = 5;
1014
+ case 5: return [2 /*return*/];
1015
+ }
1016
+ });
1017
+ });
1018
+ };
1019
+ /**
1020
+ * Determines if a text node in the XSLT template document is to be
1021
+ * stripped according to XSLT whitespace stripping rules.
1022
+ * @see [XSLT], section 3.4.
1023
+ * @param template The XSLT template.
1024
+ * @returns TODO
1025
+ * @todo Whitespace stripping on the input document is
1026
+ * currently not implemented.
1027
+ */
1028
+ Xslt.prototype.xsltPassText = function (template) {
1029
+ if (!template.nodeValue.match(/^\s*$/)) {
1030
+ return true;
1031
+ }
1032
+ var element = template.parentNode;
1033
+ if (this.isXsltElement(element, 'text')) {
1034
+ return true;
1035
+ }
1036
+ while (element && element.nodeType == constants_1.DOM_ELEMENT_NODE) {
1037
+ var xmlspace = (0, dom_1.domGetAttributeValue)(element, 'xml:space');
1038
+ if (xmlspace) {
1039
+ if (xmlspace == 'default') {
1040
+ return false;
1041
+ }
1042
+ if (xmlspace == 'preserve') {
1043
+ return true;
1044
+ }
1045
+ }
1046
+ element = element.parentNode;
1047
+ }
1048
+ return false;
1049
+ };
1050
+ Xslt.prototype.findAttributeInContext = function (attributeName, context) {
1051
+ return context.nodeList[context.position].childNodes.find(function (a) { return a.nodeType === constants_1.DOM_ATTRIBUTE_NODE && a.nodeName === attributeName; });
1052
+ };
1053
+ /**
1054
+ * Evaluates an XSL-T attribute value template. Attribute value
1055
+ * templates are attributes on XSL-T elements that contain XPath
1056
+ * expressions in braces {}. The XSL-T expressions are evaluated in
1057
+ * the current input context.
1058
+ * @param value TODO
1059
+ * @param context TODO
1060
+ * @returns TODO
1061
+ */
1062
+ Xslt.prototype.xsltAttributeValue = function (value, context) {
1063
+ var parts = value.split('{');
1064
+ if (parts.length === 1) {
1065
+ return value;
1066
+ }
1067
+ var ret = '';
1068
+ for (var i = 0; i < parts.length; ++i) {
1069
+ var rp = parts[i].split('}');
1070
+ if (rp.length != 2) {
1071
+ // first literal part of the value
1072
+ ret += parts[i];
1073
+ continue;
1074
+ }
1075
+ var val = this.xPath.xPathEval(rp[0], context).stringValue();
1076
+ ret += val + rp[1];
1077
+ }
1078
+ return ret;
1079
+ };
1080
+ /**
1081
+ * Evaluates an XPath expression in the current input context as a
1082
+ * match.
1083
+ * @see [XSLT] section 5.2, paragraph 1
1084
+ * @param match TODO
1085
+ * @param context The Expression Context.
1086
+ * @param axis The XPath axis. Used when the match does not start with the parent.
1087
+ * @returns {XNode[]} A list of the found nodes.
1088
+ */
1089
+ Xslt.prototype.xsltMatch = function (match, context, axis) {
1090
+ var expression = this.xPath.xPathParse(match, axis);
1091
+ return this.matchResolver.expressionMatch(expression, context);
1092
+ };
1093
+ /**
1094
+ * Sets parameters defined by xsl:with-param child nodes of the
1095
+ * current template node, in the current input context. This happens
1096
+ * before the operation specified by the current template node is
1097
+ * executed.
1098
+ * @param context The Expression Context.
1099
+ * @param template The template node.
1100
+ */
1101
+ Xslt.prototype.xsltWithParam = function (context, template) {
1102
+ return __awaiter(this, void 0, void 0, function () {
1103
+ var _i, _a, childNode;
1104
+ return __generator(this, function (_b) {
1105
+ switch (_b.label) {
1106
+ case 0:
1107
+ _i = 0, _a = template.childNodes;
1108
+ _b.label = 1;
1109
+ case 1:
1110
+ if (!(_i < _a.length)) return [3 /*break*/, 4];
1111
+ childNode = _a[_i];
1112
+ if (!(childNode.nodeType === constants_1.DOM_ELEMENT_NODE && this.isXsltElement(childNode, 'with-param'))) return [3 /*break*/, 3];
1113
+ return [4 /*yield*/, this.xsltVariable(context, childNode, true)];
1114
+ case 2:
1115
+ _b.sent();
1116
+ _b.label = 3;
1117
+ case 3:
1118
+ _i++;
1119
+ return [3 /*break*/, 1];
1120
+ case 4: return [2 /*return*/];
1121
+ }
1122
+ });
1123
+ });
1124
+ };
1125
+ // Test if the given element is an XSLT element, optionally the one with the given name
1126
+ Xslt.prototype.isXsltElement = function (element, opt_wantedName) {
1127
+ if (opt_wantedName && element.localName != opt_wantedName)
1128
+ return false;
1129
+ if (element.namespaceUri)
1130
+ return element.namespaceUri === 'http://www.w3.org/1999/XSL/Transform';
1131
+ return element.prefix === 'xsl'; // backwards compatibility with earlier versions of xslt-processor
1132
+ };
1133
+ return Xslt;
1134
+ }());
1135
+ exports.Xslt = Xslt;
1080
1136
  //# sourceMappingURL=xslt.js.map