Transformations API for XML - III
9 May 2008The six steps discussed in the last posts makes XSLT transformation based on the StAXSource/StAXResult classes very simple and easy. The actual task is to create the StAXSource/StAXResult objects and the using the required constructor.
Time for an example. Suppose we have following XML file:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> <?xml-stylesheet type="text/xsl" href="xslFile.xsl"?> <member> <name>Martin Hook</name> <e-mail>mh@yahoo.com</e-mail> </member>
Also we have the following XSL style sheet:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" version="4.01" encoding="ISO-8859-1" indent="yes" media-type="text/html" /> <xsl:template match="/member"> <html> <body bgcolor="#FFF2EC"> <p>Member</p> <p><font face="arial" size="3"><b><i>Name:</i></b></font> <font face="arial" size="5"><xsl:value-of select="//name"/></font></p> <p><font face="arial" size="3"><b><i>E-mail:</i></b></font> <font face="arial" size="5"><xsl:value-of select="//e-mail"/></font></p> </body> </html> </xsl:template> </xsl:stylesheet>
To create StAXSource for the XSL, we use Cursor API as shown in the snippet below:
XMLStreamReader streamReaderXSL=null; … //define the Source object for the stylesheet Source XSL=new StAXSource(streamReaderXSL);
continued …
Related Posts:
Top Of Page | Trackback
If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.
It will look like this: Transformations API for XML - III