-- 作者:roverhuang
-- 发布时间:10/14/2007 1:38:00 AM
-- 苏州大学关于一个XSD引用的问题[原创][原创]
苏州大学关于一个XSD引用的问题[原创] 不能够按照我XSD中定义的NAME元素的类型显示,就是name的数据类型不符合我XSD中定义的条件,也会正常显示,总之达不到预期的XSD约束XML中显示数据类型的效果,各位兄弟帮帮忙>>>> XSD文件定义 文件名称:shiporder1.xsd <?xml version="1.0" encoding="ISO-8859-1"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="shiporder"> <xs:complexType> <xs:sequence> <xs:element name="orderperson" type="xs:string" /> <xs:element name="shipto"> <xs:complexType> <xs:sequence> <xs:element name="name"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:pattern value="([a-z][A-Z])+"/> </xs:restriction> </xs:simpleType> </xs:element> <xs:element name="address" type="xs:string" /> <xs:element name="city" type="xs:string" /> <xs:element name="country" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="item" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="title" type="xs:string" /> <xs:element name="note" type="xs:string" minOccurs="0" /> <xs:element name="quantity" type="xs:positiveInteger" /> <xs:element name="price" type="xs:integer" /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="orderid" type="xs:string" use="required" /> </xs:complexType> </xs:element> </xs:schema> +++++++++++++++++++++++++++++++++ XML文件定义 文件名称:2007xs1.xml <?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="newexample.xsl"?> <shiporder orderid="889923" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="shiporder1.xsd"> <orderperson>John Smith</orderperson> <shipto> <name>oDkC</name> <address>Langgt 23</address> <city>4000 Stavanger</city> <country>Norway</country> </shipto> <item> <title>Empire Burlesque</title> <note>Special Edition</note> <quantity>1</quantity> <price>10.90</price> </item> <item> <title>Hide your heart</title> <quantity>1</quantity> <price>9.90</price> </item> </shiporder> +++++++++++++++++++++++++++++ 样式表定义 文件名称:newexample.xsl <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/2001/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>new example</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>name</th> <th>address</th> <th>city</th> <th>country</th> </tr> <xsl:for-each select="shiporder/shipto"> <tr> <td><xsl:value-of select="name"/></td> <td><xsl:value-of select="address"/></td> <td><xsl:value-of select="city"/></td> <td><xsl:value-of select="country"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
|