@tradik/xslt-processor 1.0.2 → 1.1.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 +292 -47
- package/bin/lib/options.js +114 -0
- package/bin/lib/paths.js +186 -0
- package/bin/lib/transform.js +115 -0
- package/bin/xslt.js +68 -162
- package/dist/xslt-processor.browser.js +2073 -163
- package/dist/xslt-processor.browser.js.map +4 -4
- package/dist/xslt-processor.browser.min.js +6 -2
- package/dist/xslt-processor.browser.min.js.map +4 -4
- package/dist/xslt-processor.cjs +2077 -162
- package/dist/xslt-processor.cjs.map +4 -4
- package/dist/xslt-processor.d.cts +299 -0
- package/dist/xslt-processor.d.ts +92 -4
- package/dist/xslt-processor.js +2072 -161
- package/dist/xslt-processor.js.map +4 -4
- package/package.json +27 -16
- package/src/XSLTProcessor.js +177 -8
- package/src/index.js +11 -5
- package/src/xpath/evaluator.js +48 -7
- package/src/xslt/elements.js +57 -0
- package/src/xslt/engine.js +474 -185
- package/src/xslt/formatNumber.js +220 -0
- package/src/xslt/functions.js +191 -0
- package/src/xslt/index.js +31 -0
- package/src/xslt/keys.js +141 -0
- package/src/xslt/literalResult.js +167 -0
- package/src/xslt/number.js +178 -0
- package/src/xslt/numberFormat.js +155 -0
- package/src/xslt/resultTree.js +74 -0
- package/src/xslt/serializer/baseWriter.js +283 -0
- package/src/xslt/serializer/constants.js +78 -0
- package/src/xslt/serializer/escape.js +98 -0
- package/src/xslt/serializer/htmlSerializer.js +141 -0
- package/src/xslt/serializer/indent.js +51 -0
- package/src/xslt/serializer/namespaces.js +68 -0
- package/src/xslt/serializer/rawText.js +41 -0
- package/src/xslt/serializer/settings.js +103 -0
- package/src/xslt/serializer/textSerializer.js +29 -0
- package/src/xslt/serializer/xmlSerializer.js +127 -0
- package/src/xslt/serializer.js +57 -0
- package/src/xslt/templatePriority.js +45 -0
- package/src/xslt/uri.js +68 -0
- package/src/xslt/whitespace.js +184 -0
- package/src/XSLTProcessor.test.js +0 -930
- package/src/xpath/evaluator.test.js +0 -1852
- package/src/xpath/tokenizer.test.js +0 -224
- package/src/xslt/engine.test.js +0 -3130
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* XPath Tokenizer Tests
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { describe, it } from "node:test";
|
|
6
|
-
import assert from "node:assert";
|
|
7
|
-
import { tokenize, TokenType } from "./tokenizer.js";
|
|
8
|
-
|
|
9
|
-
describe("XPath Tokenizer", () => {
|
|
10
|
-
describe("Simple paths", () => {
|
|
11
|
-
it("should tokenize simple element name", () => {
|
|
12
|
-
const tokens = tokenize("foo");
|
|
13
|
-
assert.strictEqual(tokens.length, 2);
|
|
14
|
-
assert.strictEqual(tokens[0].type, TokenType.NAME);
|
|
15
|
-
assert.strictEqual(tokens[0].value, "foo");
|
|
16
|
-
assert.strictEqual(tokens[1].type, TokenType.EOF);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("should tokenize root path", () => {
|
|
20
|
-
const tokens = tokenize("/");
|
|
21
|
-
assert.strictEqual(tokens[0].type, TokenType.SLASH);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it("should tokenize absolute path", () => {
|
|
25
|
-
const tokens = tokenize("/foo/bar");
|
|
26
|
-
assert.strictEqual(tokens[0].type, TokenType.SLASH);
|
|
27
|
-
assert.strictEqual(tokens[1].type, TokenType.NAME);
|
|
28
|
-
assert.strictEqual(tokens[1].value, "foo");
|
|
29
|
-
assert.strictEqual(tokens[2].type, TokenType.SLASH);
|
|
30
|
-
assert.strictEqual(tokens[3].type, TokenType.NAME);
|
|
31
|
-
assert.strictEqual(tokens[3].value, "bar");
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("should tokenize descendant path", () => {
|
|
35
|
-
const tokens = tokenize("//foo");
|
|
36
|
-
assert.strictEqual(tokens[0].type, TokenType.DOUBLE_SLASH);
|
|
37
|
-
assert.strictEqual(tokens[1].type, TokenType.NAME);
|
|
38
|
-
assert.strictEqual(tokens[1].value, "foo");
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
describe("Wildcards and special characters", () => {
|
|
43
|
-
it("should tokenize wildcard", () => {
|
|
44
|
-
const tokens = tokenize("*");
|
|
45
|
-
assert.strictEqual(tokens[0].type, TokenType.STAR);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("should tokenize attribute selector", () => {
|
|
49
|
-
const tokens = tokenize("@id");
|
|
50
|
-
assert.strictEqual(tokens[0].type, TokenType.AT);
|
|
51
|
-
assert.strictEqual(tokens[1].type, TokenType.NAME);
|
|
52
|
-
assert.strictEqual(tokens[1].value, "id");
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it("should tokenize dot (self)", () => {
|
|
56
|
-
const tokens = tokenize(".");
|
|
57
|
-
assert.strictEqual(tokens[0].type, TokenType.DOT);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("should tokenize double dot (parent)", () => {
|
|
61
|
-
const tokens = tokenize("..");
|
|
62
|
-
assert.strictEqual(tokens[0].type, TokenType.DOUBLE_DOT);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
describe("Predicates", () => {
|
|
67
|
-
it("should tokenize predicate brackets", () => {
|
|
68
|
-
const tokens = tokenize("foo[1]");
|
|
69
|
-
assert.strictEqual(tokens[0].type, TokenType.NAME);
|
|
70
|
-
assert.strictEqual(tokens[1].type, TokenType.LBRACKET);
|
|
71
|
-
assert.strictEqual(tokens[2].type, TokenType.NUMBER);
|
|
72
|
-
assert.strictEqual(tokens[2].value, 1);
|
|
73
|
-
assert.strictEqual(tokens[3].type, TokenType.RBRACKET);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it("should tokenize complex predicate", () => {
|
|
77
|
-
const tokens = tokenize('item[@id="test"]');
|
|
78
|
-
assert.strictEqual(tokens[0].type, TokenType.NAME);
|
|
79
|
-
assert.strictEqual(tokens[1].type, TokenType.LBRACKET);
|
|
80
|
-
assert.strictEqual(tokens[2].type, TokenType.AT);
|
|
81
|
-
assert.strictEqual(tokens[3].type, TokenType.NAME);
|
|
82
|
-
assert.strictEqual(tokens[4].type, TokenType.EQUALS);
|
|
83
|
-
assert.strictEqual(tokens[5].type, TokenType.LITERAL);
|
|
84
|
-
assert.strictEqual(tokens[5].value, "test");
|
|
85
|
-
assert.strictEqual(tokens[6].type, TokenType.RBRACKET);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe("Operators", () => {
|
|
90
|
-
it("should tokenize arithmetic operators", () => {
|
|
91
|
-
const tokens = tokenize("1 + 2 - 3 * 4");
|
|
92
|
-
assert.strictEqual(tokens[0].type, TokenType.NUMBER);
|
|
93
|
-
assert.strictEqual(tokens[1].type, TokenType.PLUS);
|
|
94
|
-
assert.strictEqual(tokens[2].type, TokenType.NUMBER);
|
|
95
|
-
assert.strictEqual(tokens[3].type, TokenType.MINUS);
|
|
96
|
-
assert.strictEqual(tokens[4].type, TokenType.NUMBER);
|
|
97
|
-
assert.strictEqual(tokens[5].type, TokenType.STAR);
|
|
98
|
-
assert.strictEqual(tokens[6].type, TokenType.NUMBER);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it("should tokenize comparison operators", () => {
|
|
102
|
-
const tokens = tokenize("a = b != c < d <= e > f >= g");
|
|
103
|
-
assert.strictEqual(tokens[1].type, TokenType.EQUALS);
|
|
104
|
-
assert.strictEqual(tokens[3].type, TokenType.NOT_EQUALS);
|
|
105
|
-
assert.strictEqual(tokens[5].type, TokenType.LT);
|
|
106
|
-
assert.strictEqual(tokens[7].type, TokenType.LTE);
|
|
107
|
-
assert.strictEqual(tokens[9].type, TokenType.GT);
|
|
108
|
-
assert.strictEqual(tokens[11].type, TokenType.GTE);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it("should tokenize logical operators", () => {
|
|
112
|
-
const tokens = tokenize("a and b or c");
|
|
113
|
-
assert.strictEqual(tokens[0].type, TokenType.NAME);
|
|
114
|
-
assert.strictEqual(tokens[1].type, TokenType.AND);
|
|
115
|
-
assert.strictEqual(tokens[2].type, TokenType.NAME);
|
|
116
|
-
assert.strictEqual(tokens[3].type, TokenType.OR);
|
|
117
|
-
assert.strictEqual(tokens[4].type, TokenType.NAME);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it("should tokenize div and mod", () => {
|
|
121
|
-
const tokens = tokenize("10 div 3 mod 2");
|
|
122
|
-
assert.strictEqual(tokens[1].type, TokenType.DIV);
|
|
123
|
-
assert.strictEqual(tokens[3].type, TokenType.MOD);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it("should tokenize union operator", () => {
|
|
127
|
-
const tokens = tokenize("a | b");
|
|
128
|
-
assert.strictEqual(tokens[1].type, TokenType.PIPE);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
describe("Literals", () => {
|
|
133
|
-
it("should tokenize double-quoted string", () => {
|
|
134
|
-
const tokens = tokenize('"hello world"');
|
|
135
|
-
assert.strictEqual(tokens[0].type, TokenType.LITERAL);
|
|
136
|
-
assert.strictEqual(tokens[0].value, "hello world");
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it("should tokenize single-quoted string", () => {
|
|
140
|
-
const tokens = tokenize("'hello world'");
|
|
141
|
-
assert.strictEqual(tokens[0].type, TokenType.LITERAL);
|
|
142
|
-
assert.strictEqual(tokens[0].value, "hello world");
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it("should tokenize integer", () => {
|
|
146
|
-
const tokens = tokenize("42");
|
|
147
|
-
assert.strictEqual(tokens[0].type, TokenType.NUMBER);
|
|
148
|
-
assert.strictEqual(tokens[0].value, 42);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it("should tokenize decimal number", () => {
|
|
152
|
-
const tokens = tokenize("3.14");
|
|
153
|
-
assert.strictEqual(tokens[0].type, TokenType.NUMBER);
|
|
154
|
-
assert.strictEqual(tokens[0].value, 3.14);
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it("should tokenize decimal starting with dot", () => {
|
|
158
|
-
const tokens = tokenize(".5");
|
|
159
|
-
assert.strictEqual(tokens[0].type, TokenType.NUMBER);
|
|
160
|
-
assert.strictEqual(tokens[0].value, 0.5);
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
describe("Functions", () => {
|
|
165
|
-
it("should tokenize function call", () => {
|
|
166
|
-
const tokens = tokenize("contains(a, b)");
|
|
167
|
-
assert.strictEqual(tokens[0].type, TokenType.FUNCTION);
|
|
168
|
-
assert.strictEqual(tokens[0].value, "contains");
|
|
169
|
-
assert.strictEqual(tokens[1].type, TokenType.LPAREN);
|
|
170
|
-
assert.strictEqual(tokens[2].type, TokenType.NAME);
|
|
171
|
-
assert.strictEqual(tokens[3].type, TokenType.COMMA);
|
|
172
|
-
assert.strictEqual(tokens[4].type, TokenType.NAME);
|
|
173
|
-
assert.strictEqual(tokens[5].type, TokenType.RPAREN);
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it("should tokenize node type test", () => {
|
|
177
|
-
const tokens = tokenize("text()");
|
|
178
|
-
assert.strictEqual(tokens[0].type, TokenType.NODE_TYPE);
|
|
179
|
-
assert.strictEqual(tokens[0].value, "text");
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it("should tokenize processing-instruction test", () => {
|
|
183
|
-
const tokens = tokenize("processing-instruction()");
|
|
184
|
-
assert.strictEqual(tokens[0].type, TokenType.NODE_TYPE);
|
|
185
|
-
assert.strictEqual(tokens[0].value, "processing-instruction");
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
describe("Axes", () => {
|
|
190
|
-
it("should tokenize axis with double colon", () => {
|
|
191
|
-
const tokens = tokenize("child::foo");
|
|
192
|
-
assert.strictEqual(tokens[0].type, TokenType.AXIS);
|
|
193
|
-
assert.strictEqual(tokens[0].value, "child");
|
|
194
|
-
assert.strictEqual(tokens[1].type, TokenType.DOUBLE_COLON);
|
|
195
|
-
assert.strictEqual(tokens[2].type, TokenType.NAME);
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
it("should tokenize descendant-or-self axis", () => {
|
|
199
|
-
const tokens = tokenize("descendant-or-self::node()");
|
|
200
|
-
assert.strictEqual(tokens[0].type, TokenType.AXIS);
|
|
201
|
-
assert.strictEqual(tokens[0].value, "descendant-or-self");
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
describe("Variables", () => {
|
|
206
|
-
it("should tokenize variable reference", () => {
|
|
207
|
-
const tokens = tokenize("$myVar");
|
|
208
|
-
assert.strictEqual(tokens[0].type, TokenType.DOLLAR);
|
|
209
|
-
assert.strictEqual(tokens[1].type, TokenType.NAME);
|
|
210
|
-
assert.strictEqual(tokens[1].value, "myVar");
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
describe("Complex expressions", () => {
|
|
215
|
-
it("should tokenize complex XPath expression", () => {
|
|
216
|
-
const expr = '//div[@class="content"]/p[position() > 1 and @id]';
|
|
217
|
-
const tokens = tokenize(expr);
|
|
218
|
-
|
|
219
|
-
// Verify tokenization completed without error
|
|
220
|
-
assert.ok(tokens.length > 0);
|
|
221
|
-
assert.strictEqual(tokens[tokens.length - 1].type, TokenType.EOF);
|
|
222
|
-
});
|
|
223
|
-
});
|
|
224
|
-
});
|