xslt-processor 2.3.1 → 3.0.1

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:
@@ -88,13 +96,33 @@ const xslt = new Xslt(options);
88
96
  You can simply add a tag like this:
89
97
 
90
98
  ```html
91
- <script type="application/javascript" src="https://www.unpkg.com/xslt-processor@2.1.0/umd/xslt-processor.js"></script>
99
+ <script type="application/javascript" src="https://www.unpkg.com/xslt-processor@3.0.0/umd/xslt-processor.js"></script>
92
100
  ```
93
101
 
94
- 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).
102
+ 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).
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/dom/util.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export declare function mapExec(array: any[], func: Function): void;
2
- export declare function mapExpr(array: any, func: any): any[];
2
+ export declare function mapExpr(array: any[], func: Function): any[];
3
3
  /**
4
4
  * Reverses the given array in place.
5
5
  * @param array The array to be reversed.
package/dom/util.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/dom/util.ts"],"names":[],"mappings":";AAAA,qCAAqC;AACrC,+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;IACf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;QACnC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KAC5B;IACD,OAAO,GAAG,CAAC;AAC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O,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xslt-processor",
3
- "version": "2.3.1",
3
+ "version": "3.0.1",
4
4
  "description": "A JavaScript XSLT Processor",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -47,18 +47,17 @@
47
47
  "@rollup/plugin-terser": "^0.4.3",
48
48
  "@rollup/plugin-typescript": "^11.1.1",
49
49
  "@types/he": "^1.2.0",
50
- "@types/jest": "^29.5.2",
50
+ "@types/jest": "^29.5.12",
51
51
  "@typescript-eslint/eslint-plugin": "^5.60.0",
52
52
  "@typescript-eslint/parser": "^5.60.0",
53
- "babel-jest": "^29.5.0",
53
+ "babel-jest": "^29.7.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
- "jest": "^29.5.0",
59
+ "jest": "^29.7.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",
@@ -66,12 +65,13 @@
66
65
  "rollup-plugin-commonjs": "^9.2.0",
67
66
  "rollup-plugin-node-resolve": "^4.0.0",
68
67
  "rollup-plugin-terser": "^4.0.3",
69
- "ts-jest": "^29.1.0",
70
- "ts-node": "^10.9.1",
71
- "typescript": "4.9.4"
68
+ "ts-jest": "^29.1.5",
69
+ "ts-node": "^10.9.2",
70
+ "typescript": "^4.9.5"
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
  {
package/umd/dom/util.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export declare function mapExec(array: any[], func: Function): void;
2
- export declare function mapExpr(array: any, func: any): any[];
2
+ export declare function mapExpr(array: any[], func: Function): any[];
3
3
  /**
4
4
  * Reverses the given array in place.
5
5
  * @param array The array to be reversed.
@@ -4,5 +4,5 @@ import { NodeTest } from "./node-test";
4
4
  export declare class NodeTestPI implements NodeTest {
5
5
  target: any;
6
6
  constructor(target: any);
7
- evaluate(ctx: ExprContext): BooleanValue;
7
+ evaluate(context: ExprContext): BooleanValue;
8
8
  }
@@ -50,13 +50,13 @@ export declare const TOK_NUMBER: XPathTokenRule;
50
50
  export declare const TOK_QNAME: XPathTokenRule;
51
51
  export declare const TOK_NODEO: XPathTokenRule;
52
52
  export declare const xPathTokenRules: XPathTokenRule[];
53
- export declare const Q_01: {
53
+ export declare const Q_ZERO_OR_ONE: {
54
54
  label: string;
55
55
  };
56
- export declare const Q_MM: {
56
+ export declare const Q_ZERO_OR_MULTIPLE: {
57
57
  label: string;
58
58
  };
59
- export declare const Q_1M: {
59
+ export declare const Q_ONE_OR_MULTIPLE: {
60
60
  label: string;
61
61
  };
62
62
  export declare const ASSOC_LEFT = true;
@@ -60,15 +60,15 @@ export declare class XPath {
60
60
  makeAbbrevStep(abbrev: any): StepExpr;
61
61
  makeNodeTestExpr1(): NodeTestElementOrAttribute;
62
62
  makeNodeTestExpr2(ncname: any): NodeTestNC;
63
- makeNodeTestExpr3(qname: any): NodeTestName;
63
+ makeNodeTestExpr3(qname: TokenExpr): NodeTestName;
64
64
  makeNodeTestExpr4(typeo: any): NodeTestAny | NodeTestComment | NodeTestPI | NodeTestText;
65
65
  makeNodeTestExpr5(typeo: any, target: any): NodeTestPI;
66
- makePredicateExpr(pareno: any, expr: any): PredicateExpr;
67
- makePrimaryExpr(pareno: any, expr: any): any;
66
+ makePredicateExpr(pareno: any, expression: any): PredicateExpr;
67
+ makePrimaryExpr(pareno: any, expression: any): any;
68
68
  makeFunctionCallExpr1(name: any): FunctionCallExpr;
69
69
  makeFunctionCallExpr2(name: any, pareno: any, arg1: any, args: any): FunctionCallExpr;
70
- makeArgumentExpr(comma: any, expr: any): any;
71
- makeUnionExpr(expr1: any, pipe: any, expr2: any): UnionExpr;
70
+ makeArgumentExpr(comma: any, expression: any): any;
71
+ makeUnionExpr(expr1: Expression, pipe: TokenExpr, expr2: Expression): UnionExpr;
72
72
  makePathExpr1(filter: any, slash: any, rel: any): PathExpr;
73
73
  makePathExpr2(filter: any, dslash: any, rel: any): PathExpr;
74
74
  makeFilterExpr(expr: any, predicates: any): any;
@@ -108,7 +108,7 @@ export declare class XPath {
108
108
  * performance. This is false by default.
109
109
  */
110
110
  xPathExtractTagNameFromNodeTest(nodeTest: NodeTest, ignoreNonElementNodesForNTA: any): string;
111
- xPathMatchStack(stack: any, pattern: any): any;
111
+ xPathMatchStack(stack: any[], pattern: any[]): any;
112
112
  /**
113
113
  * Finds the best rule for the XPath expression provided.
114
114
  * @param expression The XPath string expression.
@@ -139,8 +139,8 @@ export declare class XPath {
139
139
  * grammatical rules to them, "reducing" them to higher-level
140
140
  * tokens. Ultimately, any valid XPath should reduce to exactly one
141
141
  * "Expr" token.
142
-
143
- * Reduce too early or too late and you'll have two tokens that can't reduce
142
+ *
143
+ * Reduce too early or too late, and you'll have two tokens that can't reduce
144
144
  * to single Expr. For example, you may hastily reduce a qname that
145
145
  * should name a function, incorrectly treating it as a tag name.
146
146
  * Or you may reduce too late, accidentally reducing the last part of the
@@ -155,6 +155,10 @@ export declare class XPath {
155
155
  *
156
156
  * Some tokens have left associativity, in which case we shift when they
157
157
  * have LOWER precedence than the candidate.
158
+ * @param stack The actual grammar rule stack.
159
+ * @param ahead The grammar rule ahead.
160
+ * @return `true` if a grammar rule candidate was applied. `false` otherwise.
161
+ * @private
158
162
  */
159
163
  private xPathReduce;
160
164
  /**
@@ -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,30 @@ 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>;
55
+ /**
56
+ * Implements `xsl:apply-templates`.
57
+ * @param context The Expression Context.
58
+ * @param template The template.
59
+ * @param output The output. Only used if there's no corresponding output node already defined.
60
+ * @protected
61
+ */
62
+ protected xsltApplyTemplates(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
63
+ /**
64
+ * Implements `xsl:attribute`.
65
+ * @param context The Expression Context.
66
+ * @param template The template.
67
+ * @param output The output. Only used if there's no corresponding output node already defined.
68
+ * @protected
69
+ */
70
+ protected xsltAttribute(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
54
71
  /**
55
72
  * Implements `xsl:choose`, its child nodes `xsl:when`, and
56
73
  * `xsl:otherwise`.
@@ -58,7 +75,7 @@ export declare class Xslt {
58
75
  * @param template The template.
59
76
  * @param output The output. Only used if there's no corresponding output node already defined.
60
77
  */
61
- protected xsltChoose(context: ExprContext, template: XNode, output: XNode): void;
78
+ protected xsltChoose(context: ExprContext, template: XNode, output: XNode): Promise<void>;
62
79
  /**
63
80
  * Implements `xsl:copy` for all node types.
64
81
  * @param {XNode} destination the node being copied to, part of output document.
@@ -76,11 +93,18 @@ export declare class Xslt {
76
93
  protected xsltCopyOf(destination: XNode, source: XNode): void;
77
94
  /**
78
95
  * Implements `xsl:for-each`.
79
- * @param input The Expression Context.
96
+ * @param context The Expression Context.
97
+ * @param template The template.
98
+ * @param output The output.
99
+ */
100
+ protected xsltForEach(context: ExprContext, template: XNode, output: XNode): Promise<void>;
101
+ /**
102
+ * Implements `xsl:include`.
103
+ * @param context The Expression Context.
80
104
  * @param template The template.
81
105
  * @param output The output.
82
106
  */
83
- protected xsltForEach(context: ExprContext, template: XNode, output: XNode): void;
107
+ protected xsltInclude(context: ExprContext, template: XNode, output: XNode): Promise<void>;
84
108
  /**
85
109
  * Orders the current node list in the input context according to the
86
110
  * sort order specified by xsl:sort child nodes of the current
@@ -98,7 +122,7 @@ export declare class Xslt {
98
122
  * @param context The Expression Context.
99
123
  * @param output The output XML.
100
124
  */
101
- protected xsltTransformOrStylesheet(template: XNode, context: ExprContext, output: XNode): void;
125
+ protected xsltTransformOrStylesheet(template: XNode, context: ExprContext, output: XNode): Promise<void>;
102
126
  /**
103
127
  * Evaluates a variable or parameter and set it in the current input
104
128
  * context. Implements `xsl:variable`, `xsl:param`, and `xsl:with-param`.
@@ -110,7 +134,7 @@ export declare class Xslt {
110
134
  * case. I.e. decides if this is a default value or a local
111
135
  * value. `xsl:variable` and `xsl:with-param` override; `xsl:param` doesn't.
112
136
  */
113
- protected xsltVariable(context: ExprContext, template: XNode, override: boolean): void;
137
+ protected xsltVariable(context: ExprContext, template: XNode, override: boolean): Promise<void>;
114
138
  /**
115
139
  * Traverses the template node tree. Calls the main processing
116
140
  * function with the current input context for every child node of the
@@ -119,13 +143,14 @@ export declare class Xslt {
119
143
  * @param template The XSL-T definition.
120
144
  * @param output If set, the output where the transformation should occur.
121
145
  */
122
- protected xsltChildNodes(context: ExprContext, template: XNode, output?: XNode): void;
146
+ protected xsltChildNodes(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
123
147
  /**
124
148
  * This logic is used in two different places:
125
149
  * - `xsltPassThrough`, if the template asks this library to write a text node;
126
150
  * - `xsltProcessContext`, `apply-templates` operation, when the current node is text.
127
151
  * @param context The Expression Context.
128
152
  * @param template The template, that contains the node value to be written.
153
+ * @param output The output.
129
154
  */
130
155
  private commonLogicTextNode;
131
156
  /**
@@ -137,7 +162,7 @@ export declare class Xslt {
137
162
  * @param template The XSLT stylesheet or transformation.
138
163
  * @param output The output.
139
164
  */
140
- protected xsltPassThrough(context: ExprContext, template: XNode, output: XNode): void;
165
+ protected xsltPassThrough(context: ExprContext, template: XNode, output: XNode): Promise<void>;
141
166
  /**
142
167
  * Determines if a text node in the XSLT template document is to be
143
168
  * stripped according to XSLT whitespace stripping rules.
@@ -148,7 +173,7 @@ export declare class Xslt {
148
173
  * currently not implemented.
149
174
  */
150
175
  protected xsltPassText(template: XNode): boolean;
151
- protected xsltAttribute(attributeName: string, context: ExprContext): XNode;
176
+ protected findAttributeInContext(attributeName: string, context: ExprContext): XNode;
152
177
  /**
153
178
  * Evaluates an XSL-T attribute value template. Attribute value
154
179
  * templates are attributes on XSL-T elements that contain XPath
@@ -177,6 +202,6 @@ export declare class Xslt {
177
202
  * @param context The Expression Context.
178
203
  * @param template The template node.
179
204
  */
180
- protected xsltWithParam(context: ExprContext, template: XNode): void;
205
+ protected xsltWithParam(context: ExprContext, template: XNode): Promise<void>;
181
206
  protected isXsltElement(element: any, opt_wantedName?: string): boolean;
182
207
  }