[英]xslt transform an xsd validated xml
將schemaLocation
添加到我的xml文件時,我有一個非常奇怪的效果。
問題 :
將
xsi:schemaLocation="Projekt.xsd"
到我的xml文件的根元素時,xslt轉換不再起作用。 當我不指定xsd-File時,轉換有效並且顯示了數據,但是一旦添加xsd-File,就不再顯示任何數據。
信息: 所有文件都在同一文件夾中
<?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>
<?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>
<?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>
有人知道我的文件出了什么問題嗎?
schemaLocation
無關緊要,但是您的輸入示例在根元素上具有默認的名稱空間聲明xmlns="http://www.w3schools.com"
,該元素將所有元素放入該名稱空間。 但是,您的XSLT使用諸如school/personen/person
類的路徑(在XSLT / XPath 1.0中),該路徑在沒有名稱空間的情況下選擇元素。 轉移到XSLT 2.0處理器,然后可以在樣式表上定義xpath-default-namespace="http://www.w3schools.com"
,或者,如果要使用XSLT 1.0解決它,則聲明xmlns:df="http://www.w3schools.com"
樣式表中的xmlns:df="http://www.w3schools.com"
,並按照df:school/df:personen/df:person
和df:name
等方式修改路徑以使用該前綴。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.