xslt-processor 4.3.0 → 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
@@ -22,6 +22,7 @@ declare class XNode {
22
22
  parentNode: XNode;
23
23
  visited: boolean;
24
24
  escape: boolean;
25
+ fromXslText: boolean;
25
26
  static _unusedXNodes: any[];
26
27
  constructor(type: number, name: string, opt_value: any, opt_owner: any, opt_namespace?: any);
27
28
  /**
@@ -138,7 +139,7 @@ interface XPathNode {
138
139
  nodeType: number;
139
140
  nodeName: string;
140
141
  localName?: string;
141
- namespaceURI?: string | null;
142
+ namespaceUri?: string | null;
142
143
  textContent?: string | null;
143
144
  parentNode?: XPathNode | null;
144
145
  childNodes?: ArrayLike<XPathNode>;
@@ -213,6 +214,11 @@ interface XPathContext {
213
214
  * Example: { "atom": "http://www.w3.org/2005/Atom" }
214
215
  */
215
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;
216
222
  }
217
223
  /**
218
224
  * Result types that can be returned from XPath evaluation.
@@ -412,6 +418,11 @@ declare class NodeConverter {
412
418
  * Create custom functions for XPath context (like key(), document(), etc.).
413
419
  */
414
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;
415
426
  /**
416
427
  * Convert an XML node to a JSON string representation.
417
428
  * This is a simplified implementation of XSLT 3.0's xml-to-json().
@@ -532,7 +543,7 @@ type XsltOptions = {
532
543
  cData: boolean;
533
544
  escape: boolean;
534
545
  selfClosingTags: boolean;
535
- outputMethod?: 'xml' | 'html' | 'text' | 'xhtml' | 'json';
546
+ outputMethod?: 'xml' | 'html' | 'text' | 'xhtml' | 'json' | 'adaptive';
536
547
  parameters?: XsltParameter[];
537
548
  };
538
549
 
@@ -567,7 +578,7 @@ declare class Xslt {
567
578
  options: XsltOptions;
568
579
  decimalFormatSettings: XsltDecimalFormatSettings;
569
580
  outputDocument: XDocument;
570
- outputMethod: 'xml' | 'html' | 'text' | 'name' | 'xhtml' | 'json';
581
+ outputMethod: 'xml' | 'html' | 'text' | 'name' | 'xhtml' | 'json' | 'adaptive';
571
582
  outputOmitXmlDeclaration: string;
572
583
  version: string;
573
584
  firstTemplateRan: boolean;
@@ -592,7 +603,7 @@ declare class Xslt {
592
603
  * The exported entry point of the XSL-T processor.
593
604
  * @param xmlDoc The input document root, as DOM node.
594
605
  * @param stylesheet The stylesheet document root, as DOM node.
595
- * @returns the processed document, as XML text in a string, or JSON string if outputMethod is 'json'.
606
+ * @returns the processed document, as XML text in a string, JSON string if outputMethod is 'json', or text if outputMethod is 'text' or 'adaptive' (with text content).
596
607
  */
597
608
  xsltProcess(xmlDoc: XDocument, stylesheet: XDocument): Promise<string>;
598
609
  /**
@@ -843,6 +854,17 @@ declare class Xslt {
843
854
  */
844
855
  protected xsltTemplate(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
845
856
  protected xsltText(context: ExprContext, template: XNode, output?: XNode): void;
857
+ /**
858
+ * Validates XSLT stylesheet/transform attributes.
859
+ * According to XSLT specification, validates:
860
+ * - Required version attribute
861
+ * - Valid version values (1.0, 2.0, 3.0)
862
+ * - Valid namespace declarations
863
+ * - Valid values for optional attributes (extension-element-prefixes, exclude-result-prefixes)
864
+ * @param stylesheetElement The `<xsl:stylesheet>` or `<xsl:transform>` element to validate.
865
+ * @param context The Expression Context for namespace access.
866
+ */
867
+ protected validateStylesheetAttributes(stylesheetElement: XNode, context: ExprContext): void;
846
868
  /**
847
869
  * Implements `<xsl:stylesheet>` and `<xsl:transform>`, and its corresponding
848
870
  * validations.
package/index.d.ts CHANGED
@@ -22,6 +22,7 @@ declare class XNode {
22
22
  parentNode: XNode;
23
23
  visited: boolean;
24
24
  escape: boolean;
25
+ fromXslText: boolean;
25
26
  static _unusedXNodes: any[];
26
27
  constructor(type: number, name: string, opt_value: any, opt_owner: any, opt_namespace?: any);
27
28
  /**
@@ -138,7 +139,7 @@ interface XPathNode {
138
139
  nodeType: number;
139
140
  nodeName: string;
140
141
  localName?: string;
141
- namespaceURI?: string | null;
142
+ namespaceUri?: string | null;
142
143
  textContent?: string | null;
143
144
  parentNode?: XPathNode | null;
144
145
  childNodes?: ArrayLike<XPathNode>;
@@ -213,6 +214,11 @@ interface XPathContext {
213
214
  * Example: { "atom": "http://www.w3.org/2005/Atom" }
214
215
  */
215
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;
216
222
  }
217
223
  /**
218
224
  * Result types that can be returned from XPath evaluation.
@@ -412,6 +418,11 @@ declare class NodeConverter {
412
418
  * Create custom functions for XPath context (like key(), document(), etc.).
413
419
  */
414
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;
415
426
  /**
416
427
  * Convert an XML node to a JSON string representation.
417
428
  * This is a simplified implementation of XSLT 3.0's xml-to-json().
@@ -532,7 +543,7 @@ type XsltOptions = {
532
543
  cData: boolean;
533
544
  escape: boolean;
534
545
  selfClosingTags: boolean;
535
- outputMethod?: 'xml' | 'html' | 'text' | 'xhtml' | 'json';
546
+ outputMethod?: 'xml' | 'html' | 'text' | 'xhtml' | 'json' | 'adaptive';
536
547
  parameters?: XsltParameter[];
537
548
  };
538
549
 
@@ -567,7 +578,7 @@ declare class Xslt {
567
578
  options: XsltOptions;
568
579
  decimalFormatSettings: XsltDecimalFormatSettings;
569
580
  outputDocument: XDocument;
570
- outputMethod: 'xml' | 'html' | 'text' | 'name' | 'xhtml' | 'json';
581
+ outputMethod: 'xml' | 'html' | 'text' | 'name' | 'xhtml' | 'json' | 'adaptive';
571
582
  outputOmitXmlDeclaration: string;
572
583
  version: string;
573
584
  firstTemplateRan: boolean;
@@ -592,7 +603,7 @@ declare class Xslt {
592
603
  * The exported entry point of the XSL-T processor.
593
604
  * @param xmlDoc The input document root, as DOM node.
594
605
  * @param stylesheet The stylesheet document root, as DOM node.
595
- * @returns the processed document, as XML text in a string, or JSON string if outputMethod is 'json'.
606
+ * @returns the processed document, as XML text in a string, JSON string if outputMethod is 'json', or text if outputMethod is 'text' or 'adaptive' (with text content).
596
607
  */
597
608
  xsltProcess(xmlDoc: XDocument, stylesheet: XDocument): Promise<string>;
598
609
  /**
@@ -843,6 +854,17 @@ declare class Xslt {
843
854
  */
844
855
  protected xsltTemplate(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
845
856
  protected xsltText(context: ExprContext, template: XNode, output?: XNode): void;
857
+ /**
858
+ * Validates XSLT stylesheet/transform attributes.
859
+ * According to XSLT specification, validates:
860
+ * - Required version attribute
861
+ * - Valid version values (1.0, 2.0, 3.0)
862
+ * - Valid namespace declarations
863
+ * - Valid values for optional attributes (extension-element-prefixes, exclude-result-prefixes)
864
+ * @param stylesheetElement The `<xsl:stylesheet>` or `<xsl:transform>` element to validate.
865
+ * @param context The Expression Context for namespace access.
866
+ */
867
+ protected validateStylesheetAttributes(stylesheetElement: XNode, context: ExprContext): void;
846
868
  /**
847
869
  * Implements `<xsl:stylesheet>` and `<xsl:transform>`, and its corresponding
848
870
  * validations.