0
我在XML下面我试图在一些输出文件将这一说HTML转换编码,XSLT
是否有可能转换到&
在&输出文件?
<Property>
<name>Document Title</name>
<value>Me & you</value>
</Property>
我在XML下面我试图在一些输出文件将这一说HTML转换编码,XSLT
是否有可能转换到&
在&输出文件?
<Property>
<name>Document Title</name>
<value>Me & you</value>
</Property>
正如你所标记的问题作为XSLT 2.0,如果你真的想在HTML输出转义符号&
那么你可以使用字符映射表:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:output method="html" use-character-maps="m1"/>
<xsl:character-map name="m1">
<xsl:output-character character="&" string="&"/>
</xsl:character-map>
<xsl:template match="/">
<html>
<body>
<p>This is a test of the encoding of the <code>&</code> character.</p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
输出是
<html>
<body>
<p>This is a test of the encoding of the <code>&</code> character.
</p>
</body>
</html>
但是,在XML中,与&符号通常会被转义为&
,因为某种原因,如果您的XSLT处理器在HTML输出中转义它,那么它通常会执行nting HTML语法规则。
你能解释一下这个问题到底是什么吗?在HTML中,与XML一样,&字符通常编码为'&',所以在HTML输出中的何处/为什么需要非转义的&符号? –