xslt-processor 1.2.7 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +37 -9
  2. package/dom/functions.d.ts +0 -7
  3. package/dom/functions.js +2 -164
  4. package/dom/functions.js.map +1 -1
  5. package/dom/index.d.ts +1 -0
  6. package/dom/index.js +1 -0
  7. package/dom/index.js.map +1 -1
  8. package/dom/util.d.ts +0 -4
  9. package/dom/util.js +1 -27
  10. package/dom/util.js.map +1 -1
  11. package/dom/xml-functions.d.ts +13 -2
  12. package/dom/xml-functions.js +59 -40
  13. package/dom/xml-functions.js.map +1 -1
  14. package/dom/xml-output-options.d.ts +1 -0
  15. package/dom/xml-parser.d.ts +47 -0
  16. package/dom/xml-parser.js +301 -0
  17. package/dom/xml-parser.js.map +1 -0
  18. package/index.d.ts +1 -1
  19. package/index.js +2 -2
  20. package/index.js.map +1 -1
  21. package/package.json +1 -1
  22. package/umd/dom/functions.d.ts +0 -7
  23. package/umd/dom/index.d.ts +1 -0
  24. package/umd/dom/util.d.ts +0 -4
  25. package/umd/dom/xml-functions.d.ts +13 -2
  26. package/umd/dom/xml-output-options.d.ts +1 -0
  27. package/umd/dom/xml-parser.d.ts +47 -0
  28. package/umd/index.d.ts +1 -1
  29. package/umd/xpath/values/node-set-value.d.ts +1 -1
  30. package/umd/xslt/xslt.d.ts +1 -1
  31. package/umd/xslt-processor.js +2 -2
  32. package/umd/xslt-processor.js.map +1 -1
  33. package/xpath/expressions/binary-expr.js +2 -2
  34. package/xpath/expressions/binary-expr.js.map +1 -1
  35. package/xpath/functions/standard.js +1 -1
  36. package/xpath/functions/standard.js.map +1 -1
  37. package/xpath/match-resolver.js +2 -2
  38. package/xpath/match-resolver.js.map +1 -1
  39. package/xpath/values/node-set-value.d.ts +1 -1
  40. package/xpath/values/node-set-value.js +1 -1
  41. package/xpath/values/node-set-value.js.map +1 -1
  42. package/xslt/xslt.d.ts +1 -1
  43. package/xslt/xslt.js +3 -2
  44. 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 `xmlParse` function and use this way:
30
+ Within your ES2015+ code, import the `Xslt` class, the `XmlParser` class and use this way:
31
31
 
32
32
  ```js
33
- import { Xslt, xmlParse } from 'xslt-processor'
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@1.2.0/umd/xslt-processor.js"></script>
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. Grep `xpath.js` for `ext-` to see their definitions.
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
 
@@ -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
- // Original author: Steffen Meschkat <mesch@google.com>
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
@@ -1 +1 @@
1
- {"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/dom/functions.ts"],"names":[],"mappings":";;;;;;AAAA,gCAAgC;AAChC,+BAA+B;AAC/B,6BAA6B;AAC7B,sBAAsB;AACtB,EAAE;AACF,uDAAuD;AACvD,EAAE;AACF,mEAAmE;AACnE,qEAAqE;AACrE,0CAAoB;AAEpB,+BAEgB;AAChB,yCAAwC;AACxC,uCAOoB;AAGpB,IAAM,oBAAoB,GAAG,IAAI,MAAM,CAAC,YAAK,qBAAU,MAAG,CAAC,CAAC;AAC5D,IAAM,sBAAsB,GAAG,IAAI,MAAM,CAAC,0BAAe,EAAE,GAAG,CAAC,CAAC;AAEhE,IAAM,oBAAoB,GAAG,IAAI,MAAM,CAAC,YAAK,qBAAU,MAAG,CAAC,CAAC;AAC5D,IAAM,sBAAsB,GAAG,IAAI,MAAM,CAAC,0BAAe,EAAE,GAAG,CAAC,CAAC;AAEhE,mEAAmE;AACnE,SAAgB,oBAAoB,CAAC,IAAS,EAAE,IAAY;IACxD,OAAO,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;AACxC,CAAC;AAFD,oDAEC;AAED,SAAgB,eAAe,CAAC,IAAW,EAAE,IAAY,EAAE,KAAU;IACjE,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAC1C,CAAC;AAFD,0CAEC;AAED,SAAgB,0BAA0B,CAAC,IAAW,EAAE,IAAY,EAAE,KAAU;IAC5E,OAAO,IAAI,CAAC,uBAAuB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AACrD,CAAC;AAFD,gEAEC;AAED,SAAgB,cAAc,CAAC,IAAW,EAAE,KAAU;IAClD,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;AACnC,CAAC;AAFD,wCAEC;AAED,SAAgB,yBAAyB,CAAC,IAAW,EAAE,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ocument';
3
3
  export * from './xml-functions';
4
4
  export * from './xml-output-options';
5
+ export * from './xml-parser';
5
6
  export * from './xnode';
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
@@ -5,7 +5,3 @@ export declare function mapExpr(array: any, func: any): any[];
5
5
  * @param array The array to be reversed.
6
6
  */
7
7
  export declare function reverseInPlace(array: any[]): void;
8
- export declare function namespaceMapAt(node: any): {
9
- xmlns: string;
10
- xml: string;
11
- };
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.namespaceMapAt = exports.reverseInPlace = exports.mapExpr = exports.mapExec = void 0;
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,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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,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"}
@@ -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
- export declare function xmlValue(node: any, disallowBrowserSpecificOptimization?: boolean): any;
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): any;
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
@@ -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
- // Returns the text value of a node; for nodes without children this
11
- // is the nodeValue, for nodes with children this is the concatenation
12
- // of the value of all children. Browser-specific optimizations are used by
13
- // default; they can be disabled by passing "true" in as the second parameter.
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
- if (node.nodeType == constants_1.DOM_TEXT_NODE || node.nodeType == constants_1.DOM_CDATA_SECTION_NODE) {
21
- ret += node.nodeValue;
22
- }
23
- else if (node.nodeType == constants_1.DOM_ATTRIBUTE_NODE) {
24
- ret += node.nodeValue;
25
- }
26
- else if (node.nodeType == constants_1.DOM_ELEMENT_NODE ||
27
- node.nodeType == constants_1.DOM_DOCUMENT_NODE ||
28
- node.nodeType == constants_1.DOM_DOCUMENT_FRAGMENT_NODE) {
29
- if (!disallowBrowserSpecificOptimization) {
30
- // IE, Safari, Opera, and friends
31
- var innerText = node.innerText;
32
- if (innerText != undefined) {
33
- return innerText;
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
- // Firefox
36
- var textContent = node.textContent;
37
- if (textContent != undefined) {
38
- return textContent;
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
- if (node.transformedChildNodes.length > 0) {
42
- for (var i = 0; i < node.transformedChildNodes.length; ++i) {
43
- ret += xmlValue(node.transformedChildNodes[i]);
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 == constants_1.DOM_TEXT_NODE) {
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 == constants_1.DOM_CDATA_SECTION_NODE) {
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 == constants_1.DOM_DOCUMENT_NODE || nodeType == constants_1.DOM_DOCUMENT_FRAGMENT_NODE) {
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.selfClosingTags) {
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) {