Changes

Jump to navigation Jump to search
153 bytes added ,  14:19, 27 February 2020
no edit summary
This [[Module Library|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 [http://www.saxonica.com/ Saxon XSLT Processor] ({{Code|saxon9he.jar}}, {{Code|saxon9pe.jar}}, {{Code|saxon9ee.jar}}) is found in the classpath (see [[Startup#Distributions|Distributions]] for more details. A custom transformer can be specified by overwriting the system property {{Code|javax.xml.transform.TransformerFactory}}, as shown in the following Java example:
<pre classsyntaxhighlight lang="brush:java">
System.setProperty(
"javax.xml.transform.TransformerFactory",
...
ctx.close();
</presyntaxhighlight>
=Conventions=
'''Query:'''
<pre classsyntaxhighlight lang="brush:xquery">
xslt:transform-text(<dummy/>, 'basic.xslt')
</presyntaxhighlight>
'''basic.xslt'''
<pre classsyntaxhighlight lang="brush:xml">
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="/">123</xsl:template>
</xsl:stylesheet>
</presyntaxhighlight>
'''Result:'''
<pre classsyntaxhighlight lang="brush:xml">123</presyntaxhighlight>
'''Example 2: XSLT transformation of an input document'''
'''Query:'''
<pre classsyntaxhighlight lang="brush:xquery">
(: Outputs the result as html. :)
declare option output:method 'html';
</xsl:stylesheet>
return xslt:transform($in, $style)</presyntaxhighlight>
'''Result:'''
<pre classsyntaxhighlight lang="brush:xml">
<html>
<body>
</body>
</html>
</presyntaxhighlight>
'''Example 3: Assigning a variable to an XSLT stylesheet'''
'''Query:'''
<pre classsyntaxhighlight lang="brush:xquery">
let $in := <dummy/>
let $style := doc('variable.xsl')
return xslt:transform($in, $style, map { "v": 1 })
</presyntaxhighlight>
'''variable.xsl'''
<pre classsyntaxhighlight lang="brush:xslt">
<xsl:stylesheet version='1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
</xsl:template>
</xsl:stylesheet>
</presyntaxhighlight>
'''Result:'''
<pre classsyntaxhighlight lang="brush:xml">
<v>1</v>
<v>1</v>
</presyntaxhighlight>
=Errors=
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu