簡體   English   中英

XML文件僅顯示DTD而不是XSLT的數據

[英]XML file only shows data with DTD not XSLT

也許您可以幫我解決這個問題。 我有一個帶有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規范。 您可以在此處閱讀有關內容: 哪些瀏覽器支持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定義中看不到任何類似信息。

讓我知道是否有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM