These examples illustrate all the steps required to use the document function of XSLT.
The use of built-in functions of XSLT is not recommended in pureXML. However, if you decide to use the document function of XSLT, you must set up the DB2_XSLT_ALLOWED_PATH registry variable to the list of directories containing your XML documents to limit the references to a list of URIs. By default, the document function of XSLT cannot access any XML document.
The following examples illustrate how to use the document function of XSLT in a secure fashion.
The examples store the XML document and the XSLT stylesheets in XML columns and use the XSLTRANSFORM function to convert the XML document using one of the XSLT stylesheets. The examples use the XMLDATA and XMLTRANS tables created for Example: Using XSLT to remove namespaces.
db2set DB2_XSLT_ALLOWED_PATH="/home/user/xml_files"
Restart the instance to make this registry variable setting effective.
INSERT INTO XMLTRANS (XSLID, XSLT)
VALUES ( 3, '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:value-of select="document(''/home/user/xml_files/n.xml'')/*"/>
</xsl:template>
</xsl:stylesheet>') ;
SELECT XSLTRANSFORM (XMLDOC USING XSLT ) FROM XMLDATA, XMLTRANS
WHERE ID = 1 and XSLID = 3
The XSLTRANSFORM command converts the XML document using the XSLT stylesheet and returns the converted XML document. If the database manager cannot open the document specified in the document function of XSLT, then call to the document function is ignored.
Restart the instance to make this registry variable setting effective.
INSERT INTO XMLTRANS (XSLID, XSLT)
VALUES ( 4,
'<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:value-of select="document(''C:\Documents and Settings\user\xml_files\t.xml'')/*"/>
</xsl:template>
</xsl:stylesheet>') ;
SELECT XSLTRANSFORM (XMLDOC USING XSLT ) FROM XMLDATA, XMLTRANS
WHERE ID = 1 and XSLID = 4
The XSLTRANSFORM command converts the XML document using the XSLT stylesheet and returns the converted XML document. If the database manager cannot open the document specified in the document function of XSLT, then call to the document function is ignored.