2

Just Curious,

I have two XSLT files, One is the main XSL file used for transformation, and the second has templates for a specific nodeset.

Is it possible to run the transformation within another XSL file and get the results for a specific node-set? eg: call the second XSLT in a template function of the first XSLT?

Jason
  • 65
  • 7

2 Answers2

1

A stylesheet module can import or include the templates (and variables, functions, keys, etc) defined in another stylesheet, with an xsl:import or an xsl:include statement.

There's also the transform() XPath function which you can use to execute another XSLT transformation, which allows you to specify the secondary stylesheet module dynamically, i.e. at runtime.

Conal Tuohy
  • 2,561
  • 1
  • 8
  • 15
1

You've tagged the question xslt-30, and XSLT 3.0 greatly expands the range of possibilities for how to invoke a transformation.

However, stylesheet modules (files) are not themselves units of execution. By the time you've compiled a multi-module stylesheet, there's no way of distinguishing which module a particular template rule came from. The best way to do this would be to follow the discipline of using one mode for each module (and XSLT 3.0 encourages this with a default-mode attribute on xsl:stylesheet). You can then invoke a transformation by naming the initial mode that you want to apply.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164