Changes

Jump to navigation Jump to search
259 bytes added ,  06:46, 29 November 2019
This [[Module Library|XQuery Module]] contains functions and variables to perform XSLT XSL transformations. By default, this module uses Java’s XSLT 1.0 Xalan implementation to transform documents. XSLT 23.0 is used instead 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 class="brush:java">
System.setProperty( "javax.xml.transform.TransformerFactory", "org.custom.xslt.TransformerFactoryImpl"); 
Context ctx = new Context();
String result = new XQuery("xslt:transform('...', '...')").execute(ctx);
=Conventions=
All functions and errors in this module are assigned to the {{Code|<code><nowiki>http://basex.org/modules/xslt}} </nowiki></code> namespace, which is statically bound to the {{Code|xslt}} prefix.<br/>All errors are assigned to the {{Code|http://basex.org/errors}} namespace, which is statically bound to the {{Code|bxerr}} prefix.
=Functions=
{| width='100%'
|-
| width='90120' | '''Signatures'''
|{{Code|'''xslt:processor'''() as xs:string}}<br />
|-
{| width='100%'
|-
| width='90120' | '''Signatures'''
|{{Code|'''xslt:version'''() as xs:string}}<br />
|-
| '''Summary'''
|Returns the supported XSLT version (currently: "1.0" or "23.0"). "Unknown" is returned if a custom implementation was chosen.<br />
|}
==xslt:transform==
 
{| width='100%'
|-
| width='90120' | '''Signatures'''|{{Func|xslt:transform|$input as item(), $stylesheet as item()|node()}}<br />{{Func|xslt:transform|$input as item(), $stylesheet as item(), $params as map(*)?|node()}}<br />{{Func|xslt:transform|$input as item(), $stylesheet as item(), $args as map(*)?, $options as map(*)?|node()}}
|-
| '''Summary'''
|Transforms the document specified by {{Code|$input}}, using the XSLT template specified by {{Code|$stylesheet}}, and returns the result as node. {{Code|$input}} and {{Code|$stylesheet}} can be specified as<br />
* {{Code|xs:string}}, containing the path to the documentstylesheet URI,
* {{Code|xs:string}}, containing the document in its string representation, or
* {{Code|node()}}, containing the document itself.
The {{Code[[Catalog Resolver|$params}} argument XML Catalog files]] will be considered when resolving URIs. Variables can be used to bind variables bound to a stylesheet, which can either be specified<br />* as children of an via {{Code|<xslt:parameters/>$args}} element; e.g.:<pre class="brush:xml"><xslt:parameters> <xslt:key1 value='value1'/> ...</xslt:parameters></pre>* or as map, which contains all key/value pairs:<pre class="brush:xquery">map { "key1" := "value1", ... }</pre>Note that (only strings are supported when using Saxon (XSLT 23.0and Saxon).The following {{Code|$options}} are available:* {{Code|cache}}: cache XSLT transformer (speeds up repeated transformations, but increases memory consumption)
|-
| '''Error'''
|{{Error|BXSL0001error|#Errors}} an error occurred during the transformation process.
|}
{| width='100%'
|-
| width='90120' | '''Signatures'''|{{Func|xslt:transform-text|$input as item(), $stylesheet as item()|xs:string}}<br />{{Func|xslt:transform-text|$input as item(), $stylesheet as item(), $params as map(*)?|xs:string}}<br />{{Func|xslt:transform-text|$input as item(), $stylesheet as item(), $params as map(*)?, $options as map(*)?|xs:string}}
|-
| '''Summary'''
|Transforms the document specified by {{Code|$input}}, using the XSLT template specified by {{Code|$stylesheet}}, and returns the result as string. The parameters are semantics of {{Code|$params}} and {{Code|$options}} is the same as described for [[#xslt:transform|xslt:transform]].<br />
|-
| '''Error'''
|{{Error|BXSL0001error|#Errors}} an error occurred during the transformation process.
|}
</books>
let $style :=
<xsl:stylesheet version='23.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:output method='xml'/>
<xsl:template match="/">
let $in := <dummy/>
let $style := doc('variable.xsl')
return ( xslt:transform($in, $style, <xslt:parameters><xslt:v>1</xslt:v></xslt:parameters>), xslt:transform($in, $style, map { "v" := 1 }))
</pre>
'''variable.xsltxsl'''
<pre class="brush:xslt">
<xsl:stylesheet version='1.0'
=Errors=
{| width='100%' class="wikitable" width="100%"! width="5%110"|Code! width="95%"|Description
|-
|{{Code|BXSL0001error}}
| An error occurred during the transformation process.
|}
=Changelog=
 
;Version 9.2
 
* Updated: Support for XML Catalog files added.
 
;Version 9.0
 
* Updated: [[#xslt:transform|xslt:transform]], [[#xslt:transform-text|xslt:transform-text]]: {{Code|$options}} argument added.
* Updated: error codes updated; errors now use the module namespace
;Version 7.6
 
* Added: [[#xslt:transform-text|xslt:transform-text]]
* Updated: [[#xslt:transform|xslt:transform]] returned error code
;Version 7.3
 
* Updated: $xslt:processor → [[#xslt:processor|xslt:processor]], $xslt:version → [[#xslt:version|xslt:version]]
 
[[Category:XQuery]]
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu