开发者

Special characters can't be displayed in XSL attribute?

I have an XSL template:

    <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&开发者_如何学JAVAgt;
           ...
            </xsl:otherwise>
     </xsl:choose>
</xsl:variable>

However, it seems that umlauts are not allowed in XLS attributes?

Because instead of what I really want I am getting this:

Lots of umlauts &#xE4;&#xF6;&#xFC;

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:

<meta name="description" content="Lots of umlauts äöü"/>

Possible solution:

  1. In your <xsl:output> instruction don't use any other value for the encoding attribute except utf-8. Try with: <xsl:output encoding="utf-8"/>

  2. 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

  3. 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).


Turned out this issue was related to the content management system I was using, i.e. Symphony (thoroughly recommended by the way!).

I solved it by changing my output method from xml to html.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜