xslt-processor 4.5.0 → 4.6.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
@@ -170,6 +170,21 @@ type XPathFunctions = Record<string, XPathFunction>;
170
170
  * Type for namespace bindings (prefix -> namespace URI).
171
171
  */
172
172
  type XPathNamespaces = Record<string, string>;
173
+ /**
174
+ * Type for available documents mapping (URI -> root node).
175
+ * Used by fn:doc() and related functions (XPath 2.0+).
176
+ */
177
+ type XPathDocuments = Record<string, XPathNode | null>;
178
+ /**
179
+ * Type for available collections mapping (URI -> sequence of nodes).
180
+ * Used by fn:collection() function (XPath 2.0+).
181
+ */
182
+ type XPathCollections = Record<string, XPathNode[]>;
183
+ /**
184
+ * Type for function implementations registry.
185
+ * Maps function names (with optional namespace) to their implementations.
186
+ */
187
+ type XPathFunctionRegistry = Record<string, XPathFunction>;
173
188
  /**
174
189
  * The evaluation context for XPath expressions.
175
190
  *
@@ -178,6 +193,7 @@ type XPathNamespaces = Record<string, string>;
178
193
  * - Position information for predicates
179
194
  * - Variable bindings
180
195
  * - Custom function definitions
196
+ * - Dynamic properties like current dateTime, available documents, etc.
181
197
  */
182
198
  interface XPathContext {
183
199
  /**
@@ -220,11 +236,85 @@ interface XPathContext {
220
236
  * Used by functions like json-to-xml() which are only available in XSLT 3.0+
221
237
  */
222
238
  xsltVersion?: string;
239
+ /**
240
+ * XPath specification version being used.
241
+ * Default: '1.0'
242
+ *
243
+ * This affects:
244
+ * - Function library available
245
+ * - Type system behavior
246
+ * - Sequence vs node-set handling
247
+ */
248
+ xpathVersion?: '1.0' | '2.0' | '3.0' | '3.1';
249
+ /**
250
+ * Enable XPath 1.0 backward compatibility mode (Phase 8.1).
251
+ * When true, XPath 2.0+ expressions follow XPath 1.0 type conversion rules.
252
+ * This enables:
253
+ * - XPath 1.0 boolean conversion semantics
254
+ * - XPath 1.0 numeric conversion (with NaN for empty sequences)
255
+ * - XPath 1.0 comparison rules (node-set to string conversion)
256
+ * - XPath 1.0 logical operator behavior (short-circuit, error suppression)
257
+ * Default: false (XPath 2.0 semantics)
258
+ */
259
+ xpath10CompatibilityMode?: boolean;
260
+ /**
261
+ * Default collation for string comparisons (XPath 2.0+).
262
+ * Default: Unicode codepoint collation
263
+ */
264
+ defaultCollation?: string;
265
+ /**
266
+ * Base URI for resolving relative URIs (XPath 2.0+).
267
+ */
268
+ baseUri?: string;
269
+ /**
270
+ * Implicit timezone as duration offset from UTC (XPath 2.0+).
271
+ * Example: '-PT5H' for US Eastern Time (UTC-5)
272
+ */
273
+ implicitTimezone?: string;
274
+ /**
275
+ * Extension data for XSLT or custom implementations.
276
+ * This allows attaching arbitrary data to the context without
277
+ * polluting the main interface.
278
+ */
279
+ extensions?: Record<string, any>;
280
+ /**
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;
223
310
  }
224
311
  /**
225
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
226
316
  */
227
- type XPathResult = XPathNode[] | string | number | boolean;
317
+ type XPathResult = XPathNode[] | string | number | boolean | any[] | Map<any, any> | null | Function;
228
318
 
229
319
  declare abstract class XPathExpression {
230
320
  abstract evaluate(context: XPathContext): XPathResult;
@@ -315,6 +405,25 @@ declare class ExprContext {
315
405
  knownNamespaces: {
316
406
  [alias: string]: string;
317
407
  };
408
+ /**
409
+ * Custom system properties for system-property() function.
410
+ * Overrides the default properties (xsl:version, xsl:vendor, xsl:vendor-url).
411
+ */
412
+ systemProperties?: {
413
+ [name: string]: string;
414
+ };
415
+ /**
416
+ * Document loader function for the document() function.
417
+ * Takes a URI and returns an XNode document, or null if loading fails.
418
+ */
419
+ documentLoader?: (uri: string) => XNode | null;
420
+ /**
421
+ * Unparsed entity URIs for the unparsed-entity-uri() function.
422
+ * Maps entity names to their URIs (from DTD declarations).
423
+ */
424
+ unparsedEntities?: {
425
+ [name: string]: string;
426
+ };
318
427
  caseInsensitive: any;
319
428
  ignoreAttributesWithoutValue: any;
320
429
  returnOnFirstMatch: any;
@@ -417,6 +526,8 @@ declare class NodeConverter {
417
526
  private convertVariables;
418
527
  /**
419
528
  * Create custom functions for XPath context (like key(), document(), etc.).
529
+ * Note: Custom functions receive the XPathContext as their first argument,
530
+ * followed by the evaluated function arguments.
420
531
  */
421
532
  private createCustomFunctions;
422
533
  /**
package/index.d.ts CHANGED
@@ -170,6 +170,21 @@ type XPathFunctions = Record<string, XPathFunction>;
170
170
  * Type for namespace bindings (prefix -> namespace URI).
171
171
  */
172
172
  type XPathNamespaces = Record<string, string>;
173
+ /**
174
+ * Type for available documents mapping (URI -> root node).
175
+ * Used by fn:doc() and related functions (XPath 2.0+).
176
+ */
177
+ type XPathDocuments = Record<string, XPathNode | null>;
178
+ /**
179
+ * Type for available collections mapping (URI -> sequence of nodes).
180
+ * Used by fn:collection() function (XPath 2.0+).
181
+ */
182
+ type XPathCollections = Record<string, XPathNode[]>;
183
+ /**
184
+ * Type for function implementations registry.
185
+ * Maps function names (with optional namespace) to their implementations.
186
+ */
187
+ type XPathFunctionRegistry = Record<string, XPathFunction>;
173
188
  /**
174
189
  * The evaluation context for XPath expressions.
175
190
  *
@@ -178,6 +193,7 @@ type XPathNamespaces = Record<string, string>;
178
193
  * - Position information for predicates
179
194
  * - Variable bindings
180
195
  * - Custom function definitions
196
+ * - Dynamic properties like current dateTime, available documents, etc.
181
197
  */
182
198
  interface XPathContext {
183
199
  /**
@@ -220,11 +236,85 @@ interface XPathContext {
220
236
  * Used by functions like json-to-xml() which are only available in XSLT 3.0+
221
237
  */
222
238
  xsltVersion?: string;
239
+ /**
240
+ * XPath specification version being used.
241
+ * Default: '1.0'
242
+ *
243
+ * This affects:
244
+ * - Function library available
245
+ * - Type system behavior
246
+ * - Sequence vs node-set handling
247
+ */
248
+ xpathVersion?: '1.0' | '2.0' | '3.0' | '3.1';
249
+ /**
250
+ * Enable XPath 1.0 backward compatibility mode (Phase 8.1).
251
+ * When true, XPath 2.0+ expressions follow XPath 1.0 type conversion rules.
252
+ * This enables:
253
+ * - XPath 1.0 boolean conversion semantics
254
+ * - XPath 1.0 numeric conversion (with NaN for empty sequences)
255
+ * - XPath 1.0 comparison rules (node-set to string conversion)
256
+ * - XPath 1.0 logical operator behavior (short-circuit, error suppression)
257
+ * Default: false (XPath 2.0 semantics)
258
+ */
259
+ xpath10CompatibilityMode?: boolean;
260
+ /**
261
+ * Default collation for string comparisons (XPath 2.0+).
262
+ * Default: Unicode codepoint collation
263
+ */
264
+ defaultCollation?: string;
265
+ /**
266
+ * Base URI for resolving relative URIs (XPath 2.0+).
267
+ */
268
+ baseUri?: string;
269
+ /**
270
+ * Implicit timezone as duration offset from UTC (XPath 2.0+).
271
+ * Example: '-PT5H' for US Eastern Time (UTC-5)
272
+ */
273
+ implicitTimezone?: string;
274
+ /**
275
+ * Extension data for XSLT or custom implementations.
276
+ * This allows attaching arbitrary data to the context without
277
+ * polluting the main interface.
278
+ */
279
+ extensions?: Record<string, any>;
280
+ /**
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;
223
310
  }
224
311
  /**
225
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
226
316
  */
227
- type XPathResult = XPathNode[] | string | number | boolean;
317
+ type XPathResult = XPathNode[] | string | number | boolean | any[] | Map<any, any> | null | Function;
228
318
 
229
319
  declare abstract class XPathExpression {
230
320
  abstract evaluate(context: XPathContext): XPathResult;
@@ -315,6 +405,25 @@ declare class ExprContext {
315
405
  knownNamespaces: {
316
406
  [alias: string]: string;
317
407
  };
408
+ /**
409
+ * Custom system properties for system-property() function.
410
+ * Overrides the default properties (xsl:version, xsl:vendor, xsl:vendor-url).
411
+ */
412
+ systemProperties?: {
413
+ [name: string]: string;
414
+ };
415
+ /**
416
+ * Document loader function for the document() function.
417
+ * Takes a URI and returns an XNode document, or null if loading fails.
418
+ */
419
+ documentLoader?: (uri: string) => XNode | null;
420
+ /**
421
+ * Unparsed entity URIs for the unparsed-entity-uri() function.
422
+ * Maps entity names to their URIs (from DTD declarations).
423
+ */
424
+ unparsedEntities?: {
425
+ [name: string]: string;
426
+ };
318
427
  caseInsensitive: any;
319
428
  ignoreAttributesWithoutValue: any;
320
429
  returnOnFirstMatch: any;
@@ -417,6 +526,8 @@ declare class NodeConverter {
417
526
  private convertVariables;
418
527
  /**
419
528
  * Create custom functions for XPath context (like key(), document(), etc.).
529
+ * Note: Custom functions receive the XPathContext as their first argument,
530
+ * followed by the evaluated function arguments.
420
531
  */
421
532
  private createCustomFunctions;
422
533
  /**