xslt-processor 4.3.1 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -62,7 +62,7 @@ const xslt = new Xslt();
62
62
  const xPath = xslt.xPath;
63
63
  ```
64
64
 
65
- Or ou can import it like this:
65
+ Or you can import it like this:
66
66
 
67
67
  ```js
68
68
  import { XPath } from 'xslt-processor'
@@ -70,6 +70,8 @@ import { XPath } from 'xslt-processor'
70
70
  const xPath = new XPath();
71
71
  ```
72
72
 
73
+ `XPath` class is an external dependency, [living in its own repository](https://github.com/DesignLiquido/xpath).
74
+
73
75
  If you write pre-2015 JS code, make adjustments as needed.
74
76
 
75
77
  ### `Xslt` class options
@@ -145,76 +147,11 @@ console.log(parsed.root.users.user); // ["Alice", "Bob"]
145
147
  You can simply add a tag like this:
146
148
 
147
149
  ```html
148
- <script type="application/javascript" src="https://www.unpkg.com/xslt-processor@3.0.0/umd/xslt-processor.js"></script>
150
+ <script type="application/javascript" src="https://www.unpkg.com/xslt-processor@latest/umd/xslt-processor.js"></script>
149
151
  ```
150
152
 
151
153
  All the exports will live under `globalThis.XsltProcessor` and `window.XsltProcessor`. [See a usage example here](https://github.com/DesignLiquido/xslt-processor/blob/main/interactive-tests/xslt.html).
152
154
 
153
- ### Breaking Changes
154
-
155
- #### Version 2
156
-
157
- Until version 2.3.1, use like the example below:
158
-
159
- ```js
160
- import { Xslt, XmlParser } from 'xslt-processor'
161
-
162
- // xmlString: string of xml file contents
163
- // xsltString: string of xslt file contents
164
- // outXmlString: output xml string.
165
- const xslt = new Xslt();
166
- const xmlParser = new XmlParser();
167
- const outXmlString = xslt.xsltProcess( // Not async.
168
- xmlParser.xmlParse(xmlString),
169
- xmlParser.xmlParse(xsltString)
170
- );
171
- ```
172
-
173
- Version 3 received `<xsl:include>` which relies on Fetch API, which is asynchronous. Version 2 doesn't support `<xsl:include>`.
174
-
175
- If using Node.js older than version v17.5.0, please use version 3.2.3, that uses `node-fetch` package. Versions 3.3.0 onward require at least Node.js version v17.5.0, since they use native `fetch()` function.
176
-
177
- #### Version 1
178
-
179
- Until version 1.2.8, use like the example below:
180
-
181
- ```js
182
- import { Xslt, xmlParse } from 'xslt-processor'
183
-
184
- // xmlString: string of xml file contents
185
- // xsltString: string of xslt file contents
186
- // outXmlString: output xml string.
187
- const xslt = new Xslt();
188
- const outXmlString = xslt.xsltProcess(
189
- xmlParse(xmlString),
190
- xmlParse(xsltString)
191
- );
192
- ```
193
-
194
- #### Version 0
195
-
196
- Until version 0.11.7, use like the example below:
197
-
198
- ```js
199
- import { xsltProcess, xmlParse } from 'xslt-processor'
200
-
201
- // xmlString: string of xml file contents
202
- // xsltString: string of xslt file contents
203
- // outXmlString: output xml string.
204
- const outXmlString = xsltProcess(
205
- xmlParse(xmlString),
206
- xmlParse(xsltString)
207
- );
208
- ```
209
-
210
- and to access the XPath parser:
211
-
212
- ```js
213
- import { xpathParse } from 'xslt-processor'
214
- ```
215
-
216
- These functions are part of `Xslt` and `XPath` classes, respectively, at version 1.x onward.
217
-
218
155
  ## Introduction
219
156
 
220
157
  XSLT-processor contains an implementation of XSLT in JavaScript. Because XSLT uses XPath, it also contains an implementation of XPath that can be used
@@ -312,6 +249,71 @@ Use `<xsl:preserve-space>` to preserve whitespace in specific elements, overridi
312
249
  3. `xsl:strip-space` applies to remaining matches
313
250
  4. By default (no declarations), whitespace is preserved
314
251
 
252
+ ### Breaking Changes
253
+
254
+ #### Version 2
255
+
256
+ Until version 2.3.1, use like the example below:
257
+
258
+ ```js
259
+ import { Xslt, XmlParser } from 'xslt-processor'
260
+
261
+ // xmlString: string of xml file contents
262
+ // xsltString: string of xslt file contents
263
+ // outXmlString: output xml string.
264
+ const xslt = new Xslt();
265
+ const xmlParser = new XmlParser();
266
+ const outXmlString = xslt.xsltProcess( // Not async.
267
+ xmlParser.xmlParse(xmlString),
268
+ xmlParser.xmlParse(xsltString)
269
+ );
270
+ ```
271
+
272
+ Version 3 received `<xsl:include>` which relies on Fetch API, which is asynchronous. Version 2 doesn't support `<xsl:include>`.
273
+
274
+ If using Node.js older than version v17.5.0, please use version 3.2.3, that uses `node-fetch` package. Versions 3.3.0 onward require at least Node.js version v17.5.0, since they use native `fetch()` function.
275
+
276
+ #### Version 1
277
+
278
+ Until version 1.2.8, use like the example below:
279
+
280
+ ```js
281
+ import { Xslt, xmlParse } from 'xslt-processor'
282
+
283
+ // xmlString: string of xml file contents
284
+ // xsltString: string of xslt file contents
285
+ // outXmlString: output xml string.
286
+ const xslt = new Xslt();
287
+ const outXmlString = xslt.xsltProcess(
288
+ xmlParse(xmlString),
289
+ xmlParse(xsltString)
290
+ );
291
+ ```
292
+
293
+ #### Version 0
294
+
295
+ Until version 0.11.7, use like the example below:
296
+
297
+ ```js
298
+ import { xsltProcess, xmlParse } from 'xslt-processor'
299
+
300
+ // xmlString: string of xml file contents
301
+ // xsltString: string of xslt file contents
302
+ // outXmlString: output xml string.
303
+ const outXmlString = xsltProcess(
304
+ xmlParse(xmlString),
305
+ xmlParse(xsltString)
306
+ );
307
+ ```
308
+
309
+ and to access the XPath parser:
310
+
311
+ ```js
312
+ import { xpathParse } from 'xslt-processor'
313
+ ```
314
+
315
+ These functions are part of `Xslt` and `XPath` classes, respectively, at version 1.x onward.
316
+
315
317
  ## References
316
318
 
317
319
  - XPath Specification: http://www.w3.org/TR/1999/REC-xpath-19991116
package/index.d.mts CHANGED
@@ -214,6 +214,11 @@ interface XPathContext {
214
214
  * Example: { "atom": "http://www.w3.org/2005/Atom" }
215
215
  */
216
216
  namespaces?: XPathNamespaces;
217
+ /**
218
+ * XSLT version ('1.0', '2.0', '3.0') for version-specific behavior.
219
+ * Used by functions like json-to-xml() which are only available in XSLT 3.0+
220
+ */
221
+ xsltVersion?: string;
217
222
  }
218
223
  /**
219
224
  * Result types that can be returned from XPath evaluation.
@@ -413,6 +418,11 @@ declare class NodeConverter {
413
418
  * Create custom functions for XPath context (like key(), document(), etc.).
414
419
  */
415
420
  private createCustomFunctions;
421
+ /**
422
+ * Convert an XPathNode interface tree to actual XNode objects.
423
+ * This is needed to convert json-to-xml() output to XSLT-compatible nodes.
424
+ */
425
+ private convertXPathNodeToXNode;
416
426
  /**
417
427
  * Convert an XML node to a JSON string representation.
418
428
  * This is a simplified implementation of XSLT 3.0's xml-to-json().
package/index.d.ts CHANGED
@@ -214,6 +214,11 @@ interface XPathContext {
214
214
  * Example: { "atom": "http://www.w3.org/2005/Atom" }
215
215
  */
216
216
  namespaces?: XPathNamespaces;
217
+ /**
218
+ * XSLT version ('1.0', '2.0', '3.0') for version-specific behavior.
219
+ * Used by functions like json-to-xml() which are only available in XSLT 3.0+
220
+ */
221
+ xsltVersion?: string;
217
222
  }
218
223
  /**
219
224
  * Result types that can be returned from XPath evaluation.
@@ -413,6 +418,11 @@ declare class NodeConverter {
413
418
  * Create custom functions for XPath context (like key(), document(), etc.).
414
419
  */
415
420
  private createCustomFunctions;
421
+ /**
422
+ * Convert an XPathNode interface tree to actual XNode objects.
423
+ * This is needed to convert json-to-xml() output to XSLT-compatible nodes.
424
+ */
425
+ private convertXPathNodeToXNode;
416
426
  /**
417
427
  * Convert an XML node to a JSON string representation.
418
428
  * This is a simplified implementation of XSLT 3.0's xml-to-json().