[英]Special characters can't be displayed in XSL attribute?
I have an XSL template: 我有一个XSL模板:
<meta name="description" content="{$page-description}"/>
and a variable: 和一个变量:
<xsl:variable name="page-description">
<xsl:choose>
<xsl:when test="$current-page = 'home'">
<xsl:text>Lots of umlauts äöü</xsl:text>
</xsl:when>
<xsl:otherwise>
...
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
However, it seems that umlauts are not allowed in XLS attributes? 但是,似乎XLS属性中不允许变音符号吗?
Because instead of what I really want I am getting this: 因为我得到的不是我真正想要的:
Lots of umlauts äöü
How can this be fixed? 如何解决?
Can't repro this . 无法对此进行复制 。 The following transformation:
进行以下转换:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:variable name="vTest">Lots of umlauts äöü</xsl:variable>
<xsl:template match="/">
<meta name="description" content="{$vTest}"/>
</xsl:template>
</xsl:stylesheet>
when run with any of the following XSLT processors : MSXML3, MSXML4, MSXML6, Saxon 6.1.4, Saxon9.1.7, AltovaXML (XML-SPY), .NET XslCompiledTransform, .NET XslTransform, produces exactly the same output : 与以下任何XSLT处理器一起运行时 :MSXML3,MSXML4,MSXML6,Saxon 6.1.4,Saxon9.1.7,AltovaXML(XML-SPY)、. NET XslCompiledTransform,.NET XslTransform,将产生完全相同的输出 :
<meta name="description" content="Lots of umlauts äöü"/>
Possible solution : 可能的解决方案 :
In your <xsl:output>
instruction don't use any other value for the encoding
attribute except utf-8
. 在您的
<xsl:output>
指令中,除了utf-8
之外,不要对encoding
属性使用任何其他值。 Try with: <xsl:output encoding="utf-8"/>
尝试使用:
<xsl:output encoding="utf-8"/>
In case that additional serialization (XmlWriter, TextWriter, ..., etc.) of the result is used, make sure that the encoding specified for this additional serialization is utf-8
如果使用结果的附加序列化(XmlWriter,TextWriter等),请确保为此附加序列化指定的编码为
utf-8
Make sure that the tool that you are viewing the results with uses encoding utf-8
and its default font has proper representation for the special characters (for example, the font named Arial Unicode MS
has a proper representation for most unicode characters). 确保查看结果的工具使用
utf-8
编码,并且其默认字体对特殊字符具有正确的表示形式(例如,名为Arial Unicode MS
的字体对于大多数Unicode字符具有正确的表示形式)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.