XSLTRANSFORM
The XSLTRANSFORM function transforms an XML document into a different data format. The output can be any form possible for the XSLT processor, including but not limited to XML, HTML, and plain text.
>>-XSLTRANSFORM(xml-document,xsl-stylesheet,xsl-parameters)----><
The schema is SYSFUN.
- xml-document
- An expression that returns a well-formed XML document with a data type of CHAR, VARCHAR, or CLOB(2 MB). The input expression can contain XMLSERIALIZE to serialize an XML data type into a CLOB. The xml-document is transformed with the XSL style sheet that is specified in xsl-stylesheet. The XML document must at minimum be single-rooted and well-formed.
- xsl-stylesheet
- An expression that returns a well-formed XML document with a data type of CHAR, VARCHAR, or CLOB(256 KB). The input expression can contain XMLSERIALIZE to serialize an XML data type into a CLOB. The document is an XSL style sheet that conforms to the W3C XSLT Version 1.0 Recommendation. This style sheet is applied to transform the value that is specified in xml-document.
- xsl-parameters
- An expression that returns a well-formed XML document or empty
string with a data type of CHAR, VARCHAR, or CLOB(64 KB). The input
expression can contain XMLSERIALIZE to serialize an XML data type
into a CLOB. The xsl-parameters provides
parameter values to the XSL style sheet specified in xsl-stylesheet.
The value of the parameter can be specified as an attribute, or as
a text node. If both are specified, the value in the attribute is
used. The xsl-stylesheet document must have
matching param name attribute values. The syntax
of the parameter document is as follows:
<params xmlns="http://www.ibm.com/XSLTransformParameters"> <param name="..." value="..."/> <param name="...">enter value here</param> ... </params>
Important: If xsl-parameters are not needed, you still must supply an empty string or the function result is null.
The result of the function is of type CLOB(2 MB).
This user-defined function requires IBM® SDK for z/OS®, Java Technology Edition Version 6.
This user-defined function uses the XSLT support that is provided by the W3C XSL Transformations V1.0 Recommendation.
Tip: To create your own variation of XSLTRANSFORM, start with
the CREATE FUNCTION shown in sample member DSNTESR. Change the function
name and size of the definition of the input parameters for your environment.
Example 1: This example illustrates how to use
XSLT as a formatting engine in a C program.
EXEC SQL BEGIN DECLARE SECTION;
SQL TYPE IS CLOB(2M) xmldoc;
SQL TYPE IS CLOB(256K) stylesheet;
SQL TYPE IS CLOB(64K) xslparms;
SQL TYPE IS CLOB(2M) result;
EXEC SQL END DECLARE SECTION;
EXEC SQL
SET :xmldoc = CLOB('<?xml version="1.0"?><hi>Hello</hi>');
EXEC SQL SET :stylesheet = CLOB( '<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="yes"/>
<xsl:param name="parm" select="'World'"/>
<xsl:template match="hi">
<out>
<xsl:value-of select="."/>
<xsl:text>, </xsl:text>
<xsl:value-of select="$parm"/>
<xsl:text>!!!</xsl:text>
</out>
</xsl:template>
</xsl:stylesheet>');
EXEC SQL SET :xslparms = CLOB(
'<params xmlns="http://www.ibm.com/XSLTransformParameters">
<param name="parm">Silicon Valley</param>
</params>');
EXEC SQL
SELECT SYSFUN.XSLTRANSFORM(:xmldoc, :stylesheet :xslparms)
INTO :result FROM SYSIBM.SYSDUMMY1;
The XML document is transformed by the XSL style sheet. The result of the transformation is:
<?xml version="1.0" encoding="UTF-8"?>
<out>Hello, Silicon Valley!!!</out>