也许您可以帮助我解决这个问题。我有一个带有XSL的XML文件,并附加了XSD。但是,我来自XSL的信息根本不会加载。仅当我将XML文件链接到DTD时,它才能起作用,而与XSL无关。你们能帮我吗?预先感谢。
这就是我的XML文件的样子。
<?xml version="1.0" standalone="yes"?>
<?xml-stylesheet type='text/xsl' href='wishlist.xsl'?>
<coins
xmlns="https://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://student.mccinfo.net/~armatsumura/wishlist.xsd">>
<wish_list>
<coin_id>SGB123</coin_id>
<issue_date>hi</issue_date>
<category>American</category>
<type>Antique</type>
<value>$2000</value>
</wish_list>
</coins>
这是我的XSD文件
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://student.mccinfo.net/~armatsumura/wishlist.xsd"
xmlns="http://student.mccinfo.net/~armatsumura/wishlist.xsd"
elementFormDefault="qualified">
<xs:element name="coins">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" ref="wish_list"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="wish_list">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element ref="coin_id"/>
<xs:element ref="issue_date"/>
<xs:element ref="category"/>
<xs:element ref="type"/>
<xs:element ref="value"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="coin_id" type="xs:string"/>
<xs:element name="issue_date" type="xs:string"/>
<xs:element name="category" type="xs:string"/>
<xs:element name="type" type="xs:string"/>
<xs:element name="value" type="xs:string"/>
</xs:schema>
这是我的XSLT
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>Wishlist</title>
<link rel="stylesheet" href="coins.css"/>
</head>
<body>
<ul>
<li><a href="http://student.mccinfo.net/~armatsumura/home.htm">Home</a></li>
<li><a href="http://student.mccinfo.net/~armatsumura/inventory.xml">Inventory</a></li>
<li><a href="http://student.mccinfo.net/~armatsumura/wishlist.xml">Wishlist</a></li>
<li><a href="http://student.mccinfo.net/~armatsumura/insurance.xml">Insurance</a></li>
<li><a href="http://student.mccinfo.net/~armatsumura/vendor.xml">Vendors</a></li>
<li><a href="mailto:armatsumura@mail.mccneb.edu">armatsumura.mail@mccneb.edu</a></li>
</ul>
<center><h2>Wishlist</h2></center>
<center><table border="1">
<tr bgcolor="#ffffff">
<th style="text-align:center">Coin ID</th>
<th style="text-align:center">Issue Date</th>
<th style="text-align:center">Category</th>
<th style="text-align:center">Type</th>
<th style="text-align:center">Value</th>
</tr>
<xsl:for-each select="coins/wish_list">
<tr>
<td><xsl:value-of select="coin_id"/></td>
<td><xsl:value-of select="issue_date"/></td>
<td><xsl:value-of select="category"/></td>
<td><xsl:value-of select="type"/></td>
<td><xsl:value-of select="value"/></td>
</tr>
</xsl:for-each>
</table></center>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
几件事..
如果您在浏览器(例如firefox)中测试此问题,则您的XML需要符合XPATH 1.0规格。您可以在此处阅读有关此信息:哪些浏览器支持XPath 2.0?
根据您的声明上方的链接,应该看起来像这样,请注意更改对第一个名称空间的更改,现在是XMLNS:CS。这将提供名称空间前缀。另外,您有一个额外的'>',可能要删除它:)
<coins
xmlns:cs="https://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://student.mccinfo.net/~armatsumura/wishlist.xsd">
然后,在XSLT中,您可以添加"前缀"名称空间,以使XSLT看起来像这样,再次注意到前缀名称空间的新行
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:cs="https://www.w3schools.com">
接下来,根选择器应为/*,因此它将选择所有内容,也可以用根的名称替换/*,但这是个人喜好类型。
<xsl:template match="/*">
最后,我认为XSD与此问题无关,XSD用于验证XML文件的"正确性",是否包含所需元素,是否正确的数据类型是正确的?但是我在XSL定义中看不到类似的东西。
让我知道这是否有帮助。