Xml xsl:character映射/xsl:output字符不工作

Xml xsl:character映射/xsl:output字符不工作,xml,xslt,Xml,Xslt,我需要为我的应用程序使用字符转换。举个例子,我看了这本书,试着用这个例子(如果是这样的话,附录A->[2.0]一节) 以下是我的XML(摘自本书): 公共类HelloWorld{ 公共静态void main(字符串[]args){ System.out.println(“你好,世界!”); } } ➀; ➁; 以下是我的XSL(摘自本书): 一些特殊字符的测试 一些特殊字符的测试 这里有一个特殊的角色: 我不指望得到什么➀ 和➁ , 我希望能找到这些角色的替代

我需要为我的应用程序使用字符转换。举个例子,我看了这本书,试着用这个例子(如果是这样的话,附录A->
[2.0]
一节)

以下是我的XML(摘自本书):


公共类HelloWorld{
公共静态void main(字符串[]args){
System.out.println(“你好,世界!”);
}
}
➀;
➁;
以下是我的XSL(摘自本书):


一些特殊字符的测试
一些特殊字符的测试

这里有一个特殊的角色:

我不指望得到什么➀ 和➁ , 我希望能找到这些角色的替代品。我尝试使用上述XML和XSL

结果不是我所期望的:

<?xml version="1.0" encoding="UTF-8"?>
<html>
   <head>
      <title>A test of some special characters</title>
   </head>
   <body style="font-family: sans-serif;">
      <h1>A test of some special characters</h1>
      <pre style="font-size: 150%; font-weight: bold;">public class HelloWorld {
            public static void main(String[] args) {
                System.out.println("Hello, World!");
                }
            }</pre>
      <p style="font-size: 200%;">Here's a special character: ➀</p>
      <p style="font-size: 200%;">Here's a special character: ➁</p>
   </body>
</html>

一些特殊字符的测试
一些特殊字符的测试
公共类HelloWorld{
公共静态void main(字符串[]args){
System.out.println(“你好,世界!”);
}
}
这里有一个特殊的字符:➀

这里有一个特殊的字符:➁

特殊字符没有被替换。我很困惑,因为这些例子来自好书,而且我可以在网上看到同样的方法。
这里的魔力何在?

这向我表明,您正在测试的XSLT处理器是1.0版处理器,而不是2.0版-字符映射是2.0版的唯一特性


如果使用Saxon 9引擎,则支持2.0。

这向我建议,您正在测试的XSLT处理器是1.0版处理器,而不是2.0版-字符映射是仅2.0版的功能


如果您使用Saxon 9引擎,则支持2.0。

另一种解释症状的可能性是您使用的是XSLT 2.0处理器,但没有使用其序列化程序(例如,您正在向DOM树发送输出)。另一种解释症状的可能性是您使用的是XSLT 2.0处理器,但是没有使用它的序列化程序(例如,您正在向DOM树发送输出)
<?xml version="1.0" encoding="utf-8"?>
<!-- character-map1.xsl -->
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" use-character-maps="sample" />
    <xsl:character-map name="sample" use-character-maps="circles">
        <xsl:output-character character="&#x9;" string=" " />
    </xsl:character-map>
    <xsl:character-map name="circles">
        <xsl:output-character character="&#x2780;" string="&lt;img src='images/circle1.gif'
width='28' height='28'/&gt;" />
        <xsl:output-character character="&#x2781;" string="&lt;img src='images/circle2.gif'
width='28' height='28'/&gt;" />
    </xsl:character-map>
    <xsl:template match="char-test">
        <html>
            <head>
                <title>A test of some special characters</title>
            </head>
            <body style="font-family: sans-serif;">
                <h1>A test of some special characters</h1>
                <xsl:apply-templates select="*" />
            </body>
        </html>
    </xsl:template>
    <xsl:template match="tabs">
        <pre style="font-size: 150%; font-weight: bold;">
            <xsl:value-of select="." />
        </pre>
    </xsl:template>
    <xsl:template match="special-char">
        <p style="font-size: 200%;">
            <xsl:text>Here's a special character: </xsl:text>
            <xsl:value-of select="." />
        </p>
    </xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<html>
   <head>
      <title>A test of some special characters</title>
   </head>
   <body style="font-family: sans-serif;">
      <h1>A test of some special characters</h1>
      <pre style="font-size: 150%; font-weight: bold;">public class HelloWorld {
            public static void main(String[] args) {
                System.out.println("Hello, World!");
                }
            }</pre>
      <p style="font-size: 200%;">Here's a special character: ➀</p>
      <p style="font-size: 200%;">Here's a special character: ➁</p>
   </body>
</html>