xslt-processor 3.0.2 → 3.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xslt-processor",
3
- "version": "3.0.2",
3
+ "version": "3.2.0",
4
4
  "description": "A JavaScript XSLT Processor",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -44,8 +44,8 @@ function test() {
44
44
  return __generator(this, function (_a) {
45
45
  switch (_a.label) {
46
46
  case 0:
47
- xml = "<XampleXml xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n <ReportName>My first transformation in js</ReportName>\n <GenerationDate>01/06/2024</GenerationDate>\n </XampleXml>";
48
- xslt = "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">\n <xsl:output method=\"html\" version=\"4.0\" encoding=\"utf-8\" omit-xml-declaration=\"yes\" />\n <xsl:template match=\"/\">\n <html>\n <head>\n <script type=\"text/javascript\">\n <xsl:text disable-output-escaping=\"yes\">\n <![CDATA[\n if (1 < 2) {}\n ]]>\n </xsl:text>\n </script>\n </head>\n <body>\n <h1>\n <xsl:value-of select=\"ReportName\"/>\n </h1>\n <p>\n <xsl:value-of select=\"GenerationDate\"/>\n </p>\n </body>\n </html>\n </xsl:template>\n </xsl:stylesheet>";
47
+ xml = "<root>\n <test name=\"test1\" />\n <test name=\"test2\" />\n <test name=\"test3\" />\n <test name=\"test4\" />\n </root>";
48
+ xslt = "<?xml version=\"1.0\"?>\n <xsl:stylesheet version=\"1.0\">\n <xsl:template match=\"test\">\n <span><xsl:value-of select=\"@name\" /></span>\n </xsl:template>\n <xsl:template match=\"test[@name='test1']\">\n <span>another name</span>\n </xsl:template>\n <xsl:template match=\"/\">\n <div>\n <xsl:apply-templates select=\"//test\" />\n </div>\n </xsl:template>\n </xsl:stylesheet>";
49
49
  xsltClass = new xslt_1.Xslt();
50
50
  xmlParser = new dom_1.XmlParser();
51
51
  parsedXml = xmlParser.xmlParse(xml);
@@ -1 +1 @@
1
- {"version":3,"file":"test-without-jest.js","sourceRoot":"","sources":["../src/test-without-jest.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6BAAkC;AAClC,+BAA8B;AAE9B,SAAe,IAAI;;;;;;oBACT,GAAG,GAAG,oQAIC,CAAC;oBACR,IAAI,GAAG,g8BAuBS,CAAC;oBAEjB,SAAS,GAAG,IAAI,WAAI,EAAE,CAAC;oBACvB,SAAS,GAAG,IAAI,eAAS,EAAE,CAAC;oBAC5B,SAAS,GAAG,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;oBACpC,UAAU,GAAG,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;oBAC/B,qBAAM,SAAS,CAAC,WAAW,CAAC,SAAS,EAAE,UAAU,CAAC,EAAA;;oBAAzD,IAAI,GAAG,SAAkD;oBAC/D,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;;;;;CACrB;AAED,IAAI,EAAE,CAAC"}
1
+ {"version":3,"file":"test-without-jest.js","sourceRoot":"","sources":["../src/test-without-jest.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6BAAkC;AAClC,+BAA8B;AAE9B,SAAe,IAAI;;;;;;oBAMT,GAAG,GAAG,qKAKA,CAAC;oBA0BP,IAAI,GAAG,yfAaS,CAAC;oBAEjB,SAAS,GAAG,IAAI,WAAI,EAAE,CAAC;oBACvB,SAAS,GAAG,IAAI,eAAS,EAAE,CAAC;oBAC5B,SAAS,GAAG,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;oBACpC,UAAU,GAAG,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;oBAC/B,qBAAM,SAAS,CAAC,WAAW,CAAC,SAAS,EAAE,UAAU,CAAC,EAAA;;oBAAzD,IAAI,GAAG,SAAkD;oBAC/D,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;;;;;CACrB;AAED,IAAI,EAAE,CAAC"}
@@ -45,6 +45,11 @@ export declare class ExprContext {
45
45
  variables: {
46
46
  [name: string]: NodeValue;
47
47
  };
48
+ keys: {
49
+ [name: string]: {
50
+ [key: string]: NodeValue;
51
+ };
52
+ };
48
53
  knownNamespaces: {
49
54
  [alias: string]: string;
50
55
  };
@@ -96,7 +101,7 @@ export declare class ExprContext {
96
101
  */
97
102
  clone(opt_nodeList?: XNode[], opt_outputNodeList?: XNode[], opt_position?: number, opt_outputPosition?: number): ExprContext;
98
103
  cloneByOutput(opt_outputNodeList?: XNode[], opt_outputPosition?: number, opt_outputDepth?: number): ExprContext;
99
- setVariable(name?: any, value?: any): void;
104
+ setVariable(name?: string, value?: NodeValue | string): void;
100
105
  getVariable(name: string): NodeValue;
101
106
  setNode(position: number): void;
102
107
  contextSize(): number;
@@ -8,8 +8,8 @@ export declare class LocationExpr extends Expression {
8
8
  steps: StepExpr[];
9
9
  xPath: XPath;
10
10
  constructor(xPath: XPath);
11
- appendStep(s: any): void;
12
- prependStep(s: any): void;
13
- _combineSteps(prevStep: any, nextStep: any): any;
11
+ appendStep(s: StepExpr): void;
12
+ prependStep(s: StepExpr): void;
13
+ private _combineSteps;
14
14
  evaluate(context: ExprContext): NodeSetValue;
15
15
  }
@@ -1,2 +1,4 @@
1
1
  export * from './non-standard';
2
2
  export * from './standard';
3
+ export * from './standard-20';
4
+ export * from './xslt-specific';
@@ -0,0 +1,3 @@
1
+ import { ExprContext } from "../expr-context";
2
+ import { NodeValue } from "../values";
3
+ export declare function key(context: ExprContext): NodeValue;
@@ -3,7 +3,7 @@ import { NodeValue } from "./node-value";
3
3
  export declare class NodeSetValue implements NodeValue {
4
4
  value: XNode[];
5
5
  type: string;
6
- constructor(value: any);
6
+ constructor(value: XNode[]);
7
7
  stringValue(): string;
8
8
  booleanValue(): boolean;
9
9
  numberValue(): number;
@@ -16,7 +16,7 @@ import { MatchResolver } from '../xpath/match-resolver';
16
16
  * <http://www.ecma-international.org/publications/standards/Ecma-262.htm>.
17
17
  *
18
18
  * The XSL processor API has one entry point, the function
19
- * xsltProcessContext(). It receives as arguments the starting point in the
19
+ * `xsltProcess()`. It receives as arguments the starting point in the
20
20
  * input document as an XPath expression context, the DOM root node of
21
21
  * the XSL-T stylesheet, and a DOM node that receives the output.
22
22
  *
@@ -37,6 +37,7 @@ export declare class Xslt {
37
37
  outputMethod: 'xml' | 'html' | 'text' | 'name';
38
38
  outputOmitXmlDeclaration: string;
39
39
  version: string;
40
+ firstTemplateRan: boolean;
40
41
  constructor(options?: Partial<XsltOptions>);
41
42
  /**
42
43
  * The exported entry point of the XSL-T processor.
@@ -68,6 +69,13 @@ export declare class Xslt {
68
69
  * @protected
69
70
  */
70
71
  protected xsltAttribute(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
72
+ /**
73
+ * Implements `xsl:call-template`.
74
+ * @param context The Expression Context.
75
+ * @param template The template.
76
+ * @param output The output, used when a fragment is passed by a previous step.
77
+ */
78
+ protected xsltCallTemplate(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
71
79
  /**
72
80
  * Implements `xsl:choose`, its child nodes `xsl:when`, and
73
81
  * `xsl:otherwise`.
@@ -83,6 +91,13 @@ export declare class Xslt {
83
91
  * @returns {XNode|null} If an element node was created, the element node. Otherwise, null.
84
92
  */
85
93
  protected xsltCopy(destination: XNode, source: XNode): XNode;
94
+ /**
95
+ * Implements `xsl:comment`.
96
+ * @param context The Expression Context.
97
+ * @param template The template.
98
+ * @param output The output. Only used if there's no corresponding output node already defined.
99
+ */
100
+ protected xsltComment(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
86
101
  /**
87
102
  * Implements `xsl:copy-of` for node-set values of the select
88
103
  * expression. Recurses down the source node tree, which is part of
@@ -91,20 +106,54 @@ export declare class Xslt {
91
106
  * @param {XNode} source the node being copied, part in input document.
92
107
  */
93
108
  protected xsltCopyOf(destination: XNode, source: XNode): void;
109
+ /**
110
+ * Implements `xsl:decimal-format`, registering the settings in this instance
111
+ * and the current context.
112
+ * @param context The Expression Context.
113
+ * @param template The template.
114
+ */
115
+ protected xsltDecimalFormat(context: ExprContext, template: XNode): void;
116
+ /**
117
+ * Implements `xsl:element`.
118
+ * @param context The Expression Context.
119
+ * @param template The template.
120
+ */
121
+ protected xsltElement(context: ExprContext, template: XNode): Promise<void>;
94
122
  /**
95
123
  * Implements `xsl:for-each`.
96
124
  * @param context The Expression Context.
97
125
  * @param template The template.
98
126
  * @param output The output.
99
127
  */
100
- protected xsltForEach(context: ExprContext, template: XNode, output: XNode): Promise<void>;
128
+ protected xsltForEach(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
129
+ /**
130
+ * Implements `xsl:if`.
131
+ * @param context The Expression Context.
132
+ * @param template The template.
133
+ * @param output The output.
134
+ */
135
+ protected xsltIf(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
136
+ /**
137
+ * Implements `<xsl:import>`. For now the code is nearly identical to `<xsl:include>`, but there's
138
+ * no precedence evaluation implemented yet.
139
+ * @param context The Expression Context.
140
+ * @param template The template.
141
+ * @param output The output.
142
+ */
143
+ protected xsltImport(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
101
144
  /**
102
145
  * Implements `xsl:include`.
103
146
  * @param context The Expression Context.
104
147
  * @param template The template.
105
148
  * @param output The output.
106
149
  */
107
- protected xsltInclude(context: ExprContext, template: XNode, output: XNode): Promise<void>;
150
+ protected xsltInclude(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
151
+ /**
152
+ * Implements `xsl:key`.
153
+ * @param context The Expression Context.
154
+ * @param template The template.
155
+ */
156
+ protected xsltKey(context: ExprContext, template: XNode): void;
108
157
  /**
109
158
  * Orders the current node list in the input context according to the
110
159
  * sort order specified by xsl:sort child nodes of the current
@@ -115,14 +164,25 @@ export declare class Xslt {
115
164
  * @todo case-order is not implemented.
116
165
  */
117
166
  protected xsltSort(context: ExprContext, template: XNode): void;
167
+ /**
168
+ * Implements `xsl:template`.
169
+ * @param context The Expression Context.
170
+ * @param template The `<xsl:template>` node.
171
+ * @param output The output. In general, a fragment that will be used by
172
+ * the caller.
173
+ */
174
+ protected xsltTemplate(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
175
+ protected xsltText(context: ExprContext, template: XNode, output?: XNode): void;
118
176
  /**
119
177
  * Implements `<xsl:stylesheet>` and `<xsl:transform>`, and its corresponding
120
178
  * validations.
121
- * @param template The `<xsl:stylesheet>` or `<xsl:transform>` node.
122
179
  * @param context The Expression Context.
123
- * @param output The output XML.
180
+ * @param template The `<xsl:stylesheet>` or `<xsl:transform>` node.
181
+ * @param output The output. In general, a fragment that will be used by
182
+ * the caller.
124
183
  */
125
- protected xsltTransformOrStylesheet(template: XNode, context: ExprContext, output: XNode): Promise<void>;
184
+ protected xsltTransformOrStylesheet(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
185
+ protected xsltValueOf(context: ExprContext, template: XNode, output?: XNode): void;
126
186
  /**
127
187
  * Evaluates a variable or parameter and set it in the current input
128
188
  * context. Implements `xsl:variable`, `xsl:param`, and `xsl:with-param`.
@@ -148,6 +208,8 @@ export declare class Xslt {
148
208
  * This logic is used in two different places:
149
209
  * - `xsltPassThrough`, if the template asks this library to write a text node;
150
210
  * - `xsltProcessContext`, `apply-templates` operation, when the current node is text.
211
+ *
212
+ * Text nodes always require a parent, and they never have children.
151
213
  * @param context The Expression Context.
152
214
  * @param template The template, that contains the node value to be written.
153
215
  * @param output The output.
@@ -203,5 +265,5 @@ export declare class Xslt {
203
265
  * @param template The template node.
204
266
  */
205
267
  protected xsltWithParam(context: ExprContext, template: XNode): Promise<void>;
206
- protected isXsltElement(element: any, opt_wantedName?: string): boolean;
268
+ protected isXsltElement(element: XNode, opt_wantedName?: string): boolean;
207
269
  }