xslt-processor 2.3.1 → 3.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.
- package/README.md +29 -1
- package/package.json +4 -4
- package/umd/xslt/xslt.d.ts +18 -10
- package/umd/xslt-processor.js +2 -2
- package/umd/xslt-processor.js.map +1 -1
- package/xslt/xslt.d.ts +18 -10
- package/xslt/xslt.js +711 -442
- package/xslt/xslt.js.map +1 -1
package/xslt/xslt.js
CHANGED
|
@@ -8,8 +8,68 @@
|
|
|
8
8
|
// remaining XSLT features.
|
|
9
9
|
//
|
|
10
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
|
+
};
|
|
11
70
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
71
|
exports.Xslt = void 0;
|
|
72
|
+
var node_fetch_1 = __importStar(require("node-fetch"));
|
|
13
73
|
var dom_1 = require("../dom");
|
|
14
74
|
var xpath_1 = require("../xpath");
|
|
15
75
|
var constants_1 = require("../constants");
|
|
@@ -48,6 +108,7 @@ var Xslt = /** @class */ (function () {
|
|
|
48
108
|
parameters: []
|
|
49
109
|
}; }
|
|
50
110
|
this.xPath = new xpath_1.XPath();
|
|
111
|
+
this.xmlParser = new dom_1.XmlParser();
|
|
51
112
|
this.matchResolver = new match_resolver_1.MatchResolver();
|
|
52
113
|
this.options = {
|
|
53
114
|
cData: options.cData === true,
|
|
@@ -77,23 +138,33 @@ var Xslt = /** @class */ (function () {
|
|
|
77
138
|
* @returns the processed document, as XML text in a string.
|
|
78
139
|
*/
|
|
79
140
|
Xslt.prototype.xsltProcess = function (xmlDoc, stylesheet) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
+
});
|
|
95
167
|
});
|
|
96
|
-
return transformedOutputXml;
|
|
97
168
|
};
|
|
98
169
|
/**
|
|
99
170
|
* The main entry point of the XSL-T processor, as explained on the top of the file.
|
|
@@ -102,302 +173,363 @@ var Xslt = /** @class */ (function () {
|
|
|
102
173
|
* @param output If set, the output where the transformation should occur.
|
|
103
174
|
*/
|
|
104
175
|
Xslt.prototype.xsltProcessContext = function (context, template, output) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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];
|
|
137
226
|
}
|
|
138
|
-
|
|
139
|
-
|
|
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();
|
|
140
233
|
}
|
|
141
|
-
|
|
142
|
-
|
|
234
|
+
else {
|
|
235
|
+
nodes = context.nodeList[context.position].childNodes;
|
|
143
236
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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;
|
|
154
249
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
);
|
|
161
|
-
clonedContext_1.inApplyTemplates = true;
|
|
162
|
-
// The output depth should be restarted, since
|
|
163
|
-
// another template is being applied from this point.
|
|
164
|
-
clonedContext_1.outputDepth = 0;
|
|
165
|
-
this.xsltProcessContext(clonedContext_1, templates[i], output);
|
|
250
|
+
if (templateAncestor.id === element.id) {
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
if (!mode || element.getAttributeValue('mode') === mode) {
|
|
254
|
+
templates.push(element);
|
|
166
255
|
}
|
|
167
256
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
(
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
(0, dom_1.domSetTransformedAttribute)(parentSourceNode.outputNode, name_1, value);
|
|
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);
|
|
210
298
|
}
|
|
211
299
|
else {
|
|
212
|
-
|
|
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
|
+
}
|
|
213
334
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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 &&
|
|
226
350
|
this.isXsltElement(childNode, 'template') &&
|
|
227
|
-
(0, dom_1.domGetAttributeValue)(childNode, 'name') == name_1)
|
|
228
|
-
|
|
229
|
-
|
|
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);
|
|
230
395
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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];
|
|
258
481
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
var decimalSeparator = (0, dom_1.xmlGetAttribute)(template, 'decimal-separator');
|
|
268
|
-
var groupingSeparator = (0, dom_1.xmlGetAttribute)(template, 'grouping-separator');
|
|
269
|
-
var infinity = (0, dom_1.xmlGetAttribute)(template, 'infinity');
|
|
270
|
-
var minusSign = (0, dom_1.xmlGetAttribute)(template, 'minus-sign');
|
|
271
|
-
var naN = (0, dom_1.xmlGetAttribute)(template, 'NaN');
|
|
272
|
-
var percent = (0, dom_1.xmlGetAttribute)(template, 'percent');
|
|
273
|
-
var perMille = (0, dom_1.xmlGetAttribute)(template, 'per-mille');
|
|
274
|
-
var zeroDigit = (0, dom_1.xmlGetAttribute)(template, 'zero-digit');
|
|
275
|
-
var digit = (0, dom_1.xmlGetAttribute)(template, 'digit');
|
|
276
|
-
var patternSeparator = (0, dom_1.xmlGetAttribute)(template, 'pattern-separator');
|
|
277
|
-
this.decimalFormatSettings = {
|
|
278
|
-
name: name_1 || this.decimalFormatSettings.name,
|
|
279
|
-
decimalSeparator: decimalSeparator || this.decimalFormatSettings.decimalSeparator,
|
|
280
|
-
groupingSeparator: groupingSeparator || this.decimalFormatSettings.groupingSeparator,
|
|
281
|
-
infinity: infinity || this.decimalFormatSettings.infinity,
|
|
282
|
-
minusSign: minusSign || this.decimalFormatSettings.minusSign,
|
|
283
|
-
naN: naN || this.decimalFormatSettings.naN,
|
|
284
|
-
percent: percent || this.decimalFormatSettings.percent,
|
|
285
|
-
perMille: perMille || this.decimalFormatSettings.perMille,
|
|
286
|
-
zeroDigit: zeroDigit || this.decimalFormatSettings.zeroDigit,
|
|
287
|
-
digit: digit || this.decimalFormatSettings.digit,
|
|
288
|
-
patternSeparator: patternSeparator || this.decimalFormatSettings.patternSeparator
|
|
289
|
-
};
|
|
290
|
-
context.decimalFormatSettings = this.decimalFormatSettings;
|
|
291
|
-
break;
|
|
292
|
-
case 'element':
|
|
293
|
-
nameExpr = (0, dom_1.xmlGetAttribute)(template, 'name');
|
|
294
|
-
name_1 = this.xsltAttributeValue(nameExpr, context);
|
|
295
|
-
node = (0, dom_1.domCreateElement)(this.outputDocument, name_1);
|
|
296
|
-
node.transformedNodeName = name_1;
|
|
297
|
-
(0, dom_1.domAppendTransformedChild)(context.outputNodeList[context.outputPosition], node);
|
|
298
|
-
var clonedContext = context.clone(undefined, [node], undefined, 0);
|
|
299
|
-
this.xsltChildNodes(clonedContext, template, node);
|
|
300
|
-
break;
|
|
301
|
-
case 'fallback':
|
|
302
|
-
throw new Error("not implemented: ".concat(template.localName));
|
|
303
|
-
case 'for-each':
|
|
304
|
-
this.xsltForEach(context, template, output);
|
|
305
|
-
break;
|
|
306
|
-
case 'if':
|
|
307
|
-
test_1 = (0, dom_1.xmlGetAttribute)(template, 'test');
|
|
308
|
-
if (this.xPath.xPathEval(test_1, context).booleanValue()) {
|
|
309
|
-
this.xsltChildNodes(context, template, output);
|
|
310
|
-
}
|
|
311
|
-
break;
|
|
312
|
-
case 'import':
|
|
313
|
-
throw new Error("not implemented: ".concat(template.localName));
|
|
314
|
-
case 'include':
|
|
315
|
-
throw new Error("not implemented: ".concat(template.localName));
|
|
316
|
-
case 'key':
|
|
317
|
-
throw new Error("not implemented: ".concat(template.localName));
|
|
318
|
-
case 'message':
|
|
319
|
-
throw new Error("not implemented: ".concat(template.localName));
|
|
320
|
-
case 'namespace-alias':
|
|
321
|
-
throw new Error("not implemented: ".concat(template.localName));
|
|
322
|
-
case 'number':
|
|
323
|
-
throw new Error("not implemented: ".concat(template.localName));
|
|
324
|
-
case 'otherwise':
|
|
325
|
-
throw "error if here: ".concat(template.localName);
|
|
326
|
-
case 'output':
|
|
327
|
-
this.outputMethod = (0, dom_1.xmlGetAttribute)(template, 'method');
|
|
328
|
-
this.outputOmitXmlDeclaration = (0, dom_1.xmlGetAttribute)(template, 'omit-xml-declaration');
|
|
329
|
-
break;
|
|
330
|
-
case 'param':
|
|
331
|
-
this.xsltVariable(context, template, false);
|
|
332
|
-
break;
|
|
333
|
-
case 'preserve-space':
|
|
334
|
-
throw new Error("not implemented: ".concat(template.localName));
|
|
335
|
-
case 'processing-instruction':
|
|
336
|
-
throw new Error("not implemented: ".concat(template.localName));
|
|
337
|
-
case 'sort':
|
|
338
|
-
this.xsltSort(context, template);
|
|
339
|
-
break;
|
|
340
|
-
case 'strip-space':
|
|
341
|
-
throw new Error("not implemented: ".concat(template.localName));
|
|
342
|
-
case 'stylesheet':
|
|
343
|
-
case 'transform':
|
|
344
|
-
this.xsltTransformOrStylesheet(template, context, output);
|
|
345
|
-
break;
|
|
346
|
-
case 'template':
|
|
347
|
-
// If `<xsl:template>` is executed outside `<xsl:apply-templates>`,
|
|
348
|
-
// only one match is accepted per level (or per context here).
|
|
349
|
-
if (!context.inApplyTemplates && context.baseTemplateMatched) {
|
|
350
|
-
break;
|
|
351
|
-
}
|
|
352
|
-
match = (0, dom_1.xmlGetAttribute)(template, 'match');
|
|
353
|
-
if (!match)
|
|
354
|
-
break;
|
|
355
|
-
// XPath doesn't have an axis to select "self and siblings", and
|
|
356
|
-
// the default axis is "child", so to select the correct children
|
|
357
|
-
// in relative path, we force a 'self-and-siblings' axis.
|
|
358
|
-
nodes = this.xsltMatch(match, context, 'self-and-siblings');
|
|
359
|
-
if (nodes.length > 0) {
|
|
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];
|
|
360
490
|
if (!context.inApplyTemplates) {
|
|
361
491
|
context.baseTemplateMatched = true;
|
|
362
492
|
}
|
|
363
|
-
|
|
364
|
-
this.xsltChildNodes(templateContext, template, output);
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
throw new Error("error if here: ".concat(template.localName));
|
|
397
|
-
|
|
398
|
-
throw new Error("error if here: ".concat(template.localName));
|
|
399
|
-
|
|
400
|
-
|
|
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
|
+
});
|
|
401
533
|
};
|
|
402
534
|
/**
|
|
403
535
|
* Implements `xsl:choose`, its child nodes `xsl:when`, and
|
|
@@ -407,25 +539,42 @@ var Xslt = /** @class */ (function () {
|
|
|
407
539
|
* @param output The output. Only used if there's no corresponding output node already defined.
|
|
408
540
|
*/
|
|
409
541
|
Xslt.prototype.xsltChoose = function (context, template, output) {
|
|
410
|
-
|
|
411
|
-
var childNode
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
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*/];
|
|
421
575
|
}
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
var outputNode = context.outputNodeList[context.outputPosition] || output;
|
|
425
|
-
this.xsltChildNodes(context, childNode, outputNode);
|
|
426
|
-
break;
|
|
427
|
-
}
|
|
428
|
-
}
|
|
576
|
+
});
|
|
577
|
+
});
|
|
429
578
|
};
|
|
430
579
|
/**
|
|
431
580
|
* Implements `xsl:copy` for all node types.
|
|
@@ -489,28 +638,78 @@ var Xslt = /** @class */ (function () {
|
|
|
489
638
|
* @param output The output.
|
|
490
639
|
*/
|
|
491
640
|
Xslt.prototype.xsltForEach = function (context, template, output) {
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
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
|
+
});
|
|
514
713
|
};
|
|
515
714
|
/**
|
|
516
715
|
* Orders the current node list in the input context according to the
|
|
@@ -547,24 +746,35 @@ var Xslt = /** @class */ (function () {
|
|
|
547
746
|
* @param output The output XML.
|
|
548
747
|
*/
|
|
549
748
|
Xslt.prototype.xsltTransformOrStylesheet = function (template, context, output) {
|
|
550
|
-
|
|
551
|
-
var
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
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
|
+
});
|
|
568
778
|
};
|
|
569
779
|
/**
|
|
570
780
|
* Evaluates a variable or parameter and set it in the current input
|
|
@@ -578,29 +788,42 @@ var Xslt = /** @class */ (function () {
|
|
|
578
788
|
* value. `xsl:variable` and `xsl:with-param` override; `xsl:param` doesn't.
|
|
579
789
|
*/
|
|
580
790
|
Xslt.prototype.xsltVariable = function (context, template, override) {
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
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
|
+
});
|
|
604
827
|
};
|
|
605
828
|
/**
|
|
606
829
|
* Traverses the template node tree. Calls the main processing
|
|
@@ -611,12 +834,27 @@ var Xslt = /** @class */ (function () {
|
|
|
611
834
|
* @param output If set, the output where the transformation should occur.
|
|
612
835
|
*/
|
|
613
836
|
Xslt.prototype.xsltChildNodes = function (context, template, output) {
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
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
|
+
});
|
|
620
858
|
};
|
|
621
859
|
/**
|
|
622
860
|
* This logic is used in two different places:
|
|
@@ -653,59 +891,74 @@ var Xslt = /** @class */ (function () {
|
|
|
653
891
|
* @param output The output.
|
|
654
892
|
*/
|
|
655
893
|
Xslt.prototype.xsltPassThrough = function (context, template, output) {
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
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*/];
|
|
677
959
|
}
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
newNode = node.outputNode;
|
|
681
|
-
}
|
|
682
|
-
newNode.transformedNodeName = template.nodeName;
|
|
683
|
-
newNode.transformedLocalName = template.localName;
|
|
684
|
-
// The node can have transformed attributes from previous transformations.
|
|
685
|
-
var transformedAttributes = node.transformedChildNodes.filter(function (n) { return n.nodeType === constants_1.DOM_ATTRIBUTE_NODE; });
|
|
686
|
-
for (var _i = 0, transformedAttributes_1 = transformedAttributes; _i < transformedAttributes_1.length; _i++) {
|
|
687
|
-
var previouslyTransformedAttribute = transformedAttributes_1[_i];
|
|
688
|
-
var name_2 = previouslyTransformedAttribute.transformedNodeName;
|
|
689
|
-
var value = previouslyTransformedAttribute.transformedNodeValue;
|
|
690
|
-
(0, dom_1.domSetTransformedAttribute)(newNode, name_2, value);
|
|
691
|
-
}
|
|
692
|
-
var templateAttributes = template.childNodes.filter(function (a) { return (a === null || a === void 0 ? void 0 : a.nodeType) === constants_1.DOM_ATTRIBUTE_NODE; });
|
|
693
|
-
for (var _a = 0, templateAttributes_1 = templateAttributes; _a < templateAttributes_1.length; _a++) {
|
|
694
|
-
var attribute = templateAttributes_1[_a];
|
|
695
|
-
var name_3 = attribute.nodeName;
|
|
696
|
-
var value = this.xsltAttributeValue(attribute.nodeValue, elementContext);
|
|
697
|
-
(0, dom_1.domSetTransformedAttribute)(newNode, name_3, value);
|
|
698
|
-
}
|
|
699
|
-
var outputNode = context.outputNodeList[context.outputPosition];
|
|
700
|
-
(0, dom_1.domAppendTransformedChild)(outputNode, newNode);
|
|
701
|
-
var clonedContext = elementContext.cloneByOutput(outputNode.transformedChildNodes, outputNode.transformedChildNodes.length - 1, ++elementContext.outputDepth);
|
|
702
|
-
this.xsltChildNodes(clonedContext, template, output);
|
|
703
|
-
}
|
|
704
|
-
else {
|
|
705
|
-
// This applies also to the DOCUMENT_NODE of the XSL stylesheet,
|
|
706
|
-
// so we don't have to treat it specially.
|
|
707
|
-
this.xsltChildNodes(context, template, output);
|
|
708
|
-
}
|
|
960
|
+
});
|
|
961
|
+
});
|
|
709
962
|
};
|
|
710
963
|
/**
|
|
711
964
|
* Determines if a text node in the XSLT template document is to be
|
|
@@ -790,12 +1043,28 @@ var Xslt = /** @class */ (function () {
|
|
|
790
1043
|
* @param template The template node.
|
|
791
1044
|
*/
|
|
792
1045
|
Xslt.prototype.xsltWithParam = function (context, template) {
|
|
793
|
-
|
|
794
|
-
var
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
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
|
+
});
|
|
799
1068
|
};
|
|
800
1069
|
// Test if the given element is an XSLT element, optionally the one with the given name
|
|
801
1070
|
Xslt.prototype.isXsltElement = function (element, opt_wantedName) {
|