xslt-processor 2.3.1 → 3.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.
package/README.md CHANGED
@@ -37,10 +37,18 @@ import { Xslt, XmlParser } from 'xslt-processor'
37
37
  // outXmlString: output xml string.
38
38
  const xslt = new Xslt();
39
39
  const xmlParser = new XmlParser();
40
- const outXmlString = xslt.xsltProcess(
40
+ // Either
41
+ const outXmlString = await xslt.xsltProcess(
41
42
  xmlParser.xmlParse(xmlString),
42
43
  xmlParser.xmlParse(xsltString)
43
44
  );
45
+ // Or
46
+ xslt.xsltProcess(
47
+ xmlParser.xmlParse(xmlString),
48
+ xmlParser.xmlParse(xsltString)
49
+ ).then(output => {
50
+ // `output` is equivalent to `outXmlString` (a string with XML).
51
+ });
44
52
  ```
45
53
 
46
54
  To access the XPath parser, you can use the instance present at `Xslt` class:
@@ -95,6 +103,26 @@ All the exports will live under `globalThis.XsltProcessor`. [See a usage example
95
103
 
96
104
  ### Breaking Changes
97
105
 
106
+ #### Version 2
107
+
108
+ Until version 2.3.1, use like the example below:
109
+
110
+ ```js
111
+ import { Xslt, XmlParser } from 'xslt-processor'
112
+
113
+ // xmlString: string of xml file contents
114
+ // xsltString: string of xslt file contents
115
+ // outXmlString: output xml string.
116
+ const xslt = new Xslt();
117
+ const xmlParser = new XmlParser();
118
+ const outXmlString = xslt.xsltProcess( // Not async.
119
+ xmlParser.xmlParse(xmlString),
120
+ xmlParser.xmlParse(xsltString)
121
+ );
122
+ ```
123
+
124
+ Version 3 received `<xsl:include>` which relies on Fetch API, which is asynchronous. Version 2 doesn't support `<xsl:include>`.
125
+
98
126
  #### Version 1
99
127
 
100
128
  Until version 1.2.8, use like the example below:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xslt-processor",
3
- "version": "2.3.1",
3
+ "version": "3.0.0",
4
4
  "description": "A JavaScript XSLT Processor",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -52,13 +52,12 @@
52
52
  "@typescript-eslint/parser": "^5.60.0",
53
53
  "babel-jest": "^29.5.0",
54
54
  "copy-files-from-to": "^3.9.0",
55
+ "copyfiles": "^2.4.1",
55
56
  "eslint": "^5.12.1",
56
57
  "eslint-plugin-jest": "^27.2.2",
57
58
  "eslint-plugin-jsx": "^0.1.0",
58
- "isomorphic-jsx": "^0.3.0",
59
59
  "jest": "^29.5.0",
60
60
  "npm-check-updates": "^16.10.13",
61
- "react": "^18.2.0",
62
61
  "release-it": "^15.11.0",
63
62
  "rimraf": "^5.0.1",
64
63
  "rollup": "^1.1.2",
@@ -71,7 +70,8 @@
71
70
  "typescript": "4.9.4"
72
71
  },
73
72
  "dependencies": {
74
- "he": "^1.2.0"
73
+ "he": "^1.2.0",
74
+ "node-fetch": "cjs"
75
75
  },
76
76
  "copyFiles": [
77
77
  {
@@ -1,4 +1,4 @@
1
- import { XDocument, XNode } from '../dom';
1
+ import { XDocument, XNode, XmlParser } from '../dom';
2
2
  import { ExprContext, XPath } from '../xpath';
3
3
  import { XsltOptions } from './xslt-options';
4
4
  import { XsltDecimalFormatSettings } from './xslt-decimal-format-settings';
@@ -29,6 +29,7 @@ import { MatchResolver } from '../xpath/match-resolver';
29
29
  */
30
30
  export declare class Xslt {
31
31
  xPath: XPath;
32
+ xmlParser: XmlParser;
32
33
  matchResolver: MatchResolver;
33
34
  options: XsltOptions;
34
35
  decimalFormatSettings: XsltDecimalFormatSettings;
@@ -43,14 +44,14 @@ export declare class Xslt {
43
44
  * @param stylesheet The stylesheet document root, as DOM node.
44
45
  * @returns the processed document, as XML text in a string.
45
46
  */
46
- xsltProcess(xmlDoc: XDocument, stylesheet: XDocument): string;
47
+ xsltProcess(xmlDoc: XDocument, stylesheet: XDocument): Promise<string>;
47
48
  /**
48
49
  * The main entry point of the XSL-T processor, as explained on the top of the file.
49
50
  * @param context The input document root, as XPath `ExprContext`.
50
51
  * @param template The stylesheet document root, as DOM node.
51
52
  * @param output If set, the output where the transformation should occur.
52
53
  */
53
- protected xsltProcessContext(context: ExprContext, template: XNode, output?: XNode): void;
54
+ protected xsltProcessContext(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
54
55
  /**
55
56
  * Implements `xsl:choose`, its child nodes `xsl:when`, and
56
57
  * `xsl:otherwise`.
@@ -58,7 +59,7 @@ export declare class Xslt {
58
59
  * @param template The template.
59
60
  * @param output The output. Only used if there's no corresponding output node already defined.
60
61
  */
61
- protected xsltChoose(context: ExprContext, template: XNode, output: XNode): void;
62
+ protected xsltChoose(context: ExprContext, template: XNode, output: XNode): Promise<void>;
62
63
  /**
63
64
  * Implements `xsl:copy` for all node types.
64
65
  * @param {XNode} destination the node being copied to, part of output document.
@@ -80,7 +81,14 @@ export declare class Xslt {
80
81
  * @param template The template.
81
82
  * @param output The output.
82
83
  */
83
- protected xsltForEach(context: ExprContext, template: XNode, output: XNode): void;
84
+ protected xsltForEach(context: ExprContext, template: XNode, output: XNode): Promise<void>;
85
+ /**
86
+ * Implements `xsl:include`.
87
+ * @param input The Expression Context.
88
+ * @param template The template.
89
+ * @param output The output.
90
+ */
91
+ protected xsltInclude(context: ExprContext, template: XNode, output: XNode): Promise<void>;
84
92
  /**
85
93
  * Orders the current node list in the input context according to the
86
94
  * sort order specified by xsl:sort child nodes of the current
@@ -98,7 +106,7 @@ export declare class Xslt {
98
106
  * @param context The Expression Context.
99
107
  * @param output The output XML.
100
108
  */
101
- protected xsltTransformOrStylesheet(template: XNode, context: ExprContext, output: XNode): void;
109
+ protected xsltTransformOrStylesheet(template: XNode, context: ExprContext, output: XNode): Promise<void>;
102
110
  /**
103
111
  * Evaluates a variable or parameter and set it in the current input
104
112
  * context. Implements `xsl:variable`, `xsl:param`, and `xsl:with-param`.
@@ -110,7 +118,7 @@ export declare class Xslt {
110
118
  * case. I.e. decides if this is a default value or a local
111
119
  * value. `xsl:variable` and `xsl:with-param` override; `xsl:param` doesn't.
112
120
  */
113
- protected xsltVariable(context: ExprContext, template: XNode, override: boolean): void;
121
+ protected xsltVariable(context: ExprContext, template: XNode, override: boolean): Promise<void>;
114
122
  /**
115
123
  * Traverses the template node tree. Calls the main processing
116
124
  * function with the current input context for every child node of the
@@ -119,7 +127,7 @@ export declare class Xslt {
119
127
  * @param template The XSL-T definition.
120
128
  * @param output If set, the output where the transformation should occur.
121
129
  */
122
- protected xsltChildNodes(context: ExprContext, template: XNode, output?: XNode): void;
130
+ protected xsltChildNodes(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
123
131
  /**
124
132
  * This logic is used in two different places:
125
133
  * - `xsltPassThrough`, if the template asks this library to write a text node;
@@ -137,7 +145,7 @@ export declare class Xslt {
137
145
  * @param template The XSLT stylesheet or transformation.
138
146
  * @param output The output.
139
147
  */
140
- protected xsltPassThrough(context: ExprContext, template: XNode, output: XNode): void;
148
+ protected xsltPassThrough(context: ExprContext, template: XNode, output: XNode): Promise<void>;
141
149
  /**
142
150
  * Determines if a text node in the XSLT template document is to be
143
151
  * stripped according to XSLT whitespace stripping rules.
@@ -177,6 +185,6 @@ export declare class Xslt {
177
185
  * @param context The Expression Context.
178
186
  * @param template The template node.
179
187
  */
180
- protected xsltWithParam(context: ExprContext, template: XNode): void;
188
+ protected xsltWithParam(context: ExprContext, template: XNode): Promise<void>;
181
189
  protected isXsltElement(element: any, opt_wantedName?: string): boolean;
182
190
  }