I want to publish my DB2 data to PDF file using XSLT. Has anyone tried this?

This process requires three steps:

i)First, you create an XML file using DB2 built-in XML functions.
ii)You transform that file using XSL-FO (eXtensible Stylesheet Language - Formatting Objects). Apache xlane might be useful for you.
iii)Using an XSL-FO renderer, you transform the file to PDF format. Use apache FOP framework to create PDF files with XLST.

You can read more at
http://www.ibm.com/developerworks/db2/library/techarticle/dm-0401lima/#section2

I want to translate XML document using XSL transformation. Does DB2 V9 support xsltransform XSLT functions? If DB2 V9 does not support this what are other XSLT functions supported by DB2 V9?

DB2 9 does not support XSLT supported functions. However, DB2 V9.5 provides the functionality of processing XML document using XSL transformation within the database itself. The XML document stored in the database can be transformed to the HTML format by applying XLST stylesheet. To do this, DB2 V9.5 introduces the xsltransform function. It also supports stylesheets which use parameters. The xsltransform function can apply the XSLT stylesheet stored in a database table column as an XML document on an XML document. This gives the user the flexibility to retrieve a transformed XML document from the database and directly represent it on the web.

DB2 V9 supports XSLTransformToClob and XSLTransformToFile XSLT function.

XSLTransformToClob() reads an XML document as CLOB locator and a stylesheet as CLOB or from a file, and returns the document as CLOB.

XSLTransformToFile() Transforms the incoming XML document with the stylesheet and the XSLT parameter document. The transformed XML document is written into a file. When a directory and a suffix are passed as parameters, this UDF creates a file with the specified suffix in the specified directory.

How do I create an HTML document using XSLT stylesheet?

You can create your HTML file by using the XSLTransformToFile or the XSLTransformToClob UDFs. The former returns the HTML document in a file while the latter returns it as a CLOB

To create your HTML document as a file, use the following syntax:

SELECT XSLTransformToFile(CAST(doc AS CLOB(4k)),
'dxx_install\samples\extenders\db2xml\xslt\getstart.xsl',
0, 'html\getstart.html') FROM RESULT_TAB

where dxx_install is the directory where you installed DB2 XML Extender.

How are XML documents transformed and can DB2 9 XML extenders be used for this?

DB2 XML extenders provide an XSLT UDF to transform XML documents inside the database.
The two XSL UDFs defined in DB2 XML Extenders are XSLTransformToClob() and XSLTransformToFile().

SELECT XSLTransformToClob( info, /temp/xslfilename.xsl) FROM xslcustomers

You need to enable the database for XML extenders in order to use the XSLT UDFs because DB2 Viper has the XSL UDF as a part of the XML extender support, there is not any built-in function for XSL transformation.

Since XQuery has a lot of overlapping functionality with XSL, you can use XQuery in conjunction with the SQL/XML functions to transform and publish XML documents.

I want to use XML extenders of DB2. Can anyone explain the syntax of XSL function XSLTransformToFile?

Syntax of XSLTransformToFile:

XSLTransformToFile (XMLobj , stylesheet , param , validate , filename, dir , suffix)

i) XMLobj -> The XML document (CLOB) or (CAST(doc AS CLOB(4k)))
ii) stylesheet -> The style sheet (CLOB), The location and name of the stylesheet input file(VARCHAR)
iii) param -> The XSLT parameter document (CLOB), The location and name of the XSLT parameter file(VARCHAR)
iv) validate -> Enable (1) or disable (0) validation of the XMLobj(INTEGER)
v) filename -> The name of the output file(VARCHAR)
vi) dir -> The directory of the output file(VARCHAR)
vii) suffix -> The suffix of the output file(VARCHAR)

There is another XSL function, XSLTransformToClob. Is the syntax similar to XSLTransformToFile?

XSLTransformToClob() reads an XML document as CLOB locator and a stylesheet as CLOB or from a file, and returns the document as CLOB.

Syntax of XSLTransformToClob:

XSLTransformToClob(xmlobj , stylesheet, param, validate)

i) xmlobj -> The XML document (CLOB) or (CAST(doc AS CLOB(4k)))
ii) stylesheet -> The style sheet (CLOB), The location and name of the stylesheet input file(VARCHAR)
iii) param -> The XSLT parameter document (CLOB), The location and name of the XSLT parameter file(VARCHAR)
iv) validate -> Enable (1) or disable (0) validation of the xmlobj (INTEGER)

Consider the following example:

SELECT XSLTransformToClob(CAST(doc AS CLOB(4k)),
‘c:\dxx_install\samples\extenders\db2xml\xslt\getstart.xsl', 1)
FROM xslt_tab

In the above example, the xml document is stored in in the doc column which is of type “XML”. And “c:\dxx_install\samples\extenders\db2xml\xslt\getstart.xsl” stylesheet is applied to the xml document.

After executing the above specified query, it returns a document by applying stylesheet on the document stored in the “doc” column.

I have used DB2. But new to DB2 9. I want to make use of XML extender XSL functions to transform XML data into HTML. The functions XSLTransformToFile and XSLTransformToClob take CLOB object as one of the parameters in which we can store XML data. In DB2 9 I think it is possible to store XML document directly in the “XML” type column. How we can pass XMLdocument which is in “XML” type column to these functions?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.