也许你可以帮我解决这个问题。我有一个附有 xsl 和 xsd 的 xml 文件。但是,我的 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 规范。你可以在这里阅读:What browsers support 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 定义中没有看到类似的内容。
如果这有帮助,请告诉我。
关于html - XML 文件仅显示 DTD 而非 XSLT 的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54855450/