Parsing XSLT:output&;引用;没有被解析
我正在尝试实现以下XML输出:Parsing XSLT:output&;引用;没有被解析,parsing,xslt,quotes,Parsing,Xslt,Quotes,我正在尝试实现以下XML输出: <Foo bar=""" /> 伊恩·罗伯茨(Ian Roberts)已经提出了一个非常好的观点,那就是它实际上并不重要。但如果您真的非常想这样做,那么在XSLT 2.0(而不是XSLT 1.0)中,您可以使用字符映射,如下所示: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:outp
<Foo bar=""" />
伊恩·罗伯茨(Ian Roberts)已经提出了一个非常好的观点,那就是它实际上并不重要。但如果您真的非常想这样做,那么在XSLT 2.0(而不是XSLT 1.0)中,您可以使用字符映射,如下所示:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" use-character-maps="quotes" />
<xsl:character-map name="quotes">
<xsl:output-character character=""" string="&quot;" />
</xsl:character-map>
<xsl:template match="/">
<xsl:variable name="quote">
<xsl:text>"</xsl:text>
</xsl:variable>
<Foo bar="{$quote}"/>
</xsl:template>
</xsl:stylesheet>
为什么这很重要?这两者是等价的(还有其他各种等价的方式来表达相同的内容,例如
),XML解析器不会告诉应用程序它是以何种方式在源代码中编写的,应用程序只会看到一个值为双引号字符的属性。你说得很好。我的目标是以一种特定的格式输出XML—以匹配Microsoft Excel似乎想要的格式,但您是对的,Excel正确解析文件,即使";使用。谢谢!
<Foo bar="""/>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" use-character-maps="quotes" />
<xsl:character-map name="quotes">
<xsl:output-character character=""" string="&quot;" />
</xsl:character-map>
<xsl:template match="/">
<xsl:variable name="quote">
<xsl:text>"</xsl:text>
</xsl:variable>
<Foo bar="{$quote}"/>
</xsl:template>
</xsl:stylesheet>