XSLT
Purpose¶
Saxon-HE processor with stylesheet caching.
The open-source implementation of XSLT 3.0, XPath 2.0 and 3.1, and XQuery 3.1. This provides the “basic” conformance level of these languages; it also supports some optional features of the specifications such as serialization and support for XQuery modules.
Methods¶
Binding name: p6.xslt
Method: String process(String id, String xslt, String xml, Map<String, Object> parameters = null)
Process the given xml
with the supplied xslt
and applying the supplied parameters
, storing the compiled xslt
in the cache with the supplied id
.
Results of the transformation are returned as a String.
Allowed parameter types are: - Boolean - Integer - Long - Short - Character - Byte - String - Double - Float - BigDecimal - BigInteger - URI
Note
Subsequent calls to process()
will search for and use the cached instance of the compiled XSLT giving much greater performance.
The cache will expire entries after 10 minutes of inactivity.
Examples¶
Without params¶
def results = p6.xslt.process("myTransform", p6.resource.get('STYLESHEET'), p6.resource.get('XmlIn'))
println results
STYLESHEET
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/hello-world">
<HTML>
<HEAD><TITLE/></HEAD>
<BODY>
<H1><xsl:value-of select="greeting"/></H1>
<xsl:apply-templates select="greeter"/>
</BODY>
</HTML>
</xsl:template>
<xsl:template match="greeter">
<DIV>from <I><xsl:value-of select="."/></I></DIV>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="hello.xsl"?>
<hello-world>
<greeter>An XSLT Programmer</greeter>
<greeting>Hello, World!</greeting>
</hello-world>
With params¶
def params = [
"PARAM_INTEGER": 42,
"PARAM_STRING": "Amalto",
"PARAM_BOOLEAN": true
]
def results = p6.xslt.process("myTransform", p6.resource.get('STYLESHEET'), p6.resource.get('XmlIn'))
println results
STYLESHEET
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:param name="PARAM_INTEGER"/>
<xsl:param name="PARAM_STRING"/>
<xsl:param name="PARAM_BOOLEAN"/>
<xsl:template match="/hello-world">
<HTML>
<HEAD><TITLE/></HEAD>
<BODY>
<H1><xsl:value-of select="greeting"/></H1>
<xsl:apply-templates select="greeter"/>
<ul>
<li>Int: <xsl:value-of select="$PARAM_INTEGER"/></li>
<li>String: <xsl:value-of select="$PARAM_STRING"/></li>
<li>Boolean: <xsl:value-of select="$PARAM_BOOLEAN"/></li>
</ul>
</BODY>
</HTML>
</xsl:template>
<xsl:template match="greeter">
<DIV>from <I><xsl:value-of select="."/></I></DIV>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="hello.xsl"?>
<hello-world>
<greeter>An XSLT Programmer</greeter>
<greeting>Hello, World!</greeting>
</hello-world>