-- 作者:philipfu
-- 发布时间:9/1/2007 11:40:00 AM
-- [求助]新人求助如何用xslt 去显示有schema 的 xml 请各位教教小第!!!
请各位教教小第! 如何用xslt 去显示有schema 的 xml 。 我用vs 2005 做了xml, xslt 同 schema file , 但不能显示到xslt资料(table , css )。 ///-------------------students.xml-------------------------------////// <?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type="text/xsl" href="students.xsl"?> <students xmlns="http://www.w3schools.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="students.xsd"> <student> <firstname>Chung Ting</firstname> <lastname>Au Yeung</lastname> <ulid>ctauyeung</ulid> <account>xn352104</account> <class>SENIOR</class> </student> <student> <firstname>Ho Ting</firstname> <lastname>Chan</lastname> <ulid>htchan</ulid> <account>xn352111</account> <class>JENIOR</class> </student> </students> ///-------------------------students.xsd------------------------------------/// <?xml version="1.0" encoding="utf-8"?> <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="students"> <xs:complexType> <xs:sequence> <xs:element maxOccurs="unbounded" name="student"> <xs:complexType> <xs:sequence> <xs:element name="firstname" type="xs:string" /> <xs:element name="lastname" type="xs:string" /> <xs:element name="ulid" type="xs:string" /> <xs:element name="account" type="xs:string" /> <xs:element name="class" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> //---------------------------students.xsl---------------------------------/// <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xsl output method="html" encoding="utf-8" indent="no"/> <!--<xsl:import-schema schema-location="students.xsd"/>--> <xsl:template match="xs:element[@name='students']"> <html> <body> <table cellspacing="0"> <tr bgcolor="#FFFFFF"> <th>FIRSTNAME</th> <th>LASTNAME</th> <th>ULID</th> <th>ACCOUNT</th> <th>CLASS</th> </tr> <xsl:for-each select="xs:element[@name='student']"> <xsl:sort select="class"/> <xsl:variable name="pos" select="position() mod 2"/> <xsl:if test="$pos=1"> <tr bgcolor="#dddddd"> <td> <xsl:value-of select="xs:firstname"/> </td> <td> <xsl:value-of select="xs:lastname"/> </td> <td> <xsl:value-of select="xs:ulid"/> </td> <td> <xsl:value-of select="xs:account"/> </td> <td> <xsl:value-of select="xs:class"/> </td> </tr> </xsl:if> <xsl:if test="$pos=0"> <tr> <td> <xsl:value-of select="xs:firstname"/> </td> <td> <xsl:value-of select="xs:lastname"/> </td> <td> <xsl:value-of select="xs:ulid"/> </td> <td> <xsl:value-of select="xs:account"/> </td> <td> <xsl:value-of select="xs:class"/> </td> </tr> </xsl:if> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
|