2013-04-22 25 views
0

更新:失敗的情況下XML轉換時,標籤包含編碼字符

<?xml version="1.0" encoding="ISO-8859-1"?> 

<catalog> 
    <cd> 
     <title>Empire &amp; Burlesque</title> 
     <artist>Bob Dylan</artist> 
     <country>USA</country> 
     <company>Columbia</company> 
     <price>10.90</price> 
     <year>1985</year> 
    </cd> 
</catalog> 
<catalog> 
    <cd> 
     <title>Empire & Burlesque</title> 
     <artist>Bob Dylan</artist> 
     <country>USA</country> 
     <company>Columbia</company> 
     <price>10.90</price> 
     <year>1985</year> 
    </cd> 
</catalog> 

您好我有下面的XML

<catalog> 
    <cd> 
     <title>Empire Burlesque</title> 
     <artist>Bob Dylan</artist> 
     <country>USA</country> 
     <company>Columbia</company> 
     <price>10.90</price> 
     <year>1985</year> 
    </cd> 
</catalog> 

以下XSL翻譯上述

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

<xsl:template match="/"> 
    <html> 
    <body> 
    <h2>My CD Collection</h2> 
    <table border="1"> 
     <tr bgcolor="#9acd32"> 
     <th>Title</th> 
     <th>Artist</th> 
     </tr> 
     <xsl:for-each select="catalog/cd"> 
     <tr> 
     <td><xsl:value-of select="title"/></td> 
     <td><xsl:value-of select="artist"/></td> 
     </tr> 
     </xsl:for-each> 
    </table> 
    </body> 
    </html> 
</xsl:template> 
</xsl:stylesheet> 

現在翻譯好了。但是,如果我將XML標記值更改爲包含&或等編碼字符,則我無法獲得結果

如何避免這些字符?

+0

你能向我們展示實際失敗的樣本輸入嗎?並告訴我們究竟是如何失敗? – 2013-04-22 05:07:23

+0

如果您在輸入中有&,它應該與您創建的XSLT一起使用。 – 2013-04-22 05:11:22

+0

<?XML版本= 「1.0」 編碼= 「ISO-8859-1」?> \t \t \t 帝國&滑稽 \t \t 鮑勃迪倫 \t \t 美國 \t \t 哥倫比亞 \t \t 10.90 \t \t \t user778930 2013-04-22 05:12:16

回答

0

您必須將&更改爲&amp;,這應該可以正常工作。因爲它看起來像你已經試過這個。您可以嘗試使用&#38;&#x26;,它們分別是對&字符的十進制和十六進制unicode引用。

<?xml version="1.0" encoding="ISO-8859-1"?> 
<catalog> 
    <cd> 
    <title>Empire &#x26; or &#38; Burlesque</title> 
    <artist>Bob Dylan</artist> 
    <country>USA</country> 
    <company>Columbia</company> 
    <price>10.90</price> 
    <year>1985</year> 
    </cd> 
</catalog> 

如果這樣不能解決問題,我可否知道使用哪個XSLT處理器來產生輸出?

+0

不,這不是爲我工作。我這與編碼=「ISO-8859-1」的問題,或者我應該在XSL內處理它? – user778930 2013-04-22 05:28:22

+0

沒有ISO-8859-1似乎沒問題,在這裏使用.Net MSXML 4.0可以正常工作。那麼您使用哪種XSLT處理器?如果您不知道答案,請在本頁搜索處理器(http://en.wikipedia.org/wiki/XSLT)。 – 2013-04-22 05:31:43

+0

我只是想要http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog – user778930 2013-04-22 05:33:22

相關問題