标签:
XSL 指扩展样式表语言(EXtensible Stylesheet Language)。XSL用来描述XML文件的格式,类似于我们可以用CSS描述HTML的格式。具体用法请转:http://www.w3school.com.cn/xsl/index.asp
例子:利用XSL来定制XML文件的显示
ex1.xml文件:
<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type = "text/xsl" href = "ex1.xsl"?> <!-- Date:2016/1/24 Writer:Wayne Ng Theme:xml-basic1 --> <cartoon> <title>妖精的尾巴</title> <author>真岛浩</author> <style>少年漫画</style> <mainCharacters> <character id="1"> <name>艾特利亚斯?纳兹?多拉格尼尔 </name> <age>400+</age> <sex>男</sex> <magic>火之灭龙魔法、雷炎龙模式</magic> <info>男主角,火之灭龙魔导士,经常闯祸。</info> </character> <character id="2"> <name>露西·哈特菲利亚 </name> <age>18</age> <sex>女</sex> <magic>星灵魔法</magic> <info>女主角,故事的叙述者,原为富商千金,由于不满父亲离家出走。</info> </character> <character id="3"> <name>艾露莎·舒卡勒托 </name> <age>26</age> <sex>女</sex> <magic>换装魔法(骑士)</magic> <info>S级魔导士,被称为“妖精女王”,严守纪律、偶尔天然呆。</info> </character> <character id="4"> <name>格雷·佛尔帕斯塔 </name> <age>18</age> <sex>男</sex> <magic>冰之造型魔法,冰之灭恶魔法</magic> <info>冰之造型魔导士,有无意识的暴露癖,后成为灭恶魔导士</info> </character> </mainCharacters> </cartoon>
ex1.xsl文件:
<?xml version = "1.0" encoding = "UTF-8"?> <xsl:stylesheet version = "1.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"> <xsl:template match = "/"> <html> <body> <h1><xsl:value-of select = "cartoon/title" /></h1> <p>作者:<xsl:value-of select = "cartoon/author" /></p> <p>漫画类型:<xsl:value-of select = "cartoon/style" /></p> <p style = "color:red">主要角色</p> <table border = "1"> <xsl:for-each select = "cartoon/mainCharacters/character" > <xsl:sort select = "age" /> <tr /> <th colspan = "4" bgcolor = "#1E90FF"><xsl:value-of select = "name"/></th> <tr /> <tr> <td><xsl:value-of select = "age" /></td> <td><xsl:value-of select = "sex" /></td> <td><xsl:value-of select = "magic" /></td> <td><xsl:value-of select = "info" /></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
显示效果:
2016/1/26修订 By野马菌
标签:
原文地址:http://www.cnblogs.com/yemajun/p/5161295.html