Description:
Sample program that helps to understand
how XSLT converts XML to HTML page using Saxon-B Processor.
Saxon-B Processor, is nothing but a jar file doing the conversion for U.
Steps to be followed:
1) Download latest Saxon-B processor jar file from http://saxon.sourceforge.net/
2) Unzip the folder & copy saxon9ee.jar file to c:saxon
3) hello.xml & hello.xsl files in directory path c:saxonsample
4) Use given command to convert hello.xml to hello.html with the help of
transformation rules mentioned in hello.xsl
C:saxon> java -jar C:saxonsaxon9ee.jar -a -s:sample/hello.xml -o:sample/hello.html
If hello.html is created in c:saxonsample then success.
hello.xml
<?xml version="1.0" encoding="iso-8859-1"?> <?xml-stylesheet type="text/xsl" href="hello.xsl"?> <greeting>Hello, Venkat Java Sources!</greeting>
hello.xsl
<?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <head> <title>Today's greeting</title> </head> <body> <p><xsl:value-of select="greeting"/></p> </body> </html> </xsl:template> </xsl:stylesheet>
hello.html
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Today's greeting</title> </head> <body> <p>Hello, Venkat Java Sources!</p> </body> </html>
How these conversion process Completed
1) We have mentioned source file to be converted as -s:sample/hello.xml to saxon processor.
2) At second line in xml, we telling the processor to use hello.xsl file
<?xml-stylesheet type=”text/xsl” href=”hello.xsl”?>
3) In xsl we have <xsl:template match=”/”> this means start read from the beginning of the document.
4) In xsl, we have <xsl:value-of select=”greeting”/> this mean, If find any element or node with name greeting then get the value of that node or element.