如何强制XSLT将字符转义为数字格式(&160;)而不是名称格式()?

如何强制XSLT将字符转义为数字格式(&160;)而不是名称格式()?,xslt,character-encoding,docbook,Xslt,Character Encoding,Docbook,我正在使用DocBookXSL处理XML文件并生成HTML和XML输出文件。这些文件将用于Eclipse RCP应用程序中的联机帮助 标准XSL不会生成启用F1上下文帮助所需的contexts.xml文件,因此我使用了在线找到的XSL 在我将德语umlauts添加到源文本之前,这一切都很正常。这些字符被转换为命名实体,如ä;和ß;。这会导致输出的XML中出现错误,因为找不到这些实体 有没有办法告诉XSL处理器使用编号的实体,例如&223 我可以对输出文件执行搜索和替换,但这似乎

我正在使用DocBookXSL处理XML文件并生成HTML和XML输出文件。这些文件将用于Eclipse RCP应用程序中的联机帮助

标准XSL不会生成启用F1上下文帮助所需的contexts.xml文件,因此我使用了在线找到的XSL

在我将德语umlauts添加到源文本之前,这一切都很正常。这些字符被转换为命名实体,如ä;和ß;。这会导致输出的XML中出现错误,因为找不到这些实体

有没有办法告诉XSL处理器使用编号的实体,例如&223

我可以对输出文件执行搜索和替换,但这似乎有点笨拙

顶级XSL:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:ng="http://docbook.org/docbook-ng" xmlns:db="http://docbook.org/ns/docbook"
        xmlns:exsl="http://exslt.org/common" version="1.0"
        exclude-result-prefixes="exsl db ng">

        <!-- make sure the path to the standard eclipse.xsl is correct -->
        <xsl:import href="docbook-xsl-1.78.1/eclipse/eclipse3.xsl" />


        <xsl:param name="manifest">
            1
        </xsl:param>
        <xsl:param name="create.plugin.xml">
            1
        </xsl:param>
        <xsl:param name="create.context.xml">
            1
        </xsl:param>
        <xsl:param name="context.constants.package">
            org.example.help
        </xsl:param>

        <xsl:template name="plugin.xml">
            <xsl:if test="$create.context.xml = '1'">
                <xsl:call-template name="context.xml" />
                <xsl:call-template name="contextconstants">
                    <xsl:with-param name="package">
                        <xsl:value-of select="$context.constants.package" />
                    </xsl:with-param>
                </xsl:call-template>
            </xsl:if>

            <xsl:if test="$create.plugin.xml = '1'">
                <xsl:call-template name="write.chunk">
                    <xsl:with-param name="filename">
                        <xsl:if test="$manifest.in.base.dir != 0">
                            <xsl:value-of select="$base.dir" />
                        </xsl:if>
                        <xsl:value-of select="'plugin.xml'" />
                    </xsl:with-param>
                    <xsl:with-param name="method" select="'xml'" />
                    <xsl:with-param name="encoding" select="'utf-8'" />
                    <xsl:with-param name="indent" select="'yes'" />
                    <xsl:with-param name="content">
                        <xsl:choose>
                            <xsl:when test="$manifest = '1'">
                                <plugin>
                                    <extension point="org.eclipse.help.toc">
                                        <toc file="toc.xml" primary="true" />
                                    </extension>
                                    <extension point="org.eclipse.help.contexts">
                                        <contexts file="contexts.xml"></contexts>
                                    </extension>
                                </plugin>
                            </xsl:when>
                            <xsl:otherwise>
                                <plugin name="{$eclipse.plugin.name}" id="{$eclipse.plugin.id}"
                                    version="1.0" provider-name="{$eclipse.plugin.provider}">
                                    <extension point="org.eclipse.help.toc">
                                        <toc file="toc.xml" primary="true" />
                                    </extension>
                                </plugin>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:with-param>
                </xsl:call-template>
            </xsl:if>
        </xsl:template>


        <xsl:template name="context.xml">
            <xsl:call-template name="write.chunk">
                <xsl:with-param name="filename" select="'contexts.xml'" />
                <xsl:with-param name="method" select="'xml'" />
                <xsl:with-param name="encoding" select="'utf-8'" />
                <xsl:with-param name="indent" select="'yes'" />
                <xsl:with-param name="quiet" select="$chunk.quietly" />
                <xsl:with-param name="content">
                    <contexts>
                        <xsl:apply-templates select="/*" mode="context.xml" />
                    </contexts>
                </xsl:with-param>
            </xsl:call-template>
        </xsl:template>


        <xsl:template
            match="book|part|reference|preface|chapter|bibliography|appendix|article|glossary|section|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv|index"
            mode="context.xml">
            <xsl:variable name="title">
                <xsl:if test="$eclipse.autolabel=1">
                    <xsl:variable name="label.markup">
                        <xsl:apply-templates select="." mode="label.markup" />
                    </xsl:variable>
                    <xsl:if test="normalize-space($label.markup)">
                        <xsl:value-of select="concat($label.markup,$autotoc.label.separator)" />
                    </xsl:if>
                </xsl:if>
                <xsl:apply-templates select="." mode="title.markup" />
            </xsl:variable>

            <xsl:variable name="href">
                <xsl:call-template name="href.target.with.base.dir">
                    <xsl:with-param name="context" select="/" />
                </xsl:call-template>
            </xsl:variable>

            <!-- <xsl:message>Node=<xsl:value-of select="name(.)"></xsl:value-of>, 
                ID=<xsl:call-template name="object.id"> <xsl:with-param name="object" select="."/> 
                </xsl:call-template></xsl:message> -->

            <xsl:call-template name="acontext">
                <xsl:with-param name="id">
                    <xsl:call-template name="object.id">
                        <xsl:with-param name="object" select="." />
                    </xsl:call-template>
                </xsl:with-param>
                <xsl:with-param name="label" select="$title" />
                <xsl:with-param name="href" select="$href" />
            </xsl:call-template>
            <xsl:apply-templates
                select="part|reference|preface|chapter|bibliography|appendix|article|glossary|section|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv|index"
                mode="context.xml" />
        </xsl:template>

        <xsl:template name="acontext">
            <xsl:param name="id" />
            <xsl:param name="label" />
            <xsl:param name="href" />
            <xsl:message><xsl:value-of select="$id"/>, <xsl:value-of select="$href"/>
            </xsl:message>
            <context id="{normalize-space($id)}" title="">
                <description />
                <topic href="{$href}" label="{normalize-space($label)}" />
            </context>
        </xsl:template>


        <xsl:template name="contextconstants">
            <xsl:param name="package" />
            <xsl:call-template name="write.chunk">
                <xsl:with-param name="filename" select="'ContextConstants.java'" />
                <xsl:with-param name="method" select="'java'" />
                <xsl:with-param name="encoding" select="'utf-8'" />
                <xsl:with-param name="indent" select="'yes'" />
                <xsl:with-param name="quiet" select="$chunk.quietly" />
                <xsl:with-param name="content">
                    package
                    <xsl:value-of select="$package" />
                    ;
                    public class ContextConstants{
                    <xsl:apply-templates select="/*" mode="contextconstants" />
                    }
                </xsl:with-param>
            </xsl:call-template>
        </xsl:template>

        <xsl:template
            match="book|part|reference|preface|chapter|bibliography|appendix|article|glossary|section|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv|index"
            mode="contextconstants">
            <xsl:variable name="title">
                <xsl:if test="$eclipse.autolabel=1">
                    <xsl:variable name="label.markup">
                        <xsl:apply-templates select="." mode="label.markup" />
                    </xsl:variable>
                    <xsl:if test="normalize-space($label.markup)">
                        <xsl:value-of select="concat($label.markup,$autotoc.label.separator)" />
                    </xsl:if>
                </xsl:if>
                <xsl:apply-templates select="." mode="title.markup" />
            </xsl:variable>

            <xsl:variable name="href">
                <xsl:call-template name="href.target.with.base.dir">
                    <xsl:with-param name="context" select="/" />
                </xsl:call-template>
            </xsl:variable>

            <xsl:call-template name="acontextconstant">
                <xsl:with-param name="id">
                    <xsl:call-template name="object.id">
                        <xsl:with-param name="object" select="." />
                    </xsl:call-template>
                </xsl:with-param>
                <xsl:with-param name="label" select="$title" />
                <xsl:with-param name="href" select="$href" />
            </xsl:call-template>
            <xsl:apply-templates
                select="part|reference|preface|chapter|bibliography|appendix|article|glossary|section|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv|index"
                mode="contextconstants" />
        </xsl:template>

        <xsl:template name="acontextconstant">
            <xsl:param name="id" />
            <xsl:param name="label" />
            <xsl:param name="href" />
            public static final String C_
            <xsl:value-of select="translate($id,'-','_')" />
            ="
            <xsl:value-of select="$id" />
            ";
        </xsl:template>
    </xsl:stylesheet>

如果您使用的是Saxon,那么您可以尝试Saxon:character representation:参见

需要萨克森体育或更高


然而,我对你的要求感到困惑。如果需要XML输出,请使用method=XML。在这种情况下,将不会生成标记。如果您想要一个标记,但不想要HTML字符引用,那么您似乎想要某种混合,我不知道为什么。也许method=xhtml能满足您的需要?

我在网上找到的一个XSL-您能提供一个链接,并编辑问题以包含此样式表的相关部分吗?如果我们不知道代码是什么样子,我们就无法调试代码。在我看来,XSLT被配置为生成HTML而不是XML输出,您能显示声明吗?@IanRoberts-done。XSL被添加到DOCBOOK XSL之上。该标准生成许多HTML文件,一个MANIFEST.MF和一个toc.xml。此XSL也会创建contexts.xml。如果要创建xml结果文档,但在输出中获取HTML实体引用,则听起来好像没有设置XSL:output method=xml,而是将其设置为XSL:output method=HTML。如果xsl:output未设置输出方法html,并且结果树的根元素在没有命名空间的情况下是html,则XSLT处理器也会使用输出方法html。因此,请确保您已经设置了。@MartinHonnen-尝试过,但是HTML文件根本没有设置其元编码