特殊字符不会在xslt变换上进行转换 [英] special characters are not transformed on xslt transformation

查看:395
本文介绍了特殊字符不会在xslt变换上进行转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在输入XML中有许多特殊字符参数,如& ndash; ,& mdash; ,& rsquo;

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

有一种方法,我可以用&#8211替换& ndash,其他类似的

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

我的xslt定义为

<?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"

我相信他们应该自动转换,参考dtd应该改变编码?

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

推荐答案

实体引用因为& ndash; 在XSLT处理器查看之前由XML解析器自动扩展;到XSLT处理器,它们被视为普通字符。如果所选的输出文件的编码包括这些字符,XML或HTML序列化程序将把它们输出为普通字符,否则序列化程序将输出它们作为字符引用(例如&#8211;

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.

这篇关于特殊字符不会在xslt变换上进行转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆