special characters are not transformed on xslt tra

2019-09-02 06:10发布

there are many special character parameters in the input XML like & ndash; , & mdash; , & rsquo;

is there a way i can replace them with &#8211 for &ndash and similarly for others

my xslt is defined as

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  xmlns="http://www.w3.org/1999/xhtml">
<xsl:output method="html" omit-xml-declaration="yes" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:param name="pDest" select="'XSLT_Transform/Output/'" />
<xsl:template match="CHAPTER">
    <xsl:variable name="token" select="tokenize(@ABC,'-')[last()]" />
    <xsl:variable name="chapVal" select="replace($token,'C','')" />
    <!--<xsl:variable name="chapVal" select="replace($val,'_','-')"/> -->
    <xsl:result-document href="{$pDest}chapter{$chapVal}.xhtml"

i believe they are supposed to transform automatically referring to the dtd should i change encoding?

1条回答
淡お忘
2楼-- · 2019-09-02 06:46

Entity references such as &ndash; are expanded automatically by the XML parser before the XSLT processor gets to see them; to the XSLT processor they are treated like ordinary characters. The XML or HTML serializer will output them as ordinary characters if the chosen encoding of the output file includes these characters, otherwise the serializer will output them as character references (for example &#8211;.

I hope this information helps. You haven't really said what your problem is, so all I can do is give background information.

查看更多
登录 后发表回答