@tradik/xslt-processor 1.1.1 → 1.3.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/LICENSE.md +1 -1
- package/README.md +102 -757
- package/bin/lib/decode.js +15 -0
- package/bin/lib/dom.js +177 -0
- package/bin/lib/loaders.js +127 -0
- package/bin/lib/options.js +17 -0
- package/bin/lib/output.js +114 -0
- package/bin/lib/paths.js +3 -3
- package/bin/lib/transform.js +124 -33
- package/bin/xslt.js +26 -27
- package/dist/xslt-processor.browser.js +8784 -2720
- package/dist/xslt-processor.browser.js.map +4 -4
- package/dist/xslt-processor.browser.min.js +13 -6
- package/dist/xslt-processor.browser.min.js.map +4 -4
- package/dist/xslt-processor.cjs +8789 -2723
- package/dist/xslt-processor.cjs.map +4 -4
- package/dist/xslt-processor.d.cts +380 -21
- package/dist/xslt-processor.d.ts +380 -21
- package/dist/xslt-processor.js +8770 -2722
- package/dist/xslt-processor.js.map +4 -4
- package/package.json +51 -11
- package/src/XSLTProcessor.js +343 -66
- package/src/async/abort.js +63 -0
- package/src/async/documentUris.js +128 -0
- package/src/async/loaders.js +134 -0
- package/src/async/preload.js +159 -0
- package/src/async/processor.js +206 -0
- package/src/async/stream.js +125 -0
- package/src/bridge/engine.js +221 -0
- package/src/bridge/loader.js +78 -0
- package/src/bridge/results.js +75 -0
- package/src/bridge/version.js +63 -0
- package/src/index.js +16 -4
- package/src/io/decode.js +140 -0
- package/src/io/readSource.js +167 -0
- package/src/xpath/axes.js +562 -0
- package/src/xpath/documentOrder.js +270 -0
- package/src/xpath/evaluator.js +475 -355
- package/src/xpath/index.js +8 -2
- package/src/xpath/namespaceNodes.js +172 -0
- package/src/xpath/nodeSetFunctions.js +169 -0
- package/src/xpath/parser.js +30 -5
- package/src/xpath/strings.js +183 -0
- package/src/xpath/tokenizer.js +37 -23
- package/src/xslt/attributeSets.js +95 -0
- package/src/xslt/avt.js +103 -0
- package/src/xslt/computedNames.js +91 -0
- package/src/xslt/copying.js +212 -0
- package/src/xslt/declarationNames.js +80 -0
- package/src/xslt/domParsing.js +95 -0
- package/src/xslt/elements.js +1 -1
- package/src/xslt/engine/bindings.js +195 -0
- package/src/xslt/engine/context.js +105 -0
- package/src/xslt/engine/controlFlow.js +145 -0
- package/src/xslt/engine/copyInstructions.js +133 -0
- package/src/xslt/engine/declarations.js +233 -0
- package/src/xslt/engine/functionSupport.js +103 -0
- package/src/xslt/engine/methods.js +33 -0
- package/src/xslt/engine/nodeConstruction.js +187 -0
- package/src/xslt/engine/numbering.js +104 -0
- package/src/xslt/engine/outputDeclaration.js +77 -0
- package/src/xslt/engine/sequenceConstructor.js +228 -0
- package/src/xslt/engine/stylesheetLoading.js +208 -0
- package/src/xslt/engine/templateInvocation.js +253 -0
- package/src/xslt/engine/templateRules.js +243 -0
- package/src/xslt/engine/textInstructions.js +171 -0
- package/src/xslt/engine/topLevel.js +130 -0
- package/src/xslt/engine/transformation.js +263 -0
- package/src/xslt/engine/workStack.js +245 -0
- package/src/xslt/engine.js +176 -2020
- package/src/xslt/exslt/arguments.js +99 -0
- package/src/xslt/exslt/calendar.js +120 -0
- package/src/xslt/exslt/common.js +44 -0
- package/src/xslt/exslt/dateCalc.js +261 -0
- package/src/xslt/exslt/dateFormat.js +150 -0
- package/src/xslt/exslt/dateParse.js +265 -0
- package/src/xslt/exslt/dates.js +259 -0
- package/src/xslt/exslt/duration.js +207 -0
- package/src/xslt/exslt/dynamic.js +59 -0
- package/src/xslt/exslt/index.js +59 -0
- package/src/xslt/exslt/math.js +177 -0
- package/src/xslt/exslt/sets.js +96 -0
- package/src/xslt/exslt/stringOps.js +163 -0
- package/src/xslt/exslt/strings.js +147 -0
- package/src/xslt/exslt/uri.js +92 -0
- package/src/xslt/formatNumber.js +22 -9
- package/src/xslt/forwardsCompatible.js +75 -0
- package/src/xslt/functions.js +94 -15
- package/src/xslt/index.js +7 -1
- package/src/xslt/keys.js +51 -28
- package/src/xslt/literalResult.js +63 -7
- package/src/xslt/matchScope.js +116 -0
- package/src/xslt/number.js +171 -78
- package/src/xslt/numberFormat.js +124 -26
- package/src/xslt/outputNames.js +58 -0
- package/src/xslt/patternCompiler.js +175 -0
- package/src/xslt/patterns.js +324 -0
- package/src/xslt/qname.js +90 -0
- package/src/xslt/resultDocument.js +98 -0
- package/src/xslt/resultNamespaces.js +219 -0
- package/src/xslt/resultTree.js +143 -6
- package/src/xslt/serializer/baseWriter.js +173 -66
- package/src/xslt/serializer/chunks.js +120 -0
- package/src/xslt/serializer/constants.js +14 -0
- package/src/xslt/serializer/encoding.js +327 -0
- package/src/xslt/serializer/escape.js +49 -12
- package/src/xslt/serializer/frames.js +168 -0
- package/src/xslt/serializer/htmlDoctype.js +102 -0
- package/src/xslt/serializer/htmlEntities.js +77 -0
- package/src/xslt/serializer/htmlSerializer.js +123 -25
- package/src/xslt/serializer/settings.js +89 -13
- package/src/xslt/serializer/textSerializer.js +58 -10
- package/src/xslt/serializer/xhtmlDocument.js +103 -0
- package/src/xslt/serializer/xmlSerializer.js +113 -13
- package/src/xslt/serializer.js +50 -17
- package/src/xslt/sort.js +151 -0
- package/src/xslt/spaceNameTests.js +115 -0
- package/src/xslt/stylesheetChecks.js +206 -0
- package/src/xslt/stylesheetNamespaces.js +266 -0
- package/src/xslt/variables.js +152 -0
- package/src/xslt/whitespace.js +43 -27
- package/LICENSE +0 -29
package/dist/xslt-processor.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @tradik/xslt-processor - TypeScript Declarations
|
|
3
|
+
*
|
|
4
|
+
* Source of dist/xslt-processor.d.ts and dist/xslt-processor.d.cts, copied
|
|
5
|
+
* by scripts/build.js. Keep it in step with the exports of src/index.js.
|
|
3
6
|
*/
|
|
4
7
|
|
|
5
8
|
/**
|
|
@@ -11,17 +14,147 @@
|
|
|
11
14
|
* @param href - The resolved URI of the referenced stylesheet
|
|
12
15
|
* @param baseUri - The URI of the importing/including stylesheet, if known
|
|
13
16
|
*/
|
|
14
|
-
export type StylesheetLoader = (
|
|
17
|
+
export type StylesheetLoader = (
|
|
18
|
+
href: string,
|
|
19
|
+
baseUri?: string,
|
|
20
|
+
) => Document | string;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Loader used by the XSLT document() function.
|
|
24
|
+
*
|
|
25
|
+
* The loader is synchronous: it must return the document as a Document, as an
|
|
26
|
+
* XML string (which is parsed automatically) or null when it is unavailable
|
|
27
|
+
* (document() then evaluates to an empty node-set).
|
|
28
|
+
*
|
|
29
|
+
* @param uri - The resolved URI of the requested document
|
|
30
|
+
* @param baseUri - The base URI the reference was resolved against, if known
|
|
31
|
+
*/
|
|
32
|
+
export type DocumentLoader = (
|
|
33
|
+
uri: string,
|
|
34
|
+
baseUri?: string,
|
|
35
|
+
) => Document | string | null;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Anything with a DOMParser-like parseFromString method (a browser, jsdom or
|
|
39
|
+
* xmldom DOMParser instance).
|
|
40
|
+
*/
|
|
41
|
+
export interface DomParserLike {
|
|
42
|
+
parseFromString(text: string, type: string): Document;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* What an asynchronous loader may resolve to: a Document, markup, bytes
|
|
47
|
+
* (decoded from the byte order mark or XML declaration, else UTF-8), a fetch
|
|
48
|
+
* Response, or null when the resource is unavailable.
|
|
49
|
+
*/
|
|
50
|
+
export type AsyncLoaderResult =
|
|
51
|
+
Document | string | Uint8Array | ArrayBuffer | Response | null;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Asynchronous loader of stylesheet modules and document() documents.
|
|
55
|
+
* @param uri - The resolved URI
|
|
56
|
+
* @param baseUri - The URI it was resolved against, if known
|
|
57
|
+
* @param init - Holds the AbortSignal of the call
|
|
58
|
+
*/
|
|
59
|
+
export type AsyncLoader = (
|
|
60
|
+
uri: string,
|
|
61
|
+
baseUri: string | undefined,
|
|
62
|
+
init: { signal?: AbortSignal },
|
|
63
|
+
) => AsyncLoaderResult | Promise<AsyncLoaderResult>;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Input of the asynchronous API: a node, markup, bytes, or a stream of
|
|
67
|
+
* markup/bytes. Streams are read to their end before parsing (XSLT 1.0 needs
|
|
68
|
+
* the whole source tree).
|
|
69
|
+
*/
|
|
70
|
+
export type AsyncSource =
|
|
71
|
+
| Node
|
|
72
|
+
| string
|
|
73
|
+
| Uint8Array
|
|
74
|
+
| ArrayBuffer
|
|
75
|
+
| ReadableStream<string | Uint8Array | ArrayBuffer>
|
|
76
|
+
| AsyncIterable<string | Uint8Array | ArrayBuffer>;
|
|
77
|
+
|
|
78
|
+
/** Options of transformToStream. */
|
|
79
|
+
export interface StreamOptions {
|
|
80
|
+
/** Cancels: the stream is errored with the abort reason. */
|
|
81
|
+
signal?: AbortSignal;
|
|
82
|
+
/** Chunk size in UTF-16 code units (default 16384); Infinity for one chunk. */
|
|
83
|
+
chunkSize?: number;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Options of importStylesheetAsync. */
|
|
87
|
+
export interface ImportAsyncOptions {
|
|
88
|
+
/** Loader of xsl:import/xsl:include modules; the global fetch by default. */
|
|
89
|
+
loader?: AsyncLoader;
|
|
90
|
+
/** Loader of literal document() documents; `loader` by default. */
|
|
91
|
+
documentLoader?: AsyncLoader;
|
|
92
|
+
/** Cancels loading. */
|
|
93
|
+
signal?: AbortSignal;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Options of transformAsync. */
|
|
97
|
+
export interface TransformAsyncOptions {
|
|
98
|
+
/** Cancels loading and reading. */
|
|
99
|
+
signal?: AbortSignal;
|
|
100
|
+
/** A stylesheet to import first with importStylesheetAsync. */
|
|
101
|
+
stylesheet?: AsyncSource;
|
|
102
|
+
/** The URI of that stylesheet. */
|
|
103
|
+
stylesheetUri?: string;
|
|
104
|
+
/** Loader of its xsl:import/xsl:include modules (fetch by default). */
|
|
105
|
+
fetchStylesheet?: AsyncLoader;
|
|
106
|
+
/** Loader of the literal document() documents of the stylesheet. */
|
|
107
|
+
fetchDocument?: AsyncLoader;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** The `xsltVersion` option of XSLTProcessor. */
|
|
111
|
+
export type XsltVersionMode = "1.0" | "auto";
|
|
15
112
|
|
|
16
113
|
/**
|
|
17
114
|
* XSLTProcessor - Applies XSLT stylesheet transformations to XML documents.
|
|
18
115
|
*/
|
|
19
116
|
export class XSLTProcessor {
|
|
20
|
-
constructor(
|
|
117
|
+
constructor(options?: {
|
|
118
|
+
/**
|
|
119
|
+
* @deprecated Let unprefixed name tests (`item`, `@a`) also match nodes
|
|
120
|
+
* in a namespace, as before 1.2.0. XPath 1.0 and Chrome match only nodes
|
|
121
|
+
* in no namespace.
|
|
122
|
+
*/
|
|
123
|
+
legacyNameTests?: boolean;
|
|
124
|
+
/** Allow EXSLT `dyn:evaluate()`; it evaluates XPath built from data. */
|
|
125
|
+
enableDynamicEvaluate?: boolean;
|
|
126
|
+
/** Clock for EXSLT current-time functions (reproducible output). */
|
|
127
|
+
clock?: () => Date;
|
|
128
|
+
/**
|
|
129
|
+
* Deepest nesting of template instantiations; deeper recursion throws
|
|
130
|
+
* "Template recursion too deep" (default 3000, as in libxslt).
|
|
131
|
+
*/
|
|
132
|
+
maxTemplateDepth?: number;
|
|
133
|
+
/**
|
|
134
|
+
* "1.0" (default): every stylesheet runs with the XSLT 1.0 engine, a
|
|
135
|
+
* version="2.0" one in forwards-compatible mode (as in Chrome).
|
|
136
|
+
* "auto": a stylesheet whose version is 2.0 or more runs with the
|
|
137
|
+
* optional peer dependency @tradik/xslt3, loaded with import() by the
|
|
138
|
+
* asynchronous API or by {@link XSLTProcessor.preload}.
|
|
139
|
+
* @throws RangeError for any other value
|
|
140
|
+
*/
|
|
141
|
+
xsltVersion?: XsltVersionMode;
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Load @tradik/xslt3 so that the synchronous API of processors created
|
|
146
|
+
* with `xsltVersion: "auto"` can run XSLT 2.0/3.0 stylesheets (non-W3C).
|
|
147
|
+
* Rejects with "Cannot load @tradik/xslt3: install @tradik/xslt3 to run
|
|
148
|
+
* XSLT 2.0/3.0 stylesheets" when the package is missing.
|
|
149
|
+
* @param version - "3.0" (default) or "2.0"
|
|
150
|
+
*/
|
|
151
|
+
static preload(version?: "2.0" | "3.0"): Promise<void>;
|
|
21
152
|
|
|
22
153
|
/**
|
|
23
154
|
* The underlying XSLT engine (advanced usage).
|
|
24
|
-
* Null until a stylesheet has been imported.
|
|
155
|
+
* Null until a stylesheet has been imported. With `xsltVersion: "auto"`
|
|
156
|
+
* and an XSLT 2.0/3.0 stylesheet it is the @tradik/xslt3 bridge engine,
|
|
157
|
+
* which has `outputSettings` but not the other XsltEngine members.
|
|
25
158
|
*/
|
|
26
159
|
readonly engine: XsltEngine | null;
|
|
27
160
|
|
|
@@ -34,8 +167,18 @@ export class XSLTProcessor {
|
|
|
34
167
|
*/
|
|
35
168
|
setStylesheetLoader(loader: StylesheetLoader | null): this;
|
|
36
169
|
|
|
170
|
+
/**
|
|
171
|
+
* Sets the loader used by the XSLT document() function. It may be set
|
|
172
|
+
* before or after importStylesheet(); a live engine is kept in sync.
|
|
173
|
+
* @param loader - The loader function, or null to remove it
|
|
174
|
+
* @returns This processor, to allow chaining
|
|
175
|
+
*/
|
|
176
|
+
setDocumentLoader(loader: DocumentLoader | null): this;
|
|
177
|
+
|
|
37
178
|
/**
|
|
38
179
|
* Imports the XSLT stylesheet.
|
|
180
|
+
* Throws when the stylesheet is malformed or invalid (for example when a
|
|
181
|
+
* pattern is invalid); the processor then keeps its previous stylesheet.
|
|
39
182
|
* @param style - The XSLT stylesheet to import (Document or Element)
|
|
40
183
|
* @param stylesheetUri - Optional base URI used to resolve relative
|
|
41
184
|
* xsl:import/xsl:include hrefs
|
|
@@ -65,13 +208,54 @@ export class XSLTProcessor {
|
|
|
65
208
|
*/
|
|
66
209
|
transformToString(source: Node): string | null;
|
|
67
210
|
|
|
211
|
+
/**
|
|
212
|
+
* Imports a stylesheet after loading its xsl:import/xsl:include tree and
|
|
213
|
+
* its literal document() documents asynchronously (non-W3C). Rejects on a
|
|
214
|
+
* load failure or an import cycle; the previous stylesheet is then kept.
|
|
215
|
+
* @param style - The stylesheet, as a node or as markup/stream to parse
|
|
216
|
+
* @param stylesheetUri - Base URI of relative hrefs and document() URIs
|
|
217
|
+
* @param options - Loaders and AbortSignal
|
|
218
|
+
*/
|
|
219
|
+
importStylesheetAsync(
|
|
220
|
+
style: AsyncSource,
|
|
221
|
+
stylesheetUri?: string,
|
|
222
|
+
options?: ImportAsyncOptions,
|
|
223
|
+
): Promise<void>;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Transforms asynchronously and resolves with the serialized result
|
|
227
|
+
* (non-W3C). Unlike transformToString, failures reject.
|
|
228
|
+
* @param source - Node, markup, bytes or stream of the source document
|
|
229
|
+
* @param options - AbortSignal, optional stylesheet and loaders
|
|
230
|
+
*/
|
|
231
|
+
transformAsync(
|
|
232
|
+
source: AsyncSource,
|
|
233
|
+
options?: TransformAsyncOptions,
|
|
234
|
+
): Promise<string>;
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Transforms and streams the serialized result in chunks (non-W3C). The
|
|
238
|
+
* result tree is built in memory on the first read; the output string is
|
|
239
|
+
* produced chunk by chunk on demand. Failures error the stream.
|
|
240
|
+
* @param source - Node, markup, bytes or stream of the source document
|
|
241
|
+
* @param options - AbortSignal and chunk size
|
|
242
|
+
*/
|
|
243
|
+
transformToStream(
|
|
244
|
+
source: AsyncSource,
|
|
245
|
+
options?: StreamOptions,
|
|
246
|
+
): ReadableStream<string>;
|
|
247
|
+
|
|
68
248
|
/**
|
|
69
249
|
* Sets a parameter in the XSLT stylesheet.
|
|
70
250
|
* @param namespaceURI - The namespace URI (use null for no namespace)
|
|
71
251
|
* @param localName - The local name of the parameter
|
|
72
252
|
* @param value - The value to set
|
|
73
253
|
*/
|
|
74
|
-
setParameter(
|
|
254
|
+
setParameter(
|
|
255
|
+
namespaceURI: string | null,
|
|
256
|
+
localName: string,
|
|
257
|
+
value: unknown,
|
|
258
|
+
): void;
|
|
75
259
|
|
|
76
260
|
/**
|
|
77
261
|
* Gets the value of a parameter from the XSLT stylesheet.
|
|
@@ -95,13 +279,14 @@ export class XSLTProcessor {
|
|
|
95
279
|
|
|
96
280
|
/**
|
|
97
281
|
* Removes all parameters and stylesheets from the XSLTProcessor.
|
|
98
|
-
* The
|
|
282
|
+
* The loaders are configuration, not stylesheet state, and are preserved.
|
|
99
283
|
*/
|
|
100
284
|
reset(): void;
|
|
101
285
|
}
|
|
102
286
|
|
|
103
287
|
/**
|
|
104
|
-
* Check if native XSLTProcessor is available and functional.
|
|
288
|
+
* Check if native XSLTProcessor is available and functional. After
|
|
289
|
+
* installGlobal() replaced it, the original native implementation is probed.
|
|
105
290
|
*/
|
|
106
291
|
export function isNativeXSLTSupported(): boolean;
|
|
107
292
|
|
|
@@ -128,6 +313,16 @@ export const XPathResultType: {
|
|
|
128
313
|
FIRST_ORDERED_NODE_TYPE: 9;
|
|
129
314
|
};
|
|
130
315
|
|
|
316
|
+
/**
|
|
317
|
+
* Default limits of the standalone XPath evaluator, guarding against
|
|
318
|
+
* untrusted expressions.
|
|
319
|
+
*/
|
|
320
|
+
export const XPathLimits: {
|
|
321
|
+
MAX_RECURSION_DEPTH: number;
|
|
322
|
+
MAX_RESULT_SIZE: number;
|
|
323
|
+
MAX_STRING_LENGTH: number;
|
|
324
|
+
};
|
|
325
|
+
|
|
131
326
|
/**
|
|
132
327
|
* XPath evaluation context.
|
|
133
328
|
*/
|
|
@@ -137,7 +332,8 @@ export class XPathContext {
|
|
|
137
332
|
position?: number,
|
|
138
333
|
size?: number,
|
|
139
334
|
variables?: Record<string, unknown>,
|
|
140
|
-
namespaces?: Record<string, string
|
|
335
|
+
namespaces?: Record<string, string>,
|
|
336
|
+
hostContext?: unknown,
|
|
141
337
|
);
|
|
142
338
|
|
|
143
339
|
node: Node;
|
|
@@ -145,17 +341,48 @@ export class XPathContext {
|
|
|
145
341
|
size: number;
|
|
146
342
|
variables: Record<string, unknown>;
|
|
147
343
|
namespaces: Record<string, string>;
|
|
344
|
+
/** Opaque context of the host language (XSLT), for host defined functions. */
|
|
345
|
+
hostContext: unknown;
|
|
148
346
|
|
|
149
347
|
clone(overrides?: Partial<XPathContext>): XPathContext;
|
|
150
348
|
}
|
|
151
349
|
|
|
350
|
+
/**
|
|
351
|
+
* An extension function: called with the argument expressions (unevaluated
|
|
352
|
+
* ASTs) and the evaluation context, with the evaluator as `this`.
|
|
353
|
+
*/
|
|
354
|
+
export type XPathFunction = (
|
|
355
|
+
this: XPathEvaluator,
|
|
356
|
+
args: unknown[],
|
|
357
|
+
context: XPathContext,
|
|
358
|
+
) => unknown;
|
|
359
|
+
|
|
152
360
|
/**
|
|
153
361
|
* XPath evaluator.
|
|
154
362
|
*/
|
|
155
363
|
export class XPathEvaluator {
|
|
156
|
-
constructor(
|
|
364
|
+
constructor(options?: {
|
|
365
|
+
/** Deepest expression nesting (default XPathLimits.MAX_RECURSION_DEPTH). */
|
|
366
|
+
maxRecursionDepth?: number;
|
|
367
|
+
/** Largest node-set one step may produce (default XPathLimits.MAX_RESULT_SIZE). */
|
|
368
|
+
maxResultSize?: number;
|
|
369
|
+
/** Longest string a function may produce (default XPathLimits.MAX_STRING_LENGTH). */
|
|
370
|
+
maxStringLength?: number;
|
|
371
|
+
/**
|
|
372
|
+
* @deprecated Let unprefixed name tests (`item`, `@a`) also match nodes
|
|
373
|
+
* in a namespace, as before 1.2.0. XPath 1.0 and Chrome match only nodes
|
|
374
|
+
* in no namespace.
|
|
375
|
+
*/
|
|
376
|
+
legacyNameTests?: boolean;
|
|
377
|
+
});
|
|
157
378
|
|
|
158
379
|
evaluate(ast: unknown, context: XPathContext): unknown;
|
|
380
|
+
/**
|
|
381
|
+
* Register extension functions by name, `{namespace-uri}local-name` for
|
|
382
|
+
* namespaced ones.
|
|
383
|
+
* @returns This evaluator, to allow chaining
|
|
384
|
+
*/
|
|
385
|
+
registerFunctions(functions: Record<string, XPathFunction>): this;
|
|
159
386
|
toBoolean(value: unknown): boolean;
|
|
160
387
|
toNumber(value: unknown): number;
|
|
161
388
|
toString(value: unknown): string;
|
|
@@ -168,7 +395,10 @@ export class XPathEvaluator {
|
|
|
168
395
|
export function evaluateXPath(
|
|
169
396
|
expression: string,
|
|
170
397
|
contextNode: Node,
|
|
171
|
-
options?: {
|
|
398
|
+
options?: {
|
|
399
|
+
variables?: Record<string, unknown>;
|
|
400
|
+
namespaces?: Record<string, string>;
|
|
401
|
+
},
|
|
172
402
|
): unknown;
|
|
173
403
|
|
|
174
404
|
/**
|
|
@@ -177,7 +407,10 @@ export function evaluateXPath(
|
|
|
177
407
|
export function selectXPath(
|
|
178
408
|
expression: string,
|
|
179
409
|
contextNode: Node,
|
|
180
|
-
options?: {
|
|
410
|
+
options?: {
|
|
411
|
+
variables?: Record<string, unknown>;
|
|
412
|
+
namespaces?: Record<string, string>;
|
|
413
|
+
},
|
|
181
414
|
): Node[];
|
|
182
415
|
|
|
183
416
|
/**
|
|
@@ -186,7 +419,10 @@ export function selectXPath(
|
|
|
186
419
|
export function selectFirstXPath(
|
|
187
420
|
expression: string,
|
|
188
421
|
contextNode: Node,
|
|
189
|
-
options?: {
|
|
422
|
+
options?: {
|
|
423
|
+
variables?: Record<string, unknown>;
|
|
424
|
+
namespaces?: Record<string, string>;
|
|
425
|
+
},
|
|
190
426
|
): Node | null;
|
|
191
427
|
|
|
192
428
|
/**
|
|
@@ -204,6 +440,8 @@ export class XsltContext {
|
|
|
204
440
|
position?: number;
|
|
205
441
|
variables?: Record<string, unknown>;
|
|
206
442
|
parameters?: Record<string, unknown>;
|
|
443
|
+
/** Global variables and parameters of the transformation. */
|
|
444
|
+
globals?: unknown;
|
|
207
445
|
outputDocument?: Document;
|
|
208
446
|
stylesheet?: Document;
|
|
209
447
|
namespaces?: Record<string, string>;
|
|
@@ -212,6 +450,10 @@ export class XsltContext {
|
|
|
212
450
|
decimalFormats?: Record<string, unknown>;
|
|
213
451
|
outputMethod?: string;
|
|
214
452
|
xpathEvaluator?: XPathEvaluator;
|
|
453
|
+
/** The template rule being instantiated (for xsl:apply-imports). */
|
|
454
|
+
currentTemplate?: unknown;
|
|
455
|
+
/** The current mode, null for the default mode. */
|
|
456
|
+
currentMode?: string | null;
|
|
215
457
|
});
|
|
216
458
|
|
|
217
459
|
clone(overrides?: Partial<XsltContext>): XsltContext;
|
|
@@ -219,15 +461,88 @@ export class XsltContext {
|
|
|
219
461
|
setVariable(name: string, value: unknown): void;
|
|
220
462
|
}
|
|
221
463
|
|
|
464
|
+
/**
|
|
465
|
+
* Default node-set limit of an XSLT transformation (5,000,000).
|
|
466
|
+
*/
|
|
467
|
+
export const XSLT_MAX_RESULT_SIZE: number;
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Default XPath expression depth limit of an XSLT transformation (1000).
|
|
471
|
+
*/
|
|
472
|
+
export const XSLT_MAX_EXPRESSION_DEPTH: number;
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Default limit of nested template instantiations in a transformation
|
|
476
|
+
* (3000, libxslt's `xsltMaxDepth`).
|
|
477
|
+
*/
|
|
478
|
+
export const XSLT_MAX_TEMPLATE_DEPTH: number;
|
|
479
|
+
|
|
222
480
|
/**
|
|
223
481
|
* XSLT processing engine.
|
|
224
482
|
*/
|
|
225
483
|
export class XsltEngine {
|
|
226
|
-
constructor(options?: {
|
|
484
|
+
constructor(options?: {
|
|
485
|
+
stylesheetLoader?: StylesheetLoader | null;
|
|
486
|
+
documentLoader?: DocumentLoader | null;
|
|
487
|
+
baseUri?: string;
|
|
488
|
+
/**
|
|
489
|
+
* Parser for the XML strings returned by the loaders; defaults to the
|
|
490
|
+
* global DOMParser, then to the DOMParser of the stylesheet's window.
|
|
491
|
+
*/
|
|
492
|
+
domParser?: DomParserLike | null;
|
|
493
|
+
/** Largest node-set one XPath step may produce (default XSLT_MAX_RESULT_SIZE). */
|
|
494
|
+
maxResultSize?: number;
|
|
495
|
+
/** Deepest XPath expression nesting (default XSLT_MAX_EXPRESSION_DEPTH). */
|
|
496
|
+
maxRecursionDepth?: number;
|
|
497
|
+
/**
|
|
498
|
+
* Deepest nesting of template instantiations; deeper recursion throws
|
|
499
|
+
* "Template recursion too deep" (default XSLT_MAX_TEMPLATE_DEPTH).
|
|
500
|
+
*/
|
|
501
|
+
maxTemplateDepth?: number;
|
|
502
|
+
/**
|
|
503
|
+
* @deprecated Let unprefixed name tests (`item`, `@a`) also match nodes
|
|
504
|
+
* in a namespace, as before 1.2.0. XPath 1.0 and Chrome match only nodes
|
|
505
|
+
* in no namespace.
|
|
506
|
+
*/
|
|
507
|
+
legacyNameTests?: boolean;
|
|
508
|
+
/** Allow EXSLT `dyn:evaluate()`; it evaluates XPath built from data. */
|
|
509
|
+
enableDynamicEvaluate?: boolean;
|
|
510
|
+
/** Clock for EXSLT current-time functions (reproducible output). */
|
|
511
|
+
clock?: () => Date;
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
/** Whether EXSLT `dyn:evaluate()` is allowed. */
|
|
515
|
+
enableDynamicEvaluate: boolean;
|
|
516
|
+
/** Clock for EXSLT current-time functions, or null for the system clock. */
|
|
517
|
+
clock: (() => Date) | null;
|
|
227
518
|
|
|
228
|
-
setStylesheetLoader(loader: StylesheetLoader | null):
|
|
519
|
+
setStylesheetLoader(loader: StylesheetLoader | null): this;
|
|
520
|
+
setDocumentLoader(loader: DocumentLoader | null): this;
|
|
229
521
|
importStylesheet(stylesheetNode: Node, stylesheetUri?: string): void;
|
|
230
522
|
transform(sourceNode: Node, ownerDocument: Document): DocumentFragment;
|
|
523
|
+
/**
|
|
524
|
+
* Like transform(), but html output into an HTML document is parsed as
|
|
525
|
+
* HTML (real HTMLElements), as Chrome's transformToFragment does.
|
|
526
|
+
*/
|
|
527
|
+
transformToFragment(
|
|
528
|
+
sourceNode: Node,
|
|
529
|
+
ownerDocument: Document,
|
|
530
|
+
): DocumentFragment;
|
|
531
|
+
/**
|
|
532
|
+
* Register the implementation of an extension element (XSLT 1.0 section
|
|
533
|
+
* 14.1), used instead of its xsl:fallback children.
|
|
534
|
+
* @returns This engine, to allow chaining
|
|
535
|
+
*/
|
|
536
|
+
registerExtensionElement(
|
|
537
|
+
namespaceUri: string,
|
|
538
|
+
localName: string,
|
|
539
|
+
handler: (
|
|
540
|
+
node: Element,
|
|
541
|
+
context: XsltContext,
|
|
542
|
+
output: Node,
|
|
543
|
+
engine: XsltEngine,
|
|
544
|
+
) => void,
|
|
545
|
+
): this;
|
|
231
546
|
transformToDocument(sourceNode: Node): Document;
|
|
232
547
|
transformToString(sourceNode: Node): string;
|
|
233
548
|
|
|
@@ -238,18 +553,24 @@ export class XsltEngine {
|
|
|
238
553
|
* xsl:output settings driving the result serialization
|
|
239
554
|
* (XSLT 1.0 section 16). Accepts the raw stylesheet values, so the yes/no
|
|
240
555
|
* attributes are strings and cdata-section-elements may be a name list.
|
|
556
|
+
* A null method means "not declared": html or xml is picked from the result.
|
|
241
557
|
*/
|
|
242
558
|
export interface OutputSettings {
|
|
243
|
-
method?:
|
|
559
|
+
method?: "xml" | "html" | "xhtml" | "text" | "auto" | (string & {}) | null;
|
|
244
560
|
version?: string;
|
|
245
561
|
encoding?: string;
|
|
246
|
-
standalone?:
|
|
247
|
-
indent?:
|
|
248
|
-
omitXmlDeclaration?:
|
|
562
|
+
standalone?: "yes" | "no" | string | null;
|
|
563
|
+
indent?: "yes" | "no" | boolean;
|
|
564
|
+
omitXmlDeclaration?: "yes" | "no" | boolean;
|
|
249
565
|
doctypePublic?: string | null;
|
|
250
566
|
doctypeSystem?: string | null;
|
|
251
567
|
mediaType?: string | null;
|
|
252
|
-
|
|
568
|
+
/**
|
|
569
|
+
* QNames (whitespace separated or as an array), or expanded names as the
|
|
570
|
+
* engine resolves them from xsl:output.
|
|
571
|
+
*/
|
|
572
|
+
cdataSectionElements?:
|
|
573
|
+
string | Array<string | { namespaceUri: string | null; localName: string }>;
|
|
253
574
|
}
|
|
254
575
|
|
|
255
576
|
/**
|
|
@@ -260,9 +581,43 @@ export interface OutputSettings {
|
|
|
260
581
|
*/
|
|
261
582
|
export function serializeResult(
|
|
262
583
|
node: Node | null,
|
|
263
|
-
outputSettings?: OutputSettings
|
|
584
|
+
outputSettings?: OutputSettings,
|
|
264
585
|
): string;
|
|
265
586
|
|
|
587
|
+
/** Default chunk size of the streaming serializer (16384 code units). */
|
|
588
|
+
export const DEFAULT_CHUNK_SIZE: number;
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* Serialize a transformation result in chunks of at most `chunkSize` UTF-16
|
|
592
|
+
* code units (one more when a surrogate pair straddles the boundary); joined,
|
|
593
|
+
* they equal serializeResult().
|
|
594
|
+
* @throws RangeError When chunkSize is not a positive integer or Infinity
|
|
595
|
+
*/
|
|
596
|
+
export function serializeChunks(
|
|
597
|
+
node: Node | null,
|
|
598
|
+
outputSettings?: OutputSettings,
|
|
599
|
+
options?: { chunkSize?: number },
|
|
600
|
+
): Iterator<string> & Iterable<string>;
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* Transform with an engine and serialize the result in chunks: the result
|
|
604
|
+
* tree is built by this call, serialization runs as the chunks are read.
|
|
605
|
+
*/
|
|
606
|
+
export function transformToChunks(
|
|
607
|
+
engine: XsltEngine,
|
|
608
|
+
sourceNode: Node,
|
|
609
|
+
options?: { chunkSize?: number },
|
|
610
|
+
): Iterator<string> & Iterable<string>;
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* Transform with an engine and stream the serialized result.
|
|
614
|
+
*/
|
|
615
|
+
export function transformToStream(
|
|
616
|
+
engine: XsltEngine,
|
|
617
|
+
sourceNode: Node,
|
|
618
|
+
options?: StreamOptions,
|
|
619
|
+
): ReadableStream<string>;
|
|
620
|
+
|
|
266
621
|
/**
|
|
267
622
|
* Mark a text node as produced with disable-output-escaping="yes".
|
|
268
623
|
*/
|
|
@@ -278,8 +633,12 @@ export function isRawText(node: Node | null): boolean;
|
|
|
278
633
|
*/
|
|
279
634
|
export function resolveOutputSettings(
|
|
280
635
|
outputSettings: OutputSettings | null,
|
|
281
|
-
node: Node | null
|
|
282
|
-
): Required<OutputSettings> & {
|
|
636
|
+
node: Node | null,
|
|
637
|
+
): Required<OutputSettings> & {
|
|
638
|
+
indent: boolean;
|
|
639
|
+
omitXmlDeclaration: boolean;
|
|
640
|
+
cdataSectionElements: Set<string>;
|
|
641
|
+
};
|
|
283
642
|
|
|
284
643
|
/**
|
|
285
644
|
* Version information.
|