xslt-processor 4.6.0 → 4.7.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/index.d.mts CHANGED
@@ -132,6 +132,217 @@ declare class XmlParser {
132
132
  private xmlStrictParse;
133
133
  }
134
134
 
135
+ type XsltParameter = {
136
+ name: string;
137
+ namespaceUri?: string;
138
+ value: any;
139
+ };
140
+
141
+ /**
142
+ * According to https://www.w3schools.com/xml/ref_xsl_el_decimal-format.asp:
143
+ *
144
+ * @property {string} name: Optional. Specifies a name for this format.
145
+ * @property {string} decimalSeparator: Optional. Specifies the decimal point character. Default is ".".
146
+ * @property {string} groupingSeparator: Optional. Specifies the thousands separator character. Default is ",".
147
+ * @property {string} infinity: Optional. Specifies the string used to represent infinity. Default is "Infinity".
148
+ * @property {string} minusSign: Optional. Specifies the character to represent negative numbers. Default is "-".
149
+ * @property {string} naN: Optional. Specifies the string used when the value is not a number". Default is "NaN".
150
+ * @property {string} percent: Optional. Specifies the percentage sign character. Default is "%".
151
+ * @property {string} perMille: Optional. Specifies the per thousand sign character. Default is "‰".
152
+ * @property {string} zeroDigit: Optional. Specifies the digit zero character. Default is "0".
153
+ * @property {string} digit: Optional. Specifies the character used to indicate a place where a digit is required. Default is #.
154
+ * @property {string} patternSeparator: Optional. Specifies the character used to separate positive and negative subpatterns in a format pattern. Default is ";".
155
+ */
156
+ type XsltDecimalFormatSettings = {
157
+ name?: string;
158
+ decimalSeparator: string;
159
+ groupingSeparator: string;
160
+ infinity: string;
161
+ minusSign: string;
162
+ naN: string;
163
+ percent: string;
164
+ perMille: string;
165
+ zeroDigit: string;
166
+ digit: string;
167
+ patternSeparator: string;
168
+ };
169
+ type XsltOptions = {
170
+ cData: boolean;
171
+ escape: boolean;
172
+ selfClosingTags: boolean;
173
+ outputMethod?: 'xml' | 'html' | 'text' | 'xhtml' | 'json' | 'adaptive';
174
+ parameters?: XsltParameter[];
175
+ };
176
+
177
+ interface NodeValue {
178
+ type: string;
179
+ stringValue(): string;
180
+ booleanValue(): boolean;
181
+ numberValue(): number;
182
+ nodeSetValue(): XNode[];
183
+ }
184
+
185
+ /**
186
+ * XPath expression evaluation context. An XPath context consists of a
187
+ * DOM node, a list of DOM nodes that contains this node, a number
188
+ * that represents the position of the single node in the list, and a
189
+ * current set of variable bindings. (See XPath spec.)
190
+ *
191
+ * setVariable(name, expr) -- binds given XPath expression to the
192
+ * name.
193
+ *
194
+ * getVariable(name) -- what the name says.
195
+ *
196
+ * setNode(position) -- sets the context to the node at the given
197
+ * position. Needed to implement scoping rules for variables in
198
+ * XPath. (A variable is visible to all subsequent siblings, not
199
+ * only to its children.)
200
+ *
201
+ * set/isCaseInsensitive -- specifies whether node name tests should
202
+ * be case sensitive. If you're executing xpaths against a regular
203
+ * HTML DOM, you probably don't want case-sensitivity, because
204
+ * browsers tend to disagree about whether elements & attributes
205
+ * should be upper/lower case. If you're running xpaths in an
206
+ * XSLT instance, you probably DO want case sensitivity, as per the
207
+ * XSL spec.
208
+ *
209
+ * set/isReturnOnFirstMatch -- whether XPath evaluation should quit as soon
210
+ * as a result is found. This is an optimization that might make sense if you
211
+ * only care about the first result.
212
+ *
213
+ * set/isIgnoreNonElementNodesForNTA -- whether to ignore non-element nodes
214
+ * when evaluating the "node()" any node test. While technically this is
215
+ * contrary to the XPath spec, practically it can enhance performance
216
+ * significantly, and makes sense if you a) use "node()" when you mean "*",
217
+ * and b) use "//" when you mean "/descendant::* /".
218
+ */
219
+ declare class ExprContext {
220
+ position: number;
221
+ nodeList: XNode[];
222
+ xsltVersion: '1.0' | '2.0' | '3.0';
223
+ variables: {
224
+ [name: string]: NodeValue;
225
+ };
226
+ keys: {
227
+ [name: string]: {
228
+ [key: string]: NodeValue;
229
+ };
230
+ };
231
+ knownNamespaces: {
232
+ [alias: string]: string;
233
+ };
234
+ /**
235
+ * Custom system properties for system-property() function.
236
+ * Overrides the default properties (xsl:version, xsl:vendor, xsl:vendor-url).
237
+ */
238
+ systemProperties?: {
239
+ [name: string]: string;
240
+ };
241
+ /**
242
+ * Document loader function for the document() function.
243
+ * Takes a URI and returns an XNode document, or null if loading fails.
244
+ */
245
+ documentLoader?: (uri: string) => XNode | null;
246
+ /**
247
+ * Unparsed entity URIs for the unparsed-entity-uri() function.
248
+ * Maps entity names to their URIs (from DTD declarations).
249
+ */
250
+ unparsedEntities?: {
251
+ [name: string]: string;
252
+ };
253
+ /**
254
+ * Warning callback for non-fatal XPath/XSLT warnings.
255
+ */
256
+ warningsCallback?: (...args: any[]) => void;
257
+ caseInsensitive: any;
258
+ ignoreAttributesWithoutValue: any;
259
+ returnOnFirstMatch: any;
260
+ ignoreNonElementNodesForNTA: any;
261
+ parent: ExprContext;
262
+ root: XNode;
263
+ decimalFormatSettings: XsltDecimalFormatSettings;
264
+ inApplyTemplates: boolean;
265
+ baseTemplateMatched: boolean;
266
+ /**
267
+ * Regex groups from xsl:analyze-string for regex-group() function.
268
+ * Index 0 is the full match, 1+ are captured groups.
269
+ */
270
+ regexGroups?: string[];
271
+ /**
272
+ * Current group from xsl:for-each-group for current-group() function.
273
+ * Contains the nodes/items in the current group being processed.
274
+ */
275
+ currentGroup?: XNode[];
276
+ /**
277
+ * Current grouping key from xsl:for-each-group for current-grouping-key() function.
278
+ * Contains the key value of the current group being processed.
279
+ */
280
+ currentGroupingKey?: any;
281
+ /**
282
+ * Constructor -- gets the node, its position, the node set it
283
+ * belongs to, and a parent context as arguments. The parent context
284
+ * is used to implement scoping rules for variables: if a variable
285
+ * is not found in the current context, it is looked for in the
286
+ * parent context, recursively. Except for node, all arguments have
287
+ * default values: default position is 0, default node set is the
288
+ * set that contains only the node, and the default parent is null.
289
+ *
290
+ * Notice that position starts at 0 at the outside interface;
291
+ * inside XPath expressions this shows up as position()=1.
292
+ * @param nodeList TODO
293
+ * @param opt_position TODO
294
+ * @param opt_parent TODO
295
+ * @param opt_caseInsensitive TODO
296
+ * @param opt_ignoreAttributesWithoutValue TODO
297
+ * @param opt_returnOnFirstMatch TODO
298
+ * @param opt_ignoreNonElementNodesForNTA TODO
299
+ */
300
+ constructor(nodeList: XNode[], xsltVersion?: '1.0' | '2.0' | '3.0', opt_position?: number, opt_decimalFormatSettings?: XsltDecimalFormatSettings, opt_variables?: {
301
+ [name: string]: any;
302
+ }, opt_knownNamespaces?: {
303
+ [alias: string]: string;
304
+ }, opt_parent?: ExprContext, opt_caseInsensitive?: any, opt_ignoreAttributesWithoutValue?: any, opt_returnOnFirstMatch?: any, opt_ignoreNonElementNodesForNTA?: any, opt_warningsCallback?: (...args: any[]) => void);
305
+ /**
306
+ * clone() -- creates a new context with the current context as
307
+ * parent. If passed as argument to clone(), the new context has a
308
+ * different node, position, or node set. What is not passed is
309
+ * inherited from the cloned context.
310
+ * @param opt_nodeList TODO
311
+ * @param opt_position TODO
312
+ * @returns TODO
313
+ */
314
+ clone(opt_nodeList?: XNode[], opt_position?: number): ExprContext;
315
+ setVariable(name?: string, value?: NodeValue | string): void;
316
+ getVariable(name: string): NodeValue;
317
+ /**
318
+ * Gets a regex group from xsl:analyze-string context.
319
+ * Searches up the parent chain for regexGroups.
320
+ * @param index Group index (0 = full match, 1+ = captured groups)
321
+ * @returns The group value or empty string if not found
322
+ */
323
+ getRegexGroup(index: number): string;
324
+ setNode(position: number): void;
325
+ contextSize(): number;
326
+ isCaseInsensitive(): any;
327
+ setCaseInsensitive(caseInsensitive: any): any;
328
+ isIgnoreAttributesWithoutValue(): any;
329
+ setIgnoreAttributesWithoutValue(ignore: any): any;
330
+ isReturnOnFirstMatch(): any;
331
+ setReturnOnFirstMatch(returnOnFirstMatch: any): any;
332
+ isIgnoreNonElementNodesForNTA(): any;
333
+ setIgnoreNonElementNodesForNTA(ignoreNonElementNodesForNTA: any): any;
334
+ }
335
+
336
+ /**
337
+ * XPath version support and configuration.
338
+ *
339
+ * This module defines version-specific behavior and prepares for future XPath 2.0/3.0 support.
340
+ */
341
+ /**
342
+ * Supported XPath specification versions.
343
+ */
344
+ type XPathVersion = '1.0' | '2.0' | '3.0' | '3.1';
345
+
135
346
  /**
136
347
  * Represents a DOM-like node interface for XPath evaluation.
137
348
  * This is compatible with browser DOM nodes and can be extended for other implementations.
@@ -278,224 +489,59 @@ interface XPathContext {
278
489
  */
279
490
  extensions?: Record<string, any>;
280
491
  /**
281
- * Current dateTime in the dynamic context (XPath 2.0+).
282
- * Returned by fn:current-dateTime().
283
- * If not provided, defaults to system time when accessed.
284
- */
285
- currentDateTime?: Date;
286
- /**
287
- * Available documents mapping for fn:doc() function (XPath 2.0+).
288
- * Maps document URIs to their root document nodes.
289
- * Example: { "http://example.com/data.xml": rootNode }
290
- */
291
- availableDocuments?: XPathDocuments;
292
- /**
293
- * Available collections mapping for fn:collection() function (XPath 2.0+).
294
- * Maps collection URIs to sequences of nodes.
295
- * Example: { "http://example.com/collection": [node1, node2, ...] }
296
- */
297
- availableCollections?: XPathCollections;
298
- /**
299
- * Default collection URI when fn:collection() is called without arguments (XPath 2.0+).
300
- * If provided, fn:collection() returns availableCollections[defaultCollection].
301
- */
302
- defaultCollection?: string;
303
- /**
304
- * Function implementations registry (XPath 2.0+).
305
- * Maps QName function names to their implementations.
306
- * Allows defining custom/XSLT functions at evaluation time.
307
- * Format: "localName" or "prefix:localName"
308
- */
309
- functionRegistry?: XPathFunctionRegistry;
310
- }
311
- /**
312
- * Result types that can be returned from XPath evaluation.
313
- *
314
- * XPath 1.0: node-set, string, number, boolean
315
- * XPath 2.0+: sequences (which subsume node-sets), atomic values, functions
316
- */
317
- type XPathResult = XPathNode[] | string | number | boolean | any[] | Map<any, any> | null | Function;
318
-
319
- declare abstract class XPathExpression {
320
- abstract evaluate(context: XPathContext): XPathResult;
321
- }
322
-
323
- /**
324
- * According to https://www.w3schools.com/xml/ref_xsl_el_decimal-format.asp:
325
- *
326
- * @property {string} name: Optional. Specifies a name for this format.
327
- * @property {string} decimalSeparator: Optional. Specifies the decimal point character. Default is ".".
328
- * @property {string} groupingSeparator: Optional. Specifies the thousands separator character. Default is ",".
329
- * @property {string} infinity: Optional. Specifies the string used to represent infinity. Default is "Infinity".
330
- * @property {string} minusSign: Optional. Specifies the character to represent negative numbers. Default is "-".
331
- * @property {string} naN: Optional. Specifies the string used when the value is not a number". Default is "NaN".
332
- * @property {string} percent: Optional. Specifies the percentage sign character. Default is "%".
333
- * @property {string} perMille: Optional. Specifies the per thousand sign character. Default is "‰".
334
- * @property {string} zeroDigit: Optional. Specifies the digit zero character. Default is "0".
335
- * @property {string} digit: Optional. Specifies the character used to indicate a place where a digit is required. Default is #.
336
- * @property {string} patternSeparator: Optional. Specifies the character used to separate positive and negative subpatterns in a format pattern. Default is ";".
337
- */
338
- type XsltDecimalFormatSettings = {
339
- name?: string;
340
- decimalSeparator: string;
341
- groupingSeparator: string;
342
- infinity: string;
343
- minusSign: string;
344
- naN: string;
345
- percent: string;
346
- perMille: string;
347
- zeroDigit: string;
348
- digit: string;
349
- patternSeparator: string;
350
- };
351
-
352
- interface NodeValue {
353
- stringValue(): string;
354
- booleanValue(): boolean;
355
- numberValue(): number;
356
- nodeSetValue(): XNode[];
357
- }
358
-
359
- /**
360
- * XPath expression evaluation context. An XPath context consists of a
361
- * DOM node, a list of DOM nodes that contains this node, a number
362
- * that represents the position of the single node in the list, and a
363
- * current set of variable bindings. (See XPath spec.)
364
- *
365
- * setVariable(name, expr) -- binds given XPath expression to the
366
- * name.
367
- *
368
- * getVariable(name) -- what the name says.
369
- *
370
- * setNode(position) -- sets the context to the node at the given
371
- * position. Needed to implement scoping rules for variables in
372
- * XPath. (A variable is visible to all subsequent siblings, not
373
- * only to its children.)
374
- *
375
- * set/isCaseInsensitive -- specifies whether node name tests should
376
- * be case sensitive. If you're executing xpaths against a regular
377
- * HTML DOM, you probably don't want case-sensitivity, because
378
- * browsers tend to disagree about whether elements & attributes
379
- * should be upper/lower case. If you're running xpaths in an
380
- * XSLT instance, you probably DO want case sensitivity, as per the
381
- * XSL spec.
382
- *
383
- * set/isReturnOnFirstMatch -- whether XPath evaluation should quit as soon
384
- * as a result is found. This is an optimization that might make sense if you
385
- * only care about the first result.
386
- *
387
- * set/isIgnoreNonElementNodesForNTA -- whether to ignore non-element nodes
388
- * when evaluating the "node()" any node test. While technically this is
389
- * contrary to the XPath spec, practically it can enhance performance
390
- * significantly, and makes sense if you a) use "node()" when you mean "*",
391
- * and b) use "//" when you mean "/descendant::* /".
392
- */
393
- declare class ExprContext {
394
- position: number;
395
- nodeList: XNode[];
396
- xsltVersion: '1.0' | '2.0' | '3.0';
397
- variables: {
398
- [name: string]: NodeValue;
399
- };
400
- keys: {
401
- [name: string]: {
402
- [key: string]: NodeValue;
403
- };
404
- };
405
- knownNamespaces: {
406
- [alias: string]: string;
407
- };
408
- /**
409
- * Custom system properties for system-property() function.
410
- * Overrides the default properties (xsl:version, xsl:vendor, xsl:vendor-url).
492
+ * Current dateTime in the dynamic context (XPath 2.0+).
493
+ * Returned by fn:current-dateTime().
494
+ * If not provided, defaults to system time when accessed.
411
495
  */
412
- systemProperties?: {
413
- [name: string]: string;
414
- };
496
+ currentDateTime?: Date;
415
497
  /**
416
- * Document loader function for the document() function.
417
- * Takes a URI and returns an XNode document, or null if loading fails.
498
+ * Available documents mapping for fn:doc() function (XPath 2.0+).
499
+ * Maps document URIs to their root document nodes.
500
+ * Example: { "http://example.com/data.xml": rootNode }
418
501
  */
419
- documentLoader?: (uri: string) => XNode | null;
502
+ availableDocuments?: XPathDocuments;
420
503
  /**
421
- * Unparsed entity URIs for the unparsed-entity-uri() function.
422
- * Maps entity names to their URIs (from DTD declarations).
504
+ * Available collections mapping for fn:collection() function (XPath 2.0+).
505
+ * Maps collection URIs to sequences of nodes.
506
+ * Example: { "http://example.com/collection": [node1, node2, ...] }
423
507
  */
424
- unparsedEntities?: {
425
- [name: string]: string;
426
- };
427
- caseInsensitive: any;
428
- ignoreAttributesWithoutValue: any;
429
- returnOnFirstMatch: any;
430
- ignoreNonElementNodesForNTA: any;
431
- parent: ExprContext;
432
- root: XNode;
433
- decimalFormatSettings: XsltDecimalFormatSettings;
434
- inApplyTemplates: boolean;
435
- baseTemplateMatched: boolean;
508
+ availableCollections?: XPathCollections;
436
509
  /**
437
- * Constructor -- gets the node, its position, the node set it
438
- * belongs to, and a parent context as arguments. The parent context
439
- * is used to implement scoping rules for variables: if a variable
440
- * is not found in the current context, it is looked for in the
441
- * parent context, recursively. Except for node, all arguments have
442
- * default values: default position is 0, default node set is the
443
- * set that contains only the node, and the default parent is null.
444
- *
445
- * Notice that position starts at 0 at the outside interface;
446
- * inside XPath expressions this shows up as position()=1.
447
- * @param nodeList TODO
448
- * @param opt_position TODO
449
- * @param opt_parent TODO
450
- * @param opt_caseInsensitive TODO
451
- * @param opt_ignoreAttributesWithoutValue TODO
452
- * @param opt_returnOnFirstMatch TODO
453
- * @param opt_ignoreNonElementNodesForNTA TODO
510
+ * Default collection URI when fn:collection() is called without arguments (XPath 2.0+).
511
+ * If provided, fn:collection() returns availableCollections[defaultCollection].
454
512
  */
455
- constructor(nodeList: XNode[], xsltVersion?: '1.0' | '2.0' | '3.0', opt_position?: number, opt_decimalFormatSettings?: XsltDecimalFormatSettings, opt_variables?: {
456
- [name: string]: any;
457
- }, opt_knownNamespaces?: {
458
- [alias: string]: string;
459
- }, opt_parent?: ExprContext, opt_caseInsensitive?: any, opt_ignoreAttributesWithoutValue?: any, opt_returnOnFirstMatch?: any, opt_ignoreNonElementNodesForNTA?: any);
513
+ defaultCollection?: string;
460
514
  /**
461
- * clone() -- creates a new context with the current context as
462
- * parent. If passed as argument to clone(), the new context has a
463
- * different node, position, or node set. What is not passed is
464
- * inherited from the cloned context.
465
- * @param opt_nodeList TODO
466
- * @param opt_position TODO
467
- * @returns TODO
515
+ * Function implementations registry (XPath 2.0+).
516
+ * Maps QName function names to their implementations.
517
+ * Allows defining custom/XSLT functions at evaluation time.
518
+ * Format: "localName" or "prefix:localName"
468
519
  */
469
- clone(opt_nodeList?: XNode[], opt_position?: number): ExprContext;
470
- setVariable(name?: string, value?: NodeValue | string): void;
471
- getVariable(name: string): NodeValue;
472
- setNode(position: number): void;
473
- contextSize(): number;
474
- isCaseInsensitive(): any;
475
- setCaseInsensitive(caseInsensitive: any): any;
476
- isIgnoreAttributesWithoutValue(): any;
477
- setIgnoreAttributesWithoutValue(ignore: any): any;
478
- isReturnOnFirstMatch(): any;
479
- setReturnOnFirstMatch(returnOnFirstMatch: any): any;
480
- isIgnoreNonElementNodesForNTA(): any;
481
- setIgnoreNonElementNodesForNTA(ignoreNonElementNodesForNTA: any): any;
520
+ functionRegistry?: XPathFunctionRegistry;
482
521
  }
483
-
484
522
  /**
485
- * Expression wrapper that provides backward-compatible interface.
486
- * Wraps new XPath expressions to work with old ExprContext.
523
+ * Represents an XPath 3.0 function item.
524
+ * This is a simplified interface to avoid circular dependencies.
487
525
  */
488
- declare class Expression {
489
- protected xpathExpression: XPathExpression;
490
- protected nodeConverter: NodeConverter;
491
- absolute?: boolean;
492
- steps?: any[];
493
- constructor(xpathExpression: XPathExpression, nodeConverter: NodeConverter);
494
- /**
495
- * Evaluate the expression in the given context.
496
- */
497
- evaluate(context: ExprContext): NodeValue;
526
+ interface XPathFunctionItem {
527
+ __isFunctionItem: true;
528
+ implementation: (...args: any[]) => any;
529
+ arity: number;
530
+ name?: string;
531
+ namespace?: string;
532
+ }
533
+ /**
534
+ * Result types that can be returned from XPath evaluation.
535
+ *
536
+ * XPath 1.0: node-set, string, number, boolean
537
+ * XPath 2.0+: sequences (which subsume node-sets), atomic values, functions
538
+ */
539
+ type XPathResult = XPathNode[] | string | number | boolean | any[] | Map<any, any> | null | XPathFunctionItem;
540
+
541
+ declare abstract class XPathExpression {
542
+ abstract evaluate(context: XPathContext): XPathResult;
498
543
  }
544
+
499
545
  /**
500
546
  * Handles conversion between ExprContext and XPathContext.
501
547
  * Uses XNode directly as XPathNode-compatible objects to preserve node identity.
@@ -549,22 +595,42 @@ declare class NodeConverter {
549
595
  */
550
596
  clearCache(): void;
551
597
  }
598
+
599
+ /**
600
+ * Expression wrapper that provides backward-compatible interface.
601
+ * Wraps new XPath expressions to work with old ExprContext.
602
+ */
603
+ declare class Expression {
604
+ protected xpathExpression: XPathExpression;
605
+ protected nodeConverter: NodeConverter;
606
+ absolute?: boolean;
607
+ steps?: any[];
608
+ constructor(xpathExpression: XPathExpression, nodeConverter: NodeConverter);
609
+ /**
610
+ * Evaluate the expression in the given context.
611
+ */
612
+ evaluate(context: ExprContext): NodeValue;
613
+ }
614
+
552
615
  /**
553
616
  * XPath class that uses the new lexer/parser implementation
554
617
  * while maintaining API compatibility with the old implementation.
555
618
  */
556
619
  declare class XPath {
557
- private lexer;
558
- private parser;
620
+ private lexers;
621
+ private parsers;
559
622
  private nodeConverter;
560
623
  private parseCache;
561
624
  constructor();
625
+ private getLexer;
626
+ private getParser;
562
627
  /**
563
628
  * Parse an XPath expression and return an Expression object.
564
629
  * @param expression The XPath expression string.
565
630
  * @param axis Optional axis override for relative paths.
631
+ * @param version Optional XPath version (defaults to 1.0).
566
632
  */
567
- xPathParse(expression: string, axis?: string): Expression;
633
+ xPathParse(expression: string, axis?: string, version?: XPathVersion): Expression;
568
634
  /**
569
635
  * Parse and evaluate an XPath expression.
570
636
  * @param select The XPath expression string.
@@ -645,42 +711,33 @@ declare class MatchResolver {
645
711
  private relativeXsltMatch;
646
712
  }
647
713
 
648
- type XsltParameter = {
649
- name: string;
650
- namespaceUri?: string;
651
- value: any;
652
- };
653
-
654
- type XsltOptions = {
655
- cData: boolean;
656
- escape: boolean;
657
- selfClosingTags: boolean;
658
- outputMethod?: 'xml' | 'html' | 'text' | 'xhtml' | 'json' | 'adaptive';
659
- parameters?: XsltParameter[];
660
- };
661
-
662
714
  /**
663
- * The main class for XSL-T processing. The implementation is NOT
664
- * complete; some xsl element are left out.
715
+ * The main class for XSL-T processing.
665
716
  *
666
717
  * References:
667
718
  *
668
- * [XSLT] XSL-T Specification
669
- * <http://www.w3.org/TR/1999/REC-xslt-19991116>.
719
+ * [XSLT 1.0] XSL Transformations (XSLT) Version 1.0
720
+ * <https://www.w3.org/TR/1999/REC-xslt-19991116>.
721
+ *
722
+ * [XSLT 2.0] XSL Transformations (XSLT) Version 2.0
723
+ * <https://www.w3.org/TR/xslt20/>.
724
+ *
725
+ * [XSLT 3.0] XSL Transformations (XSLT) Version 3.0
726
+ * <https://www.w3.org/TR/xslt-30/>.
670
727
  *
671
728
  * [ECMA] ECMAScript Language Specification
672
729
  * <http://www.ecma-international.org/publications/standards/Ecma-262.htm>.
673
730
  *
674
- * The XSL processor API has one entry point, the function
675
- * `xsltProcess()`. It receives as arguments the starting point in the
676
- * input document as an XPath expression context, the DOM root node of
677
- * the XSL-T stylesheet, and a DOM node that receives the output.
731
+ * The XSL processor API has one entry point: the async function
732
+ * `xsltProcess()`. It receives as arguments the input XML document
733
+ * and the XSL-T stylesheet document (both as `XDocument` instances),
734
+ * and returns the transformed output as a string (XML, HTML, JSON,
735
+ * or plain text depending on the output method).
678
736
  *
679
- * NOTE: Actually, XSL-T processing according to the specification is
680
- * defined as operation on text documents, not as operation on DOM
681
- * trees. So, strictly speaking, this implementation is not an XSL-T
682
- * processor, but the processing engine that needs to be complemented
683
- * by an XML parser and serializer in order to be complete. Those two
737
+ * NOTE: Strictly speaking, XSL-T processing according to the specification
738
+ * is defined as operation on text documents, not as operation on DOM
739
+ * trees. This implementation operates on an internal DOM representation,
740
+ * complemented by an XML parser and serializer to be complete. Those two
684
741
  * are found in the `dom` folder.
685
742
  */
686
743
  declare class Xslt {
@@ -689,11 +746,23 @@ declare class Xslt {
689
746
  matchResolver: MatchResolver;
690
747
  options: XsltOptions;
691
748
  decimalFormatSettings: XsltDecimalFormatSettings;
749
+ warningsCallback: (...args: any[]) => void;
692
750
  outputDocument: XDocument;
693
751
  outputMethod: 'xml' | 'html' | 'text' | 'name' | 'xhtml' | 'json' | 'adaptive';
694
752
  outputOmitXmlDeclaration: string;
753
+ outputVersion: string;
754
+ itemSeparator: string;
695
755
  version: string;
696
756
  firstTemplateRan: boolean;
757
+ /**
758
+ * Forwards-compatible processing mode (XSLT 1.0 Section 2.5).
759
+ * When true, the processor is running a stylesheet with version > 1.0.
760
+ * In this mode:
761
+ * - Unknown top-level elements are silently ignored
762
+ * - Unknown XSLT instructions use xsl:fallback if available, otherwise are ignored
763
+ * - Unknown attributes on XSLT elements are ignored
764
+ */
765
+ forwardsCompatible: boolean;
697
766
  /**
698
767
  * List of element name patterns from xsl:strip-space declarations.
699
768
  * Whitespace-only text nodes inside matching elements will be stripped.
@@ -741,6 +810,26 @@ declare class Xslt {
741
810
  * Used by apply-imports to determine which template called it.
742
811
  */
743
812
  private currentTemplateStack;
813
+ /**
814
+ * Package registry for XSLT 3.0 package system.
815
+ * Manages loaded packages and their components.
816
+ */
817
+ private packageRegistry;
818
+ /**
819
+ * Current package being processed (for XSLT 3.0).
820
+ * null if processing a non-package stylesheet.
821
+ */
822
+ private currentPackage;
823
+ /**
824
+ * Accumulator registry for XSLT 3.0 accumulators.
825
+ * Stores accumulator definitions and current state during processing.
826
+ */
827
+ private accumulatorRegistry;
828
+ /**
829
+ * Streaming processor for XSLT 3.0 streaming processing.
830
+ * Encapsulates streaming context, copy management, and merge coordination.
831
+ */
832
+ private streamingProcessor;
744
833
  constructor(options?: Partial<XsltOptions>);
745
834
  /**
746
835
  * The exported entry point of the XSL-T processor.
@@ -756,6 +845,21 @@ declare class Xslt {
756
845
  * @param output If set, the output where the transformation should occur.
757
846
  */
758
847
  protected xsltProcessContext(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
848
+ /**
849
+ * Handle unknown XSLT instructions per XSLT 1.0 Section 2.5 (Forwards-Compatible Processing).
850
+ *
851
+ * In forwards-compatible mode (version > 1.0):
852
+ * - If the instruction has an xsl:fallback child, execute the fallback
853
+ * - Otherwise, the instruction is silently ignored
854
+ *
855
+ * In strict mode (version = 1.0):
856
+ * - Unknown instructions are an error
857
+ *
858
+ * @param context The Expression Context
859
+ * @param template The unknown XSLT instruction element
860
+ * @param output The output node
861
+ */
862
+ protected xsltUnknownInstruction(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
759
863
  /**
760
864
  * Implements `xsl:apply-templates`.
761
865
  * @param context The Expression Context.
@@ -764,6 +868,11 @@ declare class Xslt {
764
868
  * @protected
765
869
  */
766
870
  protected xsltApplyTemplates(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
871
+ /**
872
+ * Helper method to apply the built-in template for elements.
873
+ * The built-in template recursively applies templates to children.
874
+ */
875
+ private applyBuiltInTemplate;
767
876
  /**
768
877
  * Implements `xsl:apply-imports`.
769
878
  * Applies templates from imported stylesheets with the same match pattern and mode.
@@ -839,6 +948,32 @@ declare class Xslt {
839
948
  * @param template The template.
840
949
  */
841
950
  protected xsltElement(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
951
+ /**
952
+ * Implements `xsl:accumulator` (XSLT 3.0).
953
+ *
954
+ * Accumulators are a declarative way to compute values during template processing.
955
+ * They consist of rules that are applied as elements are processed.
956
+ *
957
+ * @param context The expression context
958
+ * @param template The xsl:accumulator element
959
+ */
960
+ protected xsltAccumulator(context: ExprContext, template: XNode): void;
961
+ /**
962
+ * Evaluates all matching accumulator rules for a given node
963
+ * and updates the accumulator state
964
+ *
965
+ * @param context The expression context with current node
966
+ * @param node The current node being processed
967
+ */
968
+ protected evaluateAccumulatorRules(context: ExprContext, node: XNode): void;
969
+ /**
970
+ * Retrieves the current value of an accumulator
971
+ * Used when accessing accumulators in templates via accumulator-after() or accumulator-before()
972
+ *
973
+ * @param accumulatorName The name of the accumulator
974
+ * @returns The current value of the accumulator, or null if not found
975
+ */
976
+ protected getAccumulatorValue(accumulatorName: string): any;
842
977
  /**
843
978
  * Implements `xsl:for-each`.
844
979
  * @param context The Expression Context.
@@ -846,6 +981,69 @@ declare class Xslt {
846
981
  * @param output The output.
847
982
  */
848
983
  protected xsltForEach(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
984
+ /**
985
+ * Implements `xsl:for-each-group` (XSLT 2.0).
986
+ *
987
+ * Groups items from the select expression and processes each group.
988
+ * Supports group-by and group-adjacent grouping methods.
989
+ *
990
+ * @param context The Expression Context.
991
+ * @param template The template.
992
+ * @param output The output.
993
+ */
994
+ protected xsltForEachGroup(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
995
+ /**
996
+ * Group items by a computed key value.
997
+ * Items with the same key are placed in the same group.
998
+ */
999
+ private groupByKey;
1000
+ /**
1001
+ * Group adjacent items with the same key.
1002
+ * A new group starts when the key changes.
1003
+ */
1004
+ private groupAdjacent;
1005
+ /**
1006
+ * Convert an XSLT pattern to a self:: expression for matching against the current node.
1007
+ * For example, "h1" becomes "self::h1", "section[@type]" becomes "self::section[@type]".
1008
+ */
1009
+ private patternToSelfExpression;
1010
+ /**
1011
+ * Group items starting with items that match a pattern.
1012
+ * A new group starts when an item matches the pattern.
1013
+ */
1014
+ private groupStartingWith;
1015
+ /**
1016
+ * Group items ending with items that match a pattern.
1017
+ * A group ends when an item matches the pattern.
1018
+ */
1019
+ private groupEndingWith;
1020
+ /**
1021
+ * Implements `xsl:iterate` (XSLT 3.0).
1022
+ *
1023
+ * Iterates over a sequence, maintaining accumulators that are updated across iterations.
1024
+ * Each iteration can output content and update accumulator values.
1025
+ * After all iterations complete, optional xsl:on-completion is executed.
1026
+ *
1027
+ * @param context The Expression Context.
1028
+ * @param template The template.
1029
+ * @param output The output.
1030
+ */
1031
+ protected xsltIterate(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
1032
+ /**
1033
+ * Implements `xsl:try`.
1034
+ * @param context The Expression Context.
1035
+ * @param template The template.
1036
+ * @param output The output.
1037
+ */
1038
+ protected xsltTry(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
1039
+ /**
1040
+ * Implements `xsl:evaluate` (XSLT 3.0).
1041
+ * Dynamically evaluates an XPath expression constructed as a string.
1042
+ * @param context The Expression Context.
1043
+ * @param template The template.
1044
+ * @param output The output.
1045
+ */
1046
+ protected xsltEvaluate(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
849
1047
  /**
850
1048
  * Implements `xsl:if`.
851
1049
  * @param context The Expression Context.
@@ -876,6 +1074,60 @@ declare class Xslt {
876
1074
  * @param output The output.
877
1075
  */
878
1076
  protected xsltInclude(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
1077
+ /**
1078
+ * Implements `<xsl:package>` (XSLT 3.0 Section 3.6).
1079
+ * Defines a package of XSLT components with controlled visibility.
1080
+ * @param context The Expression Context.
1081
+ * @param template The xsl:package element.
1082
+ * @param output The output node.
1083
+ */
1084
+ protected xsltPackage(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
1085
+ /**
1086
+ * Implements `<xsl:use-package>` (XSLT 3.0 Section 3.7).
1087
+ * Imports another package and makes its public components available.
1088
+ * @param context The Expression Context.
1089
+ * @param template The xsl:use-package element.
1090
+ * @param output The output node.
1091
+ */
1092
+ protected xsltUsePackage(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
1093
+ /**
1094
+ * Implements `<xsl:expose>` (XSLT 3.0 Section 3.8).
1095
+ * Marks a component as visible outside the package.
1096
+ * @param context The Expression Context.
1097
+ * @param template The xsl:expose element.
1098
+ */
1099
+ protected xsltExpose(context: ExprContext, template: XNode): void;
1100
+ /**
1101
+ * Implements `<xsl:accept>` (XSLT 3.0 Section 3.9).
1102
+ * Accepts and optionally overrides a component from a used package.
1103
+ * @param context The Expression Context.
1104
+ * @param template The xsl:accept element.
1105
+ */
1106
+ protected xsltAccept(context: ExprContext, template: XNode): void;
1107
+ /**
1108
+ * Implements `<xsl:stream>` (XSLT 3.0 Section 16).
1109
+ * Enables streaming processing of large documents.
1110
+ * @param context The Expression Context.
1111
+ * @param template The xsl:stream element.
1112
+ * @param output The output node.
1113
+ */
1114
+ protected xsltStream(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
1115
+ /**
1116
+ * Implements `<xsl:fork>` (XSLT 3.0 Section 17).
1117
+ * Creates multiple independent output branches from the input stream.
1118
+ * @param context The Expression Context.
1119
+ * @param template The xsl:fork element.
1120
+ * @param output The output node.
1121
+ */
1122
+ protected xsltFork(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
1123
+ /**
1124
+ * Implements `<xsl:merge>` (XSLT 3.0 Section 15).
1125
+ * Merges multiple sorted input sequences.
1126
+ * @param context The Expression Context.
1127
+ * @param template The xsl:merge element.
1128
+ * @param output The output node.
1129
+ */
1130
+ protected xsltMerge(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
879
1131
  /**
880
1132
  * Implements `xsl:key`.
881
1133
  * @param context The Expression Context.
@@ -909,29 +1161,57 @@ declare class Xslt {
909
1161
  * @param context The Expression Context.
910
1162
  * @param level The counting level: 'single', 'multiple', or 'any'.
911
1163
  * @param count Pattern to match nodes to count.
912
- * @param from Pattern to start counting from.
913
- * @returns The count value.
1164
+ * @param from Pattern to define counting boundary.
1165
+ * @returns Array of count values (single element for 'single'/'any', multiple for 'multiple').
914
1166
  */
915
- protected xsltNumberCount(context: ExprContext, level: string, count: string | null, from: string | null): number;
1167
+ protected xsltNumberCount(context: ExprContext, level: string, count: string | null, from: string | null): number[];
916
1168
  /**
917
- * Checks if a node matches a simple name pattern.
1169
+ * Checks if a node matches a pattern (supports simple names and union patterns).
918
1170
  * @param node The node to check.
919
- * @param pattern The pattern (node name) to match.
1171
+ * @param pattern The pattern (node name, wildcard, or union like "a|b|c").
920
1172
  * @returns True if the node matches.
921
1173
  */
922
1174
  protected nodeMatchesPattern(node: XNode, pattern: string): boolean;
1175
+ /**
1176
+ * Checks if a node matches a single (non-union) pattern.
1177
+ * @param node The node to check.
1178
+ * @param pattern The pattern (node name or wildcard).
1179
+ * @returns True if the node matches.
1180
+ */
1181
+ protected nodeMatchesSinglePattern(node: XNode, pattern: string): boolean;
923
1182
  /**
924
1183
  * Gets all nodes preceding the given node in document order.
925
1184
  * @param node The reference node.
1185
+ * @param fromPattern Optional pattern to define counting boundary.
926
1186
  * @returns Array of preceding nodes.
927
1187
  */
928
- protected getAllPrecedingNodes(node: XNode): XNode[];
1188
+ protected getAllPrecedingNodes(node: XNode, fromPattern?: string | null): XNode[];
929
1189
  /**
930
1190
  * Collects all descendant nodes of a given node.
931
1191
  * @param node The parent node.
932
1192
  * @param result The array to collect into.
933
1193
  */
934
1194
  protected collectDescendants(node: XNode, result: XNode[]): void;
1195
+ /**
1196
+ * Formats an array of numbers according to the format string.
1197
+ * For level="multiple", numbers like [1, 2, 3] with format "1.1.1" produce "1.2.3".
1198
+ * @param numbers The numbers to format.
1199
+ * @param format The format string (e.g., "1", "1.1", "1.a.i").
1200
+ * @param groupingSeparator Optional grouping separator.
1201
+ * @param groupingSize Optional grouping size.
1202
+ * @returns The formatted number string.
1203
+ */
1204
+ protected xsltFormatNumbers(numbers: number[], format: string, groupingSeparator: string | null, groupingSize: string | null): string;
1205
+ /**
1206
+ * Parses a format string into tokens and separators.
1207
+ * E.g., "1.a.i" -> tokens: ["1", "a", "i"], separators: [".", "."]
1208
+ * @param format The format string.
1209
+ * @returns Object with tokens and separators arrays.
1210
+ */
1211
+ protected parseFormatString(format: string): {
1212
+ tokens: string[];
1213
+ separators: string[];
1214
+ };
935
1215
  /**
936
1216
  * Formats a number according to the format string.
937
1217
  * @param number The number to format.
@@ -1035,6 +1315,34 @@ declare class Xslt {
1035
1315
  */
1036
1316
  protected xsltTransformOrStylesheet(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
1037
1317
  protected xsltValueOf(context: ExprContext, template: XNode, output?: XNode): void;
1318
+ /**
1319
+ * Implements `xsl:sequence` (XSLT 2.0).
1320
+ *
1321
+ * Constructs a sequence by evaluating the select expression or processing
1322
+ * child content. Unlike xsl:copy-of, xsl:sequence returns nodes by reference
1323
+ * and can return atomic values.
1324
+ *
1325
+ * @param context The expression context.
1326
+ * @param template The xsl:sequence element.
1327
+ * @param output The output node.
1328
+ */
1329
+ protected xsltSequence(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
1330
+ /**
1331
+ * Implements `xsl:analyze-string` (XSLT 2.0).
1332
+ *
1333
+ * Processes a string using a regular expression, with separate handling
1334
+ * for matching and non-matching substrings.
1335
+ *
1336
+ * @param context The expression context.
1337
+ * @param template The xsl:analyze-string element.
1338
+ * @param output The output node.
1339
+ */
1340
+ protected xsltAnalyzeString(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
1341
+ /**
1342
+ * Helper method to process xsl:matching-substring or xsl:non-matching-substring content.
1343
+ * Sets up the context with the current text and regex groups.
1344
+ */
1345
+ private processAnalyzeStringContent;
1038
1346
  /**
1039
1347
  * Evaluates a variable or parameter and set it in the current input
1040
1348
  * context. Implements `xsl:variable`, `xsl:param`, and `xsl:with-param`.
@@ -1056,6 +1364,12 @@ declare class Xslt {
1056
1364
  * @param output If set, the output where the transformation should occur.
1057
1365
  */
1058
1366
  protected xsltChildNodes(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
1367
+ /**
1368
+ * Processes child nodes while skipping xsl:on-empty and xsl:on-non-empty.
1369
+ * Used by instructions that handle these conditionals explicitly.
1370
+ */
1371
+ protected xsltChildNodesExcludingConditional(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
1372
+ private findConditionalChild;
1059
1373
  /**
1060
1374
  * This logic is used in two different places:
1061
1375
  * - `xsltPassThrough`, if the template asks this library to write a text node;
@@ -1098,6 +1412,16 @@ declare class Xslt {
1098
1412
  * @returns TODO
1099
1413
  */
1100
1414
  protected xsltAttributeValue(value: any, context: ExprContext): any;
1415
+ /**
1416
+ * Evaluates text value templates in XSLT 3.0. Text value templates
1417
+ * allow XPath expressions in braces {} within text nodes.
1418
+ * The expressions are evaluated in the current input context.
1419
+ * To include a literal brace, use {{ or }}.
1420
+ * @param value The text node value to process
1421
+ * @param context The expression context
1422
+ * @returns The processed text with expressions evaluated
1423
+ */
1424
+ protected xsltTextValueTemplate(value: string, context: ExprContext): string;
1101
1425
  /**
1102
1426
  * Evaluates an XPath expression in the current input context as a
1103
1427
  * match.