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