You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
constxslt=newXslt();
39
+
constxmlParser=newXmlParser();
39
40
constoutXmlString=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
constoptions= {
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
constxslt=newXslt(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);
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
+
constxslt=newXslt();
108
+
constoutXmlString=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.
0 commit comments