xslt-processor 4.8.0 → 4.8.2

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
@@ -833,11 +833,21 @@ declare class Xslt {
833
833
  * Manages loaded packages and their components.
834
834
  */
835
835
  private packageRegistry;
836
+ /**
837
+ * Callback for loading external packages.
838
+ * Called when a package is not found in the registry.
839
+ */
840
+ private packageLoader?;
836
841
  /**
837
842
  * Current package being processed (for XSLT 3.0).
838
843
  * null if processing a non-package stylesheet.
839
844
  */
840
845
  private currentPackage;
846
+ /**
847
+ * Current override context (for XSLT 3.0 xsl:original).
848
+ * Tracks the original component when executing an override.
849
+ */
850
+ private currentOverrideContext;
841
851
  /**
842
852
  * Accumulator registry for XSLT 3.0 accumulators.
843
853
  * Stores accumulator definitions and current state during processing.
@@ -1100,6 +1110,15 @@ declare class Xslt {
1100
1110
  * @param output The output node.
1101
1111
  */
1102
1112
  protected xsltPackage(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
1113
+ /**
1114
+ * Loads and registers an external package.
1115
+ * Creates a temporary context and processes the package document.
1116
+ *
1117
+ * @param name The package name/URI.
1118
+ * @param packageDoc The parsed package document.
1119
+ * @param version Optional semantic version string.
1120
+ */
1121
+ protected loadAndRegisterPackage(name: string, packageDoc: XNode, version?: string): Promise<void>;
1103
1122
  /**
1104
1123
  * Implements `<xsl:use-package>` (XSLT 3.0 Section 3.7).
1105
1124
  * Imports another package and makes its public components available.
@@ -1115,6 +1134,14 @@ declare class Xslt {
1115
1134
  * @param template The xsl:expose element.
1116
1135
  */
1117
1136
  protected xsltExpose(context: ExprContext, template: XNode): void;
1137
+ /**
1138
+ * Find a component definition in the package root.
1139
+ * @param packageRoot The package root element
1140
+ * @param type The component type to find
1141
+ * @param name The component name (null for all matching type)
1142
+ * @returns Component information or null if not found
1143
+ */
1144
+ private findComponentInPackageRoot;
1118
1145
  /**
1119
1146
  * Implements `<xsl:accept>` (XSLT 3.0 Section 3.9).
1120
1147
  * Accepts and optionally overrides a component from a used package.
@@ -1122,6 +1149,55 @@ declare class Xslt {
1122
1149
  * @param template The xsl:accept element.
1123
1150
  */
1124
1151
  protected xsltAccept(context: ExprContext, template: XNode): void;
1152
+ /**
1153
+ * Implements <xsl:override> (XSLT 3.0 Section 3.7.2).
1154
+ * Overrides components from a used package.
1155
+ */
1156
+ protected xsltOverride(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
1157
+ /**
1158
+ * Find components in a package matching the given criteria.
1159
+ * Used by xsl:accept to locate components from used packages.
1160
+ *
1161
+ * @param pkg The package to search in
1162
+ * @param componentType The type of component to find
1163
+ * @param namePatterns Array of name patterns ('*' for all, or specific names)
1164
+ * @returns Array of matching components
1165
+ */
1166
+ private findComponentsInPackage;
1167
+ /**
1168
+ * Get the name to use when matching components.
1169
+ * For named components (functions, variables, attribute-sets), returns the name.
1170
+ * For templates, returns the name if present, otherwise returns null (match-based templates).
1171
+ *
1172
+ * @param component The component to get the name from
1173
+ * @returns The component name for matching, or null if unnamed
1174
+ */
1175
+ private getComponentNameForMatching;
1176
+ /**
1177
+ * Implements <xsl:original> (XSLT 3.0 Section 3.7.2).
1178
+ * Calls the original component from within an override.
1179
+ */
1180
+ protected xsltOriginal(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
1181
+ /**
1182
+ * Implements `<xsl:mode>` (XSLT 3.0 Section 3.5).
1183
+ * Declares a mode with visibility and other properties.
1184
+ * Only valid within an xsl:package.
1185
+ */
1186
+ protected xsltMode(context: ExprContext, template: XNode): void;
1187
+ /**
1188
+ * Get the effective component, checking for overrides first.
1189
+ * If the component has been overridden in the current package, returns the override.
1190
+ * Otherwise, returns the original component.
1191
+ * @param component The original component
1192
+ * @returns The effective component (override or original)
1193
+ */
1194
+ private getEffectiveComponent;
1195
+ /**
1196
+ * Collect templates from accepted components in used packages.
1197
+ * @param mode The mode to match (null for default mode)
1198
+ * @returns Array of template priority interfaces
1199
+ */
1200
+ private collectAcceptedTemplates;
1125
1201
  /**
1126
1202
  * Implements `<xsl:stream>` (XSLT 3.0 Section 16).
1127
1203
  * Enables streaming processing of large documents.
@@ -1372,6 +1448,14 @@ declare class Xslt {
1372
1448
  * @param template The xsl:function element.
1373
1449
  */
1374
1450
  protected xsltFunction(context: ExprContext, template: XNode): void;
1451
+ /**
1452
+ * Coerce a NodeValue to a specific type based on the 'as' attribute.
1453
+ *
1454
+ * @param value The value to coerce.
1455
+ * @param type The target type (e.g., "xs:integer", "xs:string", "xs:boolean").
1456
+ * @returns The coerced value.
1457
+ */
1458
+ protected coerceToType(value: NodeValue, type: string): NodeValue;
1375
1459
  /**
1376
1460
  * Execute a user-defined xsl:function.
1377
1461
  * Called when a function from userDefinedFunctions is invoked from XPath.
@@ -1408,6 +1492,24 @@ declare class Xslt {
1408
1492
  * @returns A map of href URIs to serialized output strings.
1409
1493
  */
1410
1494
  getResultDocuments(): Map<string, string>;
1495
+ /**
1496
+ * Sets the package loader callback.
1497
+ * The callback is called when a package is referenced via xsl:use-package
1498
+ * but is not found in the registry.
1499
+ *
1500
+ * @param loader A function that loads package documents by URI and optional version.
1501
+ * Returns the parsed package document, or null if not found.
1502
+ */
1503
+ setPackageLoader(loader: (uri: string, version?: string) => Promise<XNode | null>): void;
1504
+ /**
1505
+ * Pre-registers a package for use in transformations.
1506
+ * The package is parsed and stored in the internal registry.
1507
+ *
1508
+ * @param name The package name/URI.
1509
+ * @param packageDoc The parsed package document.
1510
+ * @param version Optional semantic version string.
1511
+ */
1512
+ registerPackage(name: string, packageDoc: XNode, version?: string): Promise<void>;
1411
1513
  /**
1412
1514
  * Implements `xsl:perform-sort` (XSLT 2.0).
1413
1515
  *
@@ -1441,6 +1543,12 @@ declare class Xslt {
1441
1543
  * value. `xsl:variable` and `xsl:with-param` override; `xsl:param` doesn't.
1442
1544
  */
1443
1545
  protected xsltVariable(context: ExprContext, template: XNode, override: boolean): Promise<void>;
1546
+ /**
1547
+ * Register accepted variables from used packages into the context.
1548
+ * Called after processing package use-package declarations.
1549
+ * @param context The expression context.
1550
+ */
1551
+ private registerAcceptedVariables;
1444
1552
  /**
1445
1553
  * Traverses the template node tree. Calls the main processing
1446
1554
  * function with the current input context for every child node of the
@@ -1553,6 +1661,15 @@ declare class Xslt {
1553
1661
  * @param context The expression context.
1554
1662
  */
1555
1663
  private registerUserDefinedFunctionsInContext;
1664
+ /**
1665
+ * Check if there are any accepted functions in used packages.
1666
+ */
1667
+ private hasAcceptedFunctions;
1668
+ /**
1669
+ * Register accepted functions from used packages.
1670
+ * @param functionsMap The map to register functions into.
1671
+ */
1672
+ private registerAcceptedFunctions;
1556
1673
  /**
1557
1674
  * Apply one or more attribute sets to an element.
1558
1675
  * Parses space-separated attribute set names and applies them.
package/index.d.ts CHANGED
@@ -833,11 +833,21 @@ declare class Xslt {
833
833
  * Manages loaded packages and their components.
834
834
  */
835
835
  private packageRegistry;
836
+ /**
837
+ * Callback for loading external packages.
838
+ * Called when a package is not found in the registry.
839
+ */
840
+ private packageLoader?;
836
841
  /**
837
842
  * Current package being processed (for XSLT 3.0).
838
843
  * null if processing a non-package stylesheet.
839
844
  */
840
845
  private currentPackage;
846
+ /**
847
+ * Current override context (for XSLT 3.0 xsl:original).
848
+ * Tracks the original component when executing an override.
849
+ */
850
+ private currentOverrideContext;
841
851
  /**
842
852
  * Accumulator registry for XSLT 3.0 accumulators.
843
853
  * Stores accumulator definitions and current state during processing.
@@ -1100,6 +1110,15 @@ declare class Xslt {
1100
1110
  * @param output The output node.
1101
1111
  */
1102
1112
  protected xsltPackage(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
1113
+ /**
1114
+ * Loads and registers an external package.
1115
+ * Creates a temporary context and processes the package document.
1116
+ *
1117
+ * @param name The package name/URI.
1118
+ * @param packageDoc The parsed package document.
1119
+ * @param version Optional semantic version string.
1120
+ */
1121
+ protected loadAndRegisterPackage(name: string, packageDoc: XNode, version?: string): Promise<void>;
1103
1122
  /**
1104
1123
  * Implements `<xsl:use-package>` (XSLT 3.0 Section 3.7).
1105
1124
  * Imports another package and makes its public components available.
@@ -1115,6 +1134,14 @@ declare class Xslt {
1115
1134
  * @param template The xsl:expose element.
1116
1135
  */
1117
1136
  protected xsltExpose(context: ExprContext, template: XNode): void;
1137
+ /**
1138
+ * Find a component definition in the package root.
1139
+ * @param packageRoot The package root element
1140
+ * @param type The component type to find
1141
+ * @param name The component name (null for all matching type)
1142
+ * @returns Component information or null if not found
1143
+ */
1144
+ private findComponentInPackageRoot;
1118
1145
  /**
1119
1146
  * Implements `<xsl:accept>` (XSLT 3.0 Section 3.9).
1120
1147
  * Accepts and optionally overrides a component from a used package.
@@ -1122,6 +1149,55 @@ declare class Xslt {
1122
1149
  * @param template The xsl:accept element.
1123
1150
  */
1124
1151
  protected xsltAccept(context: ExprContext, template: XNode): void;
1152
+ /**
1153
+ * Implements <xsl:override> (XSLT 3.0 Section 3.7.2).
1154
+ * Overrides components from a used package.
1155
+ */
1156
+ protected xsltOverride(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
1157
+ /**
1158
+ * Find components in a package matching the given criteria.
1159
+ * Used by xsl:accept to locate components from used packages.
1160
+ *
1161
+ * @param pkg The package to search in
1162
+ * @param componentType The type of component to find
1163
+ * @param namePatterns Array of name patterns ('*' for all, or specific names)
1164
+ * @returns Array of matching components
1165
+ */
1166
+ private findComponentsInPackage;
1167
+ /**
1168
+ * Get the name to use when matching components.
1169
+ * For named components (functions, variables, attribute-sets), returns the name.
1170
+ * For templates, returns the name if present, otherwise returns null (match-based templates).
1171
+ *
1172
+ * @param component The component to get the name from
1173
+ * @returns The component name for matching, or null if unnamed
1174
+ */
1175
+ private getComponentNameForMatching;
1176
+ /**
1177
+ * Implements <xsl:original> (XSLT 3.0 Section 3.7.2).
1178
+ * Calls the original component from within an override.
1179
+ */
1180
+ protected xsltOriginal(context: ExprContext, template: XNode, output?: XNode): Promise<void>;
1181
+ /**
1182
+ * Implements `<xsl:mode>` (XSLT 3.0 Section 3.5).
1183
+ * Declares a mode with visibility and other properties.
1184
+ * Only valid within an xsl:package.
1185
+ */
1186
+ protected xsltMode(context: ExprContext, template: XNode): void;
1187
+ /**
1188
+ * Get the effective component, checking for overrides first.
1189
+ * If the component has been overridden in the current package, returns the override.
1190
+ * Otherwise, returns the original component.
1191
+ * @param component The original component
1192
+ * @returns The effective component (override or original)
1193
+ */
1194
+ private getEffectiveComponent;
1195
+ /**
1196
+ * Collect templates from accepted components in used packages.
1197
+ * @param mode The mode to match (null for default mode)
1198
+ * @returns Array of template priority interfaces
1199
+ */
1200
+ private collectAcceptedTemplates;
1125
1201
  /**
1126
1202
  * Implements `<xsl:stream>` (XSLT 3.0 Section 16).
1127
1203
  * Enables streaming processing of large documents.
@@ -1372,6 +1448,14 @@ declare class Xslt {
1372
1448
  * @param template The xsl:function element.
1373
1449
  */
1374
1450
  protected xsltFunction(context: ExprContext, template: XNode): void;
1451
+ /**
1452
+ * Coerce a NodeValue to a specific type based on the 'as' attribute.
1453
+ *
1454
+ * @param value The value to coerce.
1455
+ * @param type The target type (e.g., "xs:integer", "xs:string", "xs:boolean").
1456
+ * @returns The coerced value.
1457
+ */
1458
+ protected coerceToType(value: NodeValue, type: string): NodeValue;
1375
1459
  /**
1376
1460
  * Execute a user-defined xsl:function.
1377
1461
  * Called when a function from userDefinedFunctions is invoked from XPath.
@@ -1408,6 +1492,24 @@ declare class Xslt {
1408
1492
  * @returns A map of href URIs to serialized output strings.
1409
1493
  */
1410
1494
  getResultDocuments(): Map<string, string>;
1495
+ /**
1496
+ * Sets the package loader callback.
1497
+ * The callback is called when a package is referenced via xsl:use-package
1498
+ * but is not found in the registry.
1499
+ *
1500
+ * @param loader A function that loads package documents by URI and optional version.
1501
+ * Returns the parsed package document, or null if not found.
1502
+ */
1503
+ setPackageLoader(loader: (uri: string, version?: string) => Promise<XNode | null>): void;
1504
+ /**
1505
+ * Pre-registers a package for use in transformations.
1506
+ * The package is parsed and stored in the internal registry.
1507
+ *
1508
+ * @param name The package name/URI.
1509
+ * @param packageDoc The parsed package document.
1510
+ * @param version Optional semantic version string.
1511
+ */
1512
+ registerPackage(name: string, packageDoc: XNode, version?: string): Promise<void>;
1411
1513
  /**
1412
1514
  * Implements `xsl:perform-sort` (XSLT 2.0).
1413
1515
  *
@@ -1441,6 +1543,12 @@ declare class Xslt {
1441
1543
  * value. `xsl:variable` and `xsl:with-param` override; `xsl:param` doesn't.
1442
1544
  */
1443
1545
  protected xsltVariable(context: ExprContext, template: XNode, override: boolean): Promise<void>;
1546
+ /**
1547
+ * Register accepted variables from used packages into the context.
1548
+ * Called after processing package use-package declarations.
1549
+ * @param context The expression context.
1550
+ */
1551
+ private registerAcceptedVariables;
1444
1552
  /**
1445
1553
  * Traverses the template node tree. Calls the main processing
1446
1554
  * function with the current input context for every child node of the
@@ -1553,6 +1661,15 @@ declare class Xslt {
1553
1661
  * @param context The expression context.
1554
1662
  */
1555
1663
  private registerUserDefinedFunctionsInContext;
1664
+ /**
1665
+ * Check if there are any accepted functions in used packages.
1666
+ */
1667
+ private hasAcceptedFunctions;
1668
+ /**
1669
+ * Register accepted functions from used packages.
1670
+ * @param functionsMap The map to register functions into.
1671
+ */
1672
+ private registerAcceptedFunctions;
1556
1673
  /**
1557
1674
  * Apply one or more attribute sets to an element.
1558
1675
  * Parses space-separated attribute set names and applies them.