当标记包含编码字符时,通过XSL转换XML
更新:失败案例当标记包含编码字符时,通过XSL转换XML,xml,xslt,Xml,Xslt,更新:失败案例 <?xml version="1.0" encoding="ISO-8859-1"?> <catalog> <cd> <title>Empire & Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country>
<?xml version="1.0" encoding="ISO-8859-1"?>
<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>
帝国及;滑稽
鲍勃·迪伦
美国
哥伦比亚
10.90
1985
帝国与滑稽剧
鲍勃·迪伦
美国
哥伦比亚
10.90
1985
嗨,我有一个如下的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>
皇帝讽刺剧
鲍勃·迪伦
美国
哥伦比亚
10.90
1985
下面使用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>
我的CD收藏
标题
艺术家
到目前为止,翻译工作进展顺利。但是,如果我将XML标记值更改为包含编码字符,如&
或&代码>我没有得到结果
如何转义这些字符?您必须将&
更改为&代码>,应该可以正常工作。因为看起来你已经试过了。你可以试试&代码>和&
分别是对&
字符的十进制和十六进制unicode引用
<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
<cd>
<title>Empire & or & Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
</catalog>
帝国&;或&;滑稽
鲍勃·迪伦
美国
哥伦比亚
10.90
1985
如果这还不能解决问题,我可以知道使用哪个XSLT处理器生成输出吗?您能给我们展示一下实际失败的示例输入吗?并向我们展示它是如何失败的;在输入中,它应该与您创建的XSLT一起工作。帝国与滑稽剧鲍勃·迪伦美国哥伦比亚10.90 1985你可以编辑你的问题,而不是像这样把它贴在评论里。@Navin我试过这个:帝国与滑稽剧;滑稽剧鲍勃·迪伦美国哥伦比亚10.90 1985但它失败了不,这对我不起作用。我认为这是encoding=“ISO-8859-1”的问题,还是应该在XSL中处理?没有ISO-8859-1似乎可以,它在这里使用.Net MSXML 4.0可以正常工作。那么您使用的是哪个XSLT处理器呢?如果您不知道答案,请搜索处理器。我只是在尝试。在这种情况下,您遇到的问题是他们从
读取数据的方式有问题。如果您尝试任何其他编码字符,如“
它工作正常。他们正在将表单发布到结果页面,在这个过程中,必须对&
s和&代码>s。我认为发布表单时既要阅读一个&
,也要阅读一个&代码>作为&
输出到post数据中,这将导致无效的post数据,因为post数据中的&
表示新参数的开始。
<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
<cd>
<title>Empire & or & Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
</catalog>