HelloWorld程序
1.helloworld.xml文件
<?xml version="1.0" encoding="gb2312" ?> <?xml-stylesheet type="text/xsl" href="hellowold.xslt"?> <root> <name>zhangqs008</name> <name>清山</name> </root> 注意:如果有中文编码,请指定为encoding="gb2312" 方式。
2.被关联的样式表:helloworld.sxlt
<?xml version="1.0" encoding="gb2312" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/root"> <html> <title>this is my first xslt programm</title> <body> <xsl:for-each select="name"> <xsl:text>Hello world,This is </xsl:text> <xsl:value-of select="." /> <xsl:text> Speaking</xsl:text> <br /> <br /> </xsl:for-each> </body> </html> </xsl:template> </xsl:stylesheet>
3.在应用了上述的XSLT文档以后,原来的XML文档转换为如下的HTML代码:
<html> <title>this is my first xslt programm</title> <body>Hello world,This is zhangqs008 Speaking<br><br>Hello world,This is 清山Speaking<br><br></body> </html>