xslt-processor 1.2.8 → 2.0.1
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 +37 -9
- package/dom/functions.d.ts +0 -7
- package/dom/functions.js +2 -164
- package/dom/functions.js.map +1 -1
- package/dom/index.d.ts +1 -0
- package/dom/index.js +1 -0
- package/dom/index.js.map +1 -1
- package/dom/util.d.ts +0 -4
- package/dom/util.js +1 -27
- package/dom/util.js.map +1 -1
- package/dom/xml-functions.d.ts +13 -2
- package/dom/xml-functions.js +59 -40
- package/dom/xml-functions.js.map +1 -1
- package/dom/xml-output-options.d.ts +1 -0
- package/dom/xml-parser.d.ts +47 -0
- package/dom/xml-parser.js +301 -0
- package/dom/xml-parser.js.map +1 -0
- package/index.d.ts +1 -1
- package/index.js +2 -2
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/umd/dom/functions.d.ts +0 -7
- package/umd/dom/index.d.ts +1 -0
- package/umd/dom/util.d.ts +0 -4
- package/umd/dom/xml-functions.d.ts +13 -2
- package/umd/dom/xml-output-options.d.ts +1 -0
- package/umd/dom/xml-parser.d.ts +47 -0
- package/umd/index.d.ts +1 -1
- package/umd/xpath/values/node-set-value.d.ts +1 -1
- package/umd/xslt/xslt.d.ts +3 -3
- package/umd/xslt-processor.js +2 -2
- package/umd/xslt-processor.js.map +1 -1
- package/xpath/expressions/binary-expr.js +2 -2
- package/xpath/expressions/binary-expr.js.map +1 -1
- package/xpath/functions/standard.js +1 -1
- package/xpath/functions/standard.js.map +1 -1
- package/xpath/values/node-set-value.d.ts +1 -1
- package/xpath/values/node-set-value.js +1 -1
- package/xpath/values/node-set-value.js.map +1 -1
- package/xpath/xpath.js +8 -8
- package/xslt/xslt.d.ts +3 -3
- package/xslt/xslt.js +7 -4
- package/xslt/xslt.js.map +1 -1
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ _A JavaScript XSLT processor without native library dependencies._
|
|
|
17
17
|
|
|
18
18
|
## How to
|
|
19
19
|
|
|
20
|
-
Install xslt-processor using npm or yarn:
|
|
20
|
+
Install xslt-processor using [npm](https://docs.npmjs.com/about-npm) or [yarn](https://yarnpkg.com):
|
|
21
21
|
|
|
22
22
|
```sh
|
|
23
23
|
npm install xslt-processor
|
|
@@ -27,18 +27,19 @@ npm install xslt-processor
|
|
|
27
27
|
yarn add xslt-processor
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
Within your ES2015+ code, import the `Xslt` class, the `
|
|
30
|
+
Within your ES2015+ code, import the `Xslt` class, the `XmlParser` class and use this way:
|
|
31
31
|
|
|
32
32
|
```js
|
|
33
|
-
import { Xslt,
|
|
33
|
+
import { Xslt, XmlParser } from 'xslt-processor'
|
|
34
34
|
|
|
35
35
|
// xmlString: string of xml file contents
|
|
36
36
|
// xsltString: string of xslt file contents
|
|
37
37
|
// outXmlString: output xml string.
|
|
38
38
|
const xslt = new Xslt();
|
|
39
|
+
const xmlParser = new XmlParser();
|
|
39
40
|
const outXmlString = xslt.xsltProcess(
|
|
40
|
-
xmlParse(xmlString),
|
|
41
|
-
xmlParse(xsltString)
|
|
41
|
+
xmlParser.xmlParse(xmlString),
|
|
42
|
+
xmlParser.xmlParse(xsltString)
|
|
42
43
|
);
|
|
43
44
|
```
|
|
44
45
|
|
|
@@ -67,13 +68,15 @@ You can pass an `options` object to `Xslt` class:
|
|
|
67
68
|
const options = {
|
|
68
69
|
escape: false,
|
|
69
70
|
selfClosingTags: true,
|
|
70
|
-
parameters: [{ name: 'myparam', value: '123' }]
|
|
71
|
+
parameters: [{ name: 'myparam', value: '123' }],
|
|
72
|
+
outputMethod: 'xml'
|
|
71
73
|
};
|
|
72
74
|
const xslt = new Xslt(options);
|
|
73
75
|
```
|
|
74
76
|
|
|
75
77
|
- `escape` (`boolean`, default `true`): replaces symbols like `<`, `>`, `&` and `"` by the corresponding [XML entities](https://www.tutorialspoint.com/xml/xml_character_entities.htm).
|
|
76
78
|
- `selfClosingTags` (`boolean`, default `true`): Self-closes tags that don't have inner elements, if `true`. For instance, `<test></test>` becomes `<test />`.
|
|
79
|
+
- `outputMethod` (`string`, default `xml`): Specifies the default output method. if `<xsl:output>` is declared in your XSLT file, this will be overridden.
|
|
77
80
|
- `parameters` (`array`, default `[]`): external parameters that you want to use.
|
|
78
81
|
- `name`: the parameter name;
|
|
79
82
|
- `namespaceUri` (optional): the namespace;
|
|
@@ -84,13 +87,32 @@ const xslt = new Xslt(options);
|
|
|
84
87
|
You can simply add a tag like this:
|
|
85
88
|
|
|
86
89
|
```html
|
|
87
|
-
<script type="application/javascript" src="https://www.unpkg.com/xslt-processor@
|
|
90
|
+
<script type="application/javascript" src="https://www.unpkg.com/xslt-processor@2.0.0/umd/xslt-processor.js"></script>
|
|
88
91
|
```
|
|
89
92
|
|
|
90
93
|
All the exports will live under `globalThis.XsltProcessor`. [See a usage example here](https://github.com/DesignLiquido/xslt-processor/blob/main/interactive-tests/xslt.html).
|
|
91
94
|
|
|
92
95
|
### Breaking Changes
|
|
93
96
|
|
|
97
|
+
#### Version 1
|
|
98
|
+
|
|
99
|
+
Until version 1.2.8, use like the example below:
|
|
100
|
+
|
|
101
|
+
```js
|
|
102
|
+
import { Xslt, xmlParse } from 'xslt-processor'
|
|
103
|
+
|
|
104
|
+
// xmlString: string of xml file contents
|
|
105
|
+
// xsltString: string of xslt file contents
|
|
106
|
+
// outXmlString: output xml string.
|
|
107
|
+
const xslt = new Xslt();
|
|
108
|
+
const outXmlString = xslt.xsltProcess(
|
|
109
|
+
xmlParse(xmlString),
|
|
110
|
+
xmlParse(xsltString)
|
|
111
|
+
);
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
#### Version 0
|
|
115
|
+
|
|
94
116
|
Until version 0.11.7, use like the example below:
|
|
95
117
|
|
|
96
118
|
```js
|
|
@@ -135,7 +157,6 @@ used. This DOM comes with a minimal XML parser that can be used to
|
|
|
135
157
|
generate a suitable DOM representation of the input documents if they
|
|
136
158
|
are present as text.
|
|
137
159
|
|
|
138
|
-
|
|
139
160
|
## Tests and usage examples
|
|
140
161
|
|
|
141
162
|
New tests are written in Jest an can be run by calling: `npm test`.
|
|
@@ -155,7 +176,14 @@ The DOM implementation is minimal so as to support the XSLT processing, and not
|
|
|
155
176
|
The implementation is all agnostic about namespaces. It just expects
|
|
156
177
|
XSLT elements to have tags that carry the `xsl:` prefix, but we disregard all namespace declaration for them.
|
|
157
178
|
|
|
158
|
-
There are a few nonstandard XPath functions.
|
|
179
|
+
[There are a few nonstandard XPath functions](https://github.com/search?q=repo%3ADesignLiquido%2Fxslt-processor%20ext-&type=code).
|
|
180
|
+
|
|
181
|
+
### HTML Conformance
|
|
182
|
+
|
|
183
|
+
HTML per se is not strict XML. Because of that, starting on version 2.0.0, this library handles HTML differently than XML:
|
|
184
|
+
|
|
185
|
+
- Tags like `<hr>`, `<link>` and `<meta>` don't need to be closed. The output for these tags doesn't close them (adding a `/` before the tag closes, or a corresponding close tag);
|
|
186
|
+
- This rule doesn't apply for XHTML, which is strict XML.
|
|
159
187
|
|
|
160
188
|
## References
|
|
161
189
|
|
package/dom/functions.d.ts
CHANGED
|
@@ -12,10 +12,3 @@ export declare function domCreateCDATASection(doc: XDocument, data: any): XNode;
|
|
|
12
12
|
export declare function domCreateComment(doc: any, text: any): any;
|
|
13
13
|
export declare function domCreateDocumentFragment(doc: XDocument): XNode;
|
|
14
14
|
export declare function domCreateDTDSection(doc: XDocument, data: any): XNode;
|
|
15
|
-
/**
|
|
16
|
-
* Parses the given XML string with our custom, JavaScript XML parser
|
|
17
|
-
* @param xml The XML String.
|
|
18
|
-
* @returns A XDocument.
|
|
19
|
-
* @author Steffen Meschkat <mesch@google.com>
|
|
20
|
-
*/
|
|
21
|
-
export declare function xmlParse(xml: string): XDocument;
|
package/dom/functions.js
CHANGED
|
@@ -1,26 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.xmlParse = exports.domCreateDTDSection = exports.domCreateDocumentFragment = exports.domCreateComment = exports.domCreateCDATASection = exports.domCreateElement = exports.domCreateTransformedTextNode = exports.domCreateTextNode = exports.domAppendTransformedChild = exports.domAppendChild = exports.domSetTransformedAttribute = exports.domSetAttribute = exports.domGetAttributeValue = void 0;
|
|
7
2
|
// Copyright 2023 Design Liquido
|
|
8
3
|
// Copyright 2018 Johannes Wilm
|
|
9
4
|
// Copyright 2005 Google Inc.
|
|
10
5
|
// All Rights Reserved
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
//
|
|
14
|
-
// An XML parse and a minimal DOM implementation that just supports
|
|
15
|
-
// the subset of the W3C DOM that is used in the XSLT implementation.
|
|
16
|
-
var he_1 = __importDefault(require("he"));
|
|
17
|
-
var util_1 = require("./util");
|
|
18
|
-
var xdocument_1 = require("./xdocument");
|
|
19
|
-
var xmltoken_1 = require("./xmltoken");
|
|
20
|
-
var XML10_TAGNAME_REGEXP = new RegExp("^(".concat(xmltoken_1.XML10_NAME, ")"));
|
|
21
|
-
var XML10_ATTRIBUTE_REGEXP = new RegExp(xmltoken_1.XML10_ATTRIBUTE, 'g');
|
|
22
|
-
var XML11_TAGNAME_REGEXP = new RegExp("^(".concat(xmltoken_1.XML11_NAME, ")"));
|
|
23
|
-
var XML11_ATTRIBUTE_REGEXP = new RegExp(xmltoken_1.XML11_ATTRIBUTE, 'g');
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.domCreateDTDSection = exports.domCreateDocumentFragment = exports.domCreateComment = exports.domCreateCDATASection = exports.domCreateElement = exports.domCreateTransformedTextNode = exports.domCreateTextNode = exports.domAppendTransformedChild = exports.domAppendChild = exports.domSetTransformedAttribute = exports.domSetAttribute = exports.domGetAttributeValue = void 0;
|
|
24
8
|
// Wrapper around DOM methods so we can condense their invocations.
|
|
25
9
|
function domGetAttributeValue(node, name) {
|
|
26
10
|
return node.getAttributeValue(name);
|
|
@@ -70,151 +54,5 @@ function domCreateDTDSection(doc, data) {
|
|
|
70
54
|
return doc.createDTDSection(data);
|
|
71
55
|
}
|
|
72
56
|
exports.domCreateDTDSection = domCreateDTDSection;
|
|
73
|
-
/**
|
|
74
|
-
* Parses the given XML string with our custom, JavaScript XML parser
|
|
75
|
-
* @param xml The XML String.
|
|
76
|
-
* @returns A XDocument.
|
|
77
|
-
* @author Steffen Meschkat <mesch@google.com>
|
|
78
|
-
*/
|
|
79
|
-
function xmlParse(xml) {
|
|
80
|
-
var regexEmpty = /\/$/;
|
|
81
|
-
var regexTagname;
|
|
82
|
-
var regexAttribute;
|
|
83
|
-
if (xml.match(/^<\?xml/)) {
|
|
84
|
-
// When an XML document begins with an XML declaration
|
|
85
|
-
// VersionInfo must appear.
|
|
86
|
-
if (xml.search(new RegExp(xmltoken_1.XML10_VERSION_INFO)) == 5) {
|
|
87
|
-
regexTagname = XML10_TAGNAME_REGEXP;
|
|
88
|
-
regexAttribute = XML10_ATTRIBUTE_REGEXP;
|
|
89
|
-
}
|
|
90
|
-
else if (xml.search(new RegExp(xmltoken_1.XML11_VERSION_INFO)) == 5) {
|
|
91
|
-
regexTagname = XML11_TAGNAME_REGEXP;
|
|
92
|
-
regexAttribute = XML11_ATTRIBUTE_REGEXP;
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
// VersionInfo is missing, or unknown version number.
|
|
96
|
-
// TODO : Fallback to XML 1.0 or XML 1.1, or just return null?
|
|
97
|
-
throw new Error('VersionInfo is missing, or unknown version number.');
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
// When an XML declaration is missing it's an XML 1.0 document.
|
|
102
|
-
regexTagname = XML10_TAGNAME_REGEXP;
|
|
103
|
-
regexAttribute = XML10_ATTRIBUTE_REGEXP;
|
|
104
|
-
}
|
|
105
|
-
var xmldoc = new xdocument_1.XDocument();
|
|
106
|
-
var root = xmldoc;
|
|
107
|
-
var stack = [];
|
|
108
|
-
var parent = root;
|
|
109
|
-
stack.push(parent);
|
|
110
|
-
var tag = false, quotes = false, doublequotes = false, start = 0;
|
|
111
|
-
for (var i = 0; i < xml.length; ++i) {
|
|
112
|
-
var char = xml.charAt(i);
|
|
113
|
-
if (tag && !doublequotes && char === "'") {
|
|
114
|
-
quotes = !quotes;
|
|
115
|
-
}
|
|
116
|
-
else if (tag && !quotes && char === '"') {
|
|
117
|
-
doublequotes = !doublequotes;
|
|
118
|
-
}
|
|
119
|
-
else if (tag && char === '>' && !quotes && !doublequotes) {
|
|
120
|
-
var text = xml.slice(start, i);
|
|
121
|
-
if (text.charAt(0) == '/') {
|
|
122
|
-
stack.pop();
|
|
123
|
-
parent = stack[stack.length - 1];
|
|
124
|
-
}
|
|
125
|
-
else if (text.charAt(0) === '?') {
|
|
126
|
-
// Ignore XML declaration and processing instructions
|
|
127
|
-
}
|
|
128
|
-
else if (text.charAt(0) === '!') {
|
|
129
|
-
// Ignore comments
|
|
130
|
-
// console.log(`Ignored ${text}`);
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
var empty = text.match(regexEmpty);
|
|
134
|
-
var tagname = regexTagname.exec(text)[1];
|
|
135
|
-
var node = domCreateElement(xmldoc, tagname);
|
|
136
|
-
var attribute = void 0;
|
|
137
|
-
while ((attribute = regexAttribute.exec(text))) {
|
|
138
|
-
var val = he_1.default.decode(attribute[5] || attribute[7] || '');
|
|
139
|
-
domSetAttribute(node, attribute[1], val);
|
|
140
|
-
}
|
|
141
|
-
node.siblingPosition = parent.childNodes.length;
|
|
142
|
-
domAppendChild(parent, node);
|
|
143
|
-
if (!empty) {
|
|
144
|
-
parent = node;
|
|
145
|
-
stack.push(node);
|
|
146
|
-
}
|
|
147
|
-
var namespaceMap = (0, util_1.namespaceMapAt)(node);
|
|
148
|
-
if (node.prefix !== null) {
|
|
149
|
-
if (node.prefix in namespaceMap)
|
|
150
|
-
node.namespaceUri = namespaceMap[node.prefix];
|
|
151
|
-
// else, prefix is undefined. do anything?
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
if ('' in namespaceMap)
|
|
155
|
-
node.namespaceUri = namespaceMap[''];
|
|
156
|
-
}
|
|
157
|
-
for (var i_1 = 0; i_1 < node.attributes.length; ++i_1) {
|
|
158
|
-
if (node.attributes[i_1].prefix !== null) {
|
|
159
|
-
if (node.attributes[i_1].prefix in namespaceMap) {
|
|
160
|
-
node.attributes[i_1].namespaceUri = namespaceMap[node.attributes[i_1].prefix];
|
|
161
|
-
}
|
|
162
|
-
// else, prefix undefined.
|
|
163
|
-
}
|
|
164
|
-
// elements with no prefix always have no namespace, so do nothing here.
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
start = i + 1;
|
|
168
|
-
tag = false;
|
|
169
|
-
quotes = false;
|
|
170
|
-
doublequotes = false;
|
|
171
|
-
}
|
|
172
|
-
else if (!tag && char === '<') {
|
|
173
|
-
var text = xml.slice(start, i);
|
|
174
|
-
if (text && parent !== root) {
|
|
175
|
-
domAppendChild(parent, domCreateTextNode(xmldoc, text));
|
|
176
|
-
}
|
|
177
|
-
if (xml.slice(i + 1, i + 4) === '!--') {
|
|
178
|
-
var endTagIndex = xml.slice(i + 4).indexOf('-->');
|
|
179
|
-
if (endTagIndex) {
|
|
180
|
-
var node = domCreateComment(xmldoc, xml.slice(i + 4, i + endTagIndex + 4));
|
|
181
|
-
domAppendChild(parent, node);
|
|
182
|
-
i += endTagIndex + 6;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
else if (xml.slice(i + 1, i + 9) === '![CDATA[') {
|
|
186
|
-
var endTagIndex = xml.slice(i + 9).indexOf(']]>');
|
|
187
|
-
if (endTagIndex) {
|
|
188
|
-
var node = domCreateCDATASection(xmldoc, xml.slice(i + 9, i + endTagIndex + 9));
|
|
189
|
-
domAppendChild(parent, node);
|
|
190
|
-
i += endTagIndex + 11;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
else if (xml.slice(i + 1, i + 9) === '!DOCTYPE') {
|
|
194
|
-
var endTagIndex = xml.slice(i + 9).indexOf('>');
|
|
195
|
-
if (endTagIndex) {
|
|
196
|
-
var dtdValue = xml.slice(i + 9, i + endTagIndex + 9).trimStart();
|
|
197
|
-
// TODO: Not sure if this is a good solution.
|
|
198
|
-
// Trying to implement this: https://github.com/DesignLiquido/xslt-processor/issues/30
|
|
199
|
-
var node = void 0;
|
|
200
|
-
if (parent.nodeName === 'xsl:text') {
|
|
201
|
-
node = domCreateTextNode(xmldoc, "<!DOCTYPE ".concat(dtdValue, ">"));
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
node = domCreateDTDSection(xmldoc, dtdValue);
|
|
205
|
-
}
|
|
206
|
-
domAppendChild(parent, node);
|
|
207
|
-
i += endTagIndex + dtdValue.length + 5;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
tag = true;
|
|
212
|
-
}
|
|
213
|
-
start = i + 1;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
return root;
|
|
217
|
-
}
|
|
218
|
-
exports.xmlParse = xmlParse;
|
|
219
57
|
//XDocument.prototype = new XNode(DOM_DOCUMENT_NODE, '#document');
|
|
220
58
|
//# sourceMappingURL=functions.js.map
|
package/dom/functions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/dom/functions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/dom/functions.ts"],"names":[],"mappings":";AAAA,gCAAgC;AAChC,+BAA+B;AAC/B,6BAA6B;AAC7B,sBAAsB;;;AAKtB,mEAAmE;AACnE,SAAgB,oBAAoB,CAAC,IAAS,EAAE,IAAY;IACxD,OAAO,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;AACxC,CAAC;AAFD,oDAE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AC,sBAAsB,EAAE,CAAC;AACxC,CAAC;AAFD,8DAEC;AAED,SAAgB,mBAAmB,CAAC,GAAc,EAAE,IAAS;IACzD,OAAO,GAAG,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC;AAFD,kDAEC;AAED,kEAAkE"}
|
package/dom/index.d.ts
CHANGED
package/dom/index.js
CHANGED
|
@@ -18,5 +18,6 @@ __exportStar(require("./functions"), exports);
|
|
|
18
18
|
__exportStar(require("./xdocument"), exports);
|
|
19
19
|
__exportStar(require("./xml-functions"), exports);
|
|
20
20
|
__exportStar(require("./xml-output-options"), exports);
|
|
21
|
+
__exportStar(require("./xml-parser"), exports);
|
|
21
22
|
__exportStar(require("./xnode"), exports);
|
|
22
23
|
//# sourceMappingURL=index.js.map
|
package/dom/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dom/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,8CAA4B;AAC5B,kDAAgC;AAChC,uDAAqC;AACrC,0CAAwB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dom/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,8CAA4B;AAC5B,kDAAgC;AAChC,uDAAqC;AACrC,+CAA6B;AAC7B,0CAAwB"}
|
package/dom/util.d.ts
CHANGED
package/dom/util.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// Dummy implmentation for the logging functions. Replace by something
|
|
10
10
|
// useful when you want to debug.
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.reverseInPlace = exports.mapExpr = exports.mapExec = void 0;
|
|
13
13
|
// Applies the given function to each element of the array, preserving
|
|
14
14
|
// this, and passing the index.
|
|
15
15
|
function mapExec(array, func) {
|
|
@@ -41,30 +41,4 @@ function reverseInPlace(array) {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
exports.reverseInPlace = reverseInPlace;
|
|
44
|
-
// (viat) given an XNode (see dom.js), returns an object mapping prefixes to their corresponding namespaces in its scope.
|
|
45
|
-
// default namespace is treated as if its prefix were the empty string.
|
|
46
|
-
function namespaceMapAt(node) {
|
|
47
|
-
var map = {
|
|
48
|
-
// reserved namespaces https://www.w3.org/TR/REC-xml-names/#xmlReserved
|
|
49
|
-
xmlns: 'http://www.w3.org/2000/xmlns/',
|
|
50
|
-
xml: 'http://www.w3.org/XML/1998/namespace'
|
|
51
|
-
};
|
|
52
|
-
var n = node;
|
|
53
|
-
while (n !== null) {
|
|
54
|
-
for (var i = 0; i < n.attributes.length; i++) {
|
|
55
|
-
if (n.attributes[i].nodeName.startsWith('xmlns:')) {
|
|
56
|
-
var prefix = n.attributes[i].nodeName.split(':')[1];
|
|
57
|
-
if (!(prefix in map))
|
|
58
|
-
map[prefix] = n.attributes[i].nodeValue;
|
|
59
|
-
}
|
|
60
|
-
else if (n.attributes[i].nodeName == 'xmlns') {
|
|
61
|
-
if (!('' in map))
|
|
62
|
-
map[''] = n.attributes[i].nodeValue || null;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
n = n.parentNode;
|
|
66
|
-
}
|
|
67
|
-
return map;
|
|
68
|
-
}
|
|
69
|
-
exports.namespaceMapAt = namespaceMapAt;
|
|
70
44
|
//# sourceMappingURL=util.js.map
|
package/dom/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/dom/util.ts"],"names":[],"mappings":";AAAA,gCAAgC;AAChC,+BAA+B;AAC/B,wBAAwB;AACxB,EAAE;AACF,uDAAuD;AACvD,EAAE;AACF,mDAAmD;AACnD,sEAAsE;AACtE,iCAAiC;;;AAEjC,sEAAsE;AACtE,+BAA+B;AAC/B,SAAgB,OAAO,CAAC,KAAY,EAAE,IAAc;IAChD,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AAY,EAAE,IAAc;IAChD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;QACnC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;KAChC;AACL,CAAC;AAJD,0BAIC;AAED,+DAA+D;AAC/D,wDAAwD;AACxD,SAAgB,OAAO,CAAC,KAAK,EAAE,IAAI;IAC/B,IAAM,GAAG,GAAG,EAAE,CAAC;IACf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;QACnC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KAC5B;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AAND,0BAMC;AAED;;;GAGG;AACH,SAAgB,cAAc,CAAC,KAAY;IACvC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,EAAE,CAAC,EAAE;QACvC,IAAM,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACnB,IAAM,EAAE,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC;QAChC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC;QACrB,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;KACjB;AACL,CAAC;AAPD,wCAOC"}
|
package/dom/xml-functions.d.ts
CHANGED
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
import { XNode } from './xnode';
|
|
2
2
|
import { XDocument } from './xdocument';
|
|
3
3
|
import { XmlOutputOptions } from './xml-output-options';
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Returns the text value of a node; for nodes without children this
|
|
6
|
+
* is the nodeValue, for nodes with children this is the concatenation
|
|
7
|
+
* of the value of all children. Browser-specific optimizations are used by
|
|
8
|
+
* default; they can be disabled by passing "true" in as the second parameter.
|
|
9
|
+
* @param node The Node (not exactly a `XNode` here).
|
|
10
|
+
* @param disallowBrowserSpecificOptimization A boolean, to avoid browser optimization.
|
|
11
|
+
* @returns The XML value as a string.
|
|
12
|
+
*/
|
|
13
|
+
export declare function xmlValue(node: any, disallowBrowserSpecificOptimization?: boolean): string;
|
|
5
14
|
export declare function xmlValue2(node: any, disallowBrowserSpecificOptimization?: boolean): any;
|
|
6
15
|
/**
|
|
7
16
|
* Returns the representation of a node as XML text.
|
|
17
|
+
* In general it is not used by XSLT, that uses `xmlTransformedText` instead.
|
|
8
18
|
* @param {XNode} node The starting node.
|
|
9
19
|
* @param {XmlOutputOptions} options XML output options.
|
|
10
20
|
* @returns The XML string.
|
|
21
|
+
* @see xmlTransformedText
|
|
11
22
|
*/
|
|
12
23
|
export declare function xmlText(node: XNode, options?: XmlOutputOptions): string;
|
|
13
24
|
/**
|
|
@@ -35,7 +46,7 @@ export declare function xmlEscapeText(s: string): string;
|
|
|
35
46
|
* @param name TODO
|
|
36
47
|
* @returns TODO
|
|
37
48
|
*/
|
|
38
|
-
export declare function xmlGetAttribute(node: XNode, name: string):
|
|
49
|
+
export declare function xmlGetAttribute(node: XNode, name: string): string;
|
|
39
50
|
/**
|
|
40
51
|
* Wrapper function to access the owner document uniformly for document
|
|
41
52
|
* and other nodes: for the document node, the owner document is the
|
package/dom/xml-functions.js
CHANGED
|
@@ -7,49 +7,55 @@ exports.xmlOwnerDocument = exports.xmlGetAttribute = exports.xmlEscapeText = exp
|
|
|
7
7
|
var he_1 = __importDefault(require("he"));
|
|
8
8
|
var constants_1 = require("../constants");
|
|
9
9
|
var functions_1 = require("./functions");
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Returns the text value of a node; for nodes without children this
|
|
12
|
+
* is the nodeValue, for nodes with children this is the concatenation
|
|
13
|
+
* of the value of all children. Browser-specific optimizations are used by
|
|
14
|
+
* default; they can be disabled by passing "true" in as the second parameter.
|
|
15
|
+
* @param node The Node (not exactly a `XNode` here).
|
|
16
|
+
* @param disallowBrowserSpecificOptimization A boolean, to avoid browser optimization.
|
|
17
|
+
* @returns The XML value as a string.
|
|
18
|
+
*/
|
|
14
19
|
function xmlValue(node, disallowBrowserSpecificOptimization) {
|
|
15
20
|
if (disallowBrowserSpecificOptimization === void 0) { disallowBrowserSpecificOptimization = false; }
|
|
16
21
|
if (!node) {
|
|
17
22
|
return '';
|
|
18
23
|
}
|
|
19
24
|
var ret = '';
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
switch (node.nodeType) {
|
|
26
|
+
case constants_1.DOM_DOCUMENT_TYPE_NODE:
|
|
27
|
+
return "<!DOCTYPE ".concat(node.nodeValue, ">");
|
|
28
|
+
case constants_1.DOM_TEXT_NODE:
|
|
29
|
+
case constants_1.DOM_CDATA_SECTION_NODE:
|
|
30
|
+
case constants_1.DOM_ATTRIBUTE_NODE:
|
|
31
|
+
return node.nodeValue;
|
|
32
|
+
case constants_1.DOM_ELEMENT_NODE:
|
|
33
|
+
case constants_1.DOM_DOCUMENT_NODE:
|
|
34
|
+
case constants_1.DOM_DOCUMENT_FRAGMENT_NODE:
|
|
35
|
+
if (!disallowBrowserSpecificOptimization) {
|
|
36
|
+
// IE, Safari, Opera, and friends
|
|
37
|
+
var innerText = node.innerText;
|
|
38
|
+
if (innerText != undefined) {
|
|
39
|
+
return innerText;
|
|
40
|
+
}
|
|
41
|
+
// Firefox
|
|
42
|
+
var textContent = node.textContent;
|
|
43
|
+
if (textContent != undefined) {
|
|
44
|
+
return textContent;
|
|
45
|
+
}
|
|
34
46
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
47
|
+
if (node.transformedChildNodes.length > 0) {
|
|
48
|
+
for (var i = 0; i < node.transformedChildNodes.length; ++i) {
|
|
49
|
+
ret += xmlValue(node.transformedChildNodes[i]);
|
|
50
|
+
}
|
|
39
51
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
for (var i = 0; i < node.childNodes.length; ++i) {
|
|
48
|
-
ret += xmlValue(node.childNodes[i]);
|
|
52
|
+
else {
|
|
53
|
+
for (var i = 0; i < node.childNodes.length; ++i) {
|
|
54
|
+
ret += xmlValue(node.childNodes[i]);
|
|
55
|
+
}
|
|
49
56
|
}
|
|
50
|
-
|
|
57
|
+
return ret;
|
|
51
58
|
}
|
|
52
|
-
return ret;
|
|
53
59
|
}
|
|
54
60
|
exports.xmlValue = xmlValue;
|
|
55
61
|
// TODO: Give a better name to this.
|
|
@@ -91,15 +97,18 @@ function xmlValue2(node, disallowBrowserSpecificOptimization) {
|
|
|
91
97
|
exports.xmlValue2 = xmlValue2;
|
|
92
98
|
/**
|
|
93
99
|
* Returns the representation of a node as XML text.
|
|
100
|
+
* In general it is not used by XSLT, that uses `xmlTransformedText` instead.
|
|
94
101
|
* @param {XNode} node The starting node.
|
|
95
102
|
* @param {XmlOutputOptions} options XML output options.
|
|
96
103
|
* @returns The XML string.
|
|
104
|
+
* @see xmlTransformedText
|
|
97
105
|
*/
|
|
98
106
|
function xmlText(node, options) {
|
|
99
107
|
if (options === void 0) { options = {
|
|
100
108
|
cData: false,
|
|
101
109
|
escape: true,
|
|
102
|
-
selfClosingTags: true
|
|
110
|
+
selfClosingTags: true,
|
|
111
|
+
outputMethod: 'xml'
|
|
103
112
|
}; }
|
|
104
113
|
var buffer = [];
|
|
105
114
|
xmlTextRecursive(node, buffer, options);
|
|
@@ -130,7 +139,7 @@ function xmlTextRecursive(node, buffer, options) {
|
|
|
130
139
|
}
|
|
131
140
|
}
|
|
132
141
|
if (node.childNodes.length === 0) {
|
|
133
|
-
if (options.selfClosingTags) {
|
|
142
|
+
if (options.selfClosingTags || (options.outputMethod === 'html' && ['hr', 'link'].includes(node.nodeName))) {
|
|
134
143
|
buffer.push('/>');
|
|
135
144
|
}
|
|
136
145
|
else {
|
|
@@ -161,7 +170,8 @@ function xmlTransformedText(node, options) {
|
|
|
161
170
|
if (options === void 0) { options = {
|
|
162
171
|
cData: false,
|
|
163
172
|
escape: true,
|
|
164
|
-
selfClosingTags: true
|
|
173
|
+
selfClosingTags: true,
|
|
174
|
+
outputMethod: 'xml'
|
|
165
175
|
}; }
|
|
166
176
|
var buffer = [];
|
|
167
177
|
xmlTransformedTextRecursive(node, buffer, options);
|
|
@@ -173,7 +183,7 @@ function xmlTransformedTextRecursive(node, buffer, options) {
|
|
|
173
183
|
return;
|
|
174
184
|
var nodeType = node.transformedNodeType || node.nodeType;
|
|
175
185
|
var nodeValue = node.transformedNodeValue || node.nodeValue;
|
|
176
|
-
if (nodeType
|
|
186
|
+
if (nodeType === constants_1.DOM_TEXT_NODE) {
|
|
177
187
|
if (node.transformedNodeValue && node.transformedNodeValue.trim() !== '') {
|
|
178
188
|
var finalText = node.escape && options.escape ?
|
|
179
189
|
xmlEscapeText(node.transformedNodeValue) :
|
|
@@ -181,7 +191,7 @@ function xmlTransformedTextRecursive(node, buffer, options) {
|
|
|
181
191
|
buffer.push(finalText);
|
|
182
192
|
}
|
|
183
193
|
}
|
|
184
|
-
else if (nodeType
|
|
194
|
+
else if (nodeType === constants_1.DOM_CDATA_SECTION_NODE) {
|
|
185
195
|
if (options.cData) {
|
|
186
196
|
buffer.push(nodeValue);
|
|
187
197
|
}
|
|
@@ -203,7 +213,7 @@ function xmlTransformedTextRecursive(node, buffer, options) {
|
|
|
203
213
|
xmlElementLogicMuted(node, buffer, options);
|
|
204
214
|
}
|
|
205
215
|
}
|
|
206
|
-
else if (nodeType
|
|
216
|
+
else if (nodeType === constants_1.DOM_DOCUMENT_NODE || nodeType === constants_1.DOM_DOCUMENT_FRAGMENT_NODE) {
|
|
207
217
|
var childNodes = node.transformedChildNodes.concat(node.childNodes);
|
|
208
218
|
childNodes.sort(function (a, b) { return a.siblingPosition - b.siblingPosition; });
|
|
209
219
|
for (var i = 0; i < childNodes.length; ++i) {
|
|
@@ -233,7 +243,10 @@ function xmlElementLogicTrivial(node, buffer, options) {
|
|
|
233
243
|
var childNodes = node.transformedChildNodes.length > 0 ? node.transformedChildNodes : node.childNodes;
|
|
234
244
|
childNodes = childNodes.sort(function (a, b) { return a.siblingPosition - b.siblingPosition; });
|
|
235
245
|
if (childNodes.length === 0) {
|
|
236
|
-
if (options.
|
|
246
|
+
if (options.outputMethod === 'html' && ['hr', 'link', 'meta'].includes(node.nodeName)) {
|
|
247
|
+
buffer.push('>');
|
|
248
|
+
}
|
|
249
|
+
else if (options.selfClosingTags) {
|
|
237
250
|
buffer.push('/>');
|
|
238
251
|
}
|
|
239
252
|
else {
|
|
@@ -263,6 +276,12 @@ function xmlElementLogicMuted(node, buffer, options) {
|
|
|
263
276
|
xmlTransformedTextRecursive(childNodes[i], buffer, options);
|
|
264
277
|
}
|
|
265
278
|
}
|
|
279
|
+
/**
|
|
280
|
+
* Gets the full node name.
|
|
281
|
+
* When namespace is set, the node name is `namespace:node`.
|
|
282
|
+
* @param node The node.
|
|
283
|
+
* @returns The full node name as a string.
|
|
284
|
+
*/
|
|
266
285
|
function xmlFullNodeName(node) {
|
|
267
286
|
var nodeName = node.transformedNodeName || node.nodeName;
|
|
268
287
|
if (node.transformedPrefix && nodeName.indexOf("".concat(node.transformedPrefix, ":")) != 0) {
|