【发布时间】:2015-08-25 11:11:11
【问题描述】:
将schemaLocation 添加到我的xml 文件时,我有一个非常奇怪的效果。
问题:
将
xsi:schemaLocation="Projekt.xsd"添加到我的xml 文件的根元素时,xslt 转换不再起作用。当我不指定 xsd 文件时,转换工作并显示数据,但只要我添加 xsd 文件,就不再显示任何数据。
- 我遗漏了什么,以便在将 xsd 文件添加到 schemaLocation 后仍能正确显示和转换数据?
信息: 所有文件都在同一个文件夹中
XML
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="Projekt.xsl"?>
<school xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="Projekt.xsd">
<personen>
<person id="1">
<name>A</name>
<kuerzel>a</kuerzel>
<email>a@a.ch</email>
</person>
<person id="2">
<name>B</name>
<kuerzel>b</kuerzel>
<email>b@b.ch</email>
</person>
<person id="3">
<name>C</name>
<kuerzel>C</kuerzel>
<email>c@c.ch</email>
</person>
</personen>
</school>
XSD
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="school">
<xs:complexType>
<xs:sequence>
<xs:element name="personen" maxOccurs="unbounded">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:sequence>
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="kuerzel" type="xs:string"/>
<xs:element name="email" type="xs:string"/>
</xs:sequence>
<xs:attribute name="id" type="xs:integer" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
XSLT
<?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>
<h2>School</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th style="text-align:left">Name</th>
<th style="text-align:left">Kürzel</th>
<th style="text-align:left">Email</th>
<th style="text-align:left">Image</th>
</tr>
<xsl:for-each select="school/personen/person">
<tr>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="kuerzel"/></td>
<td><a href="mailto:{email}"><xsl:value-of select="email" /></a></td>
<td><img src="http://tempUri.com/{kuerzel}.jpg" width="100px" height="100px"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
有人知道我的文件有什么问题吗?
【问题讨论】:
标签: xml xslt xsd xsd-validation