我无法在 XMLSpy 中使用 Saxon 向元素添加特定属性

I cannot add a specific attribut to an element using Saxon in XMLSpy

我正在转换一个文档,试图为所有使用的元素提供模板,并用 "catch all others filter" 捕捉我可能错过的那些。这基本上按预期工作,我可以创建很多具有正确属性的元素,但我遇到了一个特殊属性的问题 - "valign"。其他一切都在提供的代码中工作。

我最初包含了所有应该复制到一个模板中的匹配项,但在这里我尝试将我的 xslt 匹配项拆分到不同的模板中,但我仍然得到相同的结果(这是预期的,但嘿,我有尝试...)。 当我使用 XMLSpy 调试器时,转换也有效。

来源xml 片段:

<?xml version="1.0" encoding="UTF-8"?>
    <content>
                <table tocentry="1">
                    <tgroup align="left" char="" charoff="50" cols="2">
                        <colspec colname="colspec0" colwidth="1*"/>
                        <colspec colname="colspec1" colwidth="1.5*"/>
                        <tbody valign="top">
                            <row>
                                <entry morerows="0" rotate="0" valign="top">
                                    <para>Volume washing fluid</para>
                                </entry>
                                <entry morerows="0" rotate="0" valign="top">
                                    <para>3 dm³</para>
                                </entry>
                            </row>
                        </tbody>
                    </tgroup>
                </table>
    </content>
</dmodule>

XSLT 2.0 片段:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" exclude-result-prefixes="fo xs fn">
<xsl:output encoding="utf-8" indent="yes" method="xml"/>


    <xsl:template match="@*|*">
        <xsl:comment>warning, node not handled by defined templates: "<xsl:copy-of select="local-name()"/>"</xsl:comment>
    </xsl:template>

    <xsl:template match="/content">
        <xsl:apply-templates/>
    </xsl:template>


<!--**************************************************-->
<!-- ************** Common                    ********-->
<!--**************************************************-->

    <xsl:template match="table | 
                            tgroup | 
                            tbody | 
                            colspec | 
                            row | 
                            entry | 
                            figure | 
                            para[not(parent::note or parent::warning or parent::caution or following-sibling::seqlist)] | 
                            legend | 
                            note | 
                            title | 
                            warning | 
                            caution | 
                            note
                            ">
    <xsl:copy>
        <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
    </xsl:template>

    <xsl:template match="@align |
                            @char |
                            @charoff |
                            @colname |
                            @cols |
                            @colwidth |
                            @id |
                            @morerows |
                            @tocentry |
                            @valign">
        <xsl:copy>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>

我希望它能作为恒等式转换。 我能解决这个问题的唯一方法是在找到 table 元素时使用 "copy-of"。

XMLSpy(使用 Saxon 设置)中的错误消息如下: basics_001.xsl 的第 146 行第 26 列评估 ((attr{xsi:noNamespaceSchemaLocation=...}, ...)) 时出错: XTDE0410:属性节点 (valign) 无法在包含的子节点之后创建 元素。最近的元素开始标记在模块 basics_001.xsl 的第 131 行输出 在 basics_001.xsl 的第 144 行带有 match="@valign" 的模板规则中 由 xsl:apply-templates at file:/C:/basics_001.xsl#131 调用 在 basics_001.xsl 的第 129 行带有 match="entry" 的模板规则中 由 xsl:apply-templates at ....

调用

我认为您将注释输出为其他地方不匹配的属性的子节点的方法是问题的根源;您将需要使用 xsl:message 来输出有关不匹配节点的信息。显然,如果 rotate 属性导致子注释输出,您不能指望之后能够输出任何属性节点(如 valign)。