1.XML文件:List.xml
<?xmlversion="1.0"encoding="GBK"?> <?xml-stylesheettype="text/xsl"href="List.xslt"?> <!DOCTYPEListPUBLIC"-//Tsybius//ListData//EN""List.dtd"> <ListVersion="1.0"LastUpdate="20140707"> <PersonPID="PID_1101"Name="Tsybius"Sex="Male"Phone="111-0000-0000"> <CatName="Cat_01"Age="2"/> </Person> <PersonPID="PID_1102"Name="Galatea"Sex="Female"Phone="000-1111-1111"> <DogName="Dog_01"Age="4"/> <RabbitName="Rabbit_01"Age="3"/> </Person> <PersonPID="PID_1201"Name="Fabius"Sex="Male"/> <PersonPID="PID_1202"Name="Cloudius"Sex="Male"/> <PersonPID="PID_1203"Name="Magnus"Sex="Male"/> </List>
2.DTD文件:List.dtd
用于校验XML文档是否符合格式
<!--文件List.xml的DTD文档--> <!--List:根节点,名单中有0个或多个人--> <!ELEMENTList(Person)*> <!--Version:版本信息,LastUpdate:最后更新日期--> <!ATTLISTListVersionCDATA#FIXED"1.0"> <!ATTLISTListLastUpdateCDATA#IMPLIED> <!--人结点,每个人可以养0只或多只宠物--> <!ELEMENTPerson(Cat|Dog|Rabbit)*> <!--ID:标识,Name:姓名,Sex:性别,Phone:电话--> <!ATTLISTPersonPIDID#required> <!ATTLISTPersonNameCDATA#IMPLIED> <!ATTLISTPersonSex(Male|Female)"Male"> <!ATTLISTPersonPhoneCDATA#IMPLIED> <!--猫Name:名称,Age:年龄--> <!ELEMENTCatEMPTY> <!ATTLISTCatNameCDATA#IMPLIED> <!ATTLISTCatAgeCDATA#IMPLIED> <!--狗Name:名称,Age:年龄--> <!ELEMENTDogEMPTY> <!ATTLISTDogNameCDATA#IMPLIED> <!ATTLISTDogAgeCDATA#IMPLIED> <!--兔Name:名称,Age:年龄--> <!ELEMENTRabbitEMPTY> <!ATTLISTRabbitNameCDATA#IMPLIED> <!ATTLISTRabbitAgeCDATA#IMPLIED> <!--文档结束-->
3.XSLT文件:List.xlst
用于显示XML文档
<xsl:stylesheetversion="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:templatematch="/"> <html> <head> <title>List</title> </head> <body> <h1>名单</h1> <hr/> <table> <thead> <tr> <th>标识</th> <th>名称</th> <th>性别</th> <th>电话</th> </tr> </thead> <tbody> <xsl:apply-templatesselect="List/Person"/> </tbody> </table> <hr/> </body> </html> </xsl:template> <xsl:templatematch="Person"> <tr> <td><xsl:value-ofselect="@PID"/></td> <td><xsl:value-ofselect="@Name"/></td> <td><xsl:value-ofselect="@Sex"/></td> <td><xsl:value-ofselect="@Phone"/></td> </tr> </xsl:template> </xsl:stylesheet>
4.FireFox中显示的XML文档
END