xslt-processor 3.3.1 → 4.0.0

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