在XSLT 1.0,什么是处理此xml元素XSLT解析字符串与两个转义和非转义字符(<和<)
<Product>This is a product. < and its price is < 10</Product>
注意,“小于符号”表示的最佳方式两次。即作为'<' and '<'.
逃脱<
角色,我能做到这一点
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" method="html" indent="yes" />
<xsl:template match="/">
<html>
<body>
<table border="1">
<tr>
<th>Product</th>
</tr>
<tr>
<td><xsl:value-of select="Product" disable-output-escaping="yes" /></td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
- 如果设置了禁用输出转义为“是”,
<
字符显示正确,但"<"
被完全去掉了。 - 如果我将disable-output-escaping设置为“no”,
<
字符会导致解析异常。
我该怎么做才能让两者兼容?
只有魔法,而不是白色。请只使用格式正确的XML。 – kan 2013-03-06 21:34:27
@kan在说什么,是<?>不是XML中的有效文本内容。 – 2013-03-06 21:35:21
该XML无效(或者甚至是格式良好)。 XML *要求*在被解析的字符数据中以'<'(或者''或者'<'或者其他)的形式转义。 (与某些SGML应用程序不同,XML没有任何纯字符数据内容元素的概念。) – ruakh 2013-03-06 21:35:47