XSLT Module

This XQuery Module contains functions and variables to perform XSL transformations. By default, this module uses Java’s XSLT 1.0 Xalan implementation to transform documents. XSLT 3.0 will be enabled if Version 9.x of the Saxon XSLT Processor (saxon9he.jar, saxon9pe.jar, saxon9ee.jar) is found in the classpath (see Distributions for more details. A custom transformer can be specified by overwriting the system property javax.xml.transform.TransformerFactory, as shown in the following Java example:

 System.setProperty( "javax.xml.transform.TransformerFactory",  "org.custom.xslt.TransformerFactoryImpl");

Context ctx = new Context; String result = new XQuery("xslt:transform('...', '...')").execute(ctx); ... ctx.close;

=Conventions=

All functions and errors in this module are assigned to the  namespace, which is statically bound to the xslt prefix.

=Functions=

Examples
Example 1: Basic XSL transformation with dummy document and without parameters

Query:  xslt:transform-text(, 'basic.xslt')

basic.xslt   123 

Result: 123

Example 2: XSLT transformation of an input document

Query:  (: Outputs the result as html. :) declare option output:method 'html'; (: Turn whitespace chopping off. :) declare option db:chop 'no';

let $in := XSLT Programmer’s Reference Michael H. Kay XSLT Doug Tidwell Simon St. Laurent Robert Romano let $style :=     • :   </xsl:template> </xsl:stylesheet>

return xslt:transform($in, $style) Result: <pre class="brush:xml"> • XSLT Programmer’s Reference: Michael H. Kay • XSLT: Doug Tidwell

Example 3: Assigning a variable to an XSLT stylesheet

Query: <pre class="brush:xquery"> let $in := let $style := doc('variable.xsl') return xslt:transform($in, $style, map { "v": 1 })

variable.xsl <pre class="brush:xslt"> <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <xsl:param name='v'/>  <v><xsl:value-of select='$v'/></v> </xsl:template> </xsl:stylesheet>

Result: <pre class="brush:xml"> <v>1</v> <v>1</v>

=Errors=

=Changelog=


 * Version 9.2


 * Updated: Support for XML Catalog files added.


 * Version 9.0


 * Updated: xslt:transform, xslt:transform-text: $options argument added.
 * Updated: error codes updated; errors now use the module namespace


 * Version 7.6


 * Added: xslt:transform-text
 * Updated: xslt:transform returned error code


 * Version 7.3


 * Updated: $xslt:processor → xslt:processor, $xslt:version → xslt:version