0

我收到警告

模糊规则匹配

来自模板copyReference身份转换的处理器。

<xsl:template name="processChildNodes">
    <xsl:param name="El"/>

    <xsl:for-each select="$El/node()">
        <xsl:choose>
            <xsl:when test="@sameas">
                <xsl:apply-templates mode="copyReference" select="id(substring-after(@sameas, '#'))"/>
            </xsl:when>         
            <xsl:otherwise>
                <xsl:copy-of select="." />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:for-each>
</xsl:template>


<xsl:template match="*" mode="copyReference" name="copyReference">
    <xsl:copy>
        <xsl:apply-templates select="@* except (@stem.dir, @stem.sameas)"/>
    </xsl:copy>
</xsl:template>



<xsl:template match="node() | @*" mode="#all">
        <xsl:copy>
            <xsl:apply-templates select="node() | @*"/>
        </xsl:copy>
    </xsl:template>

这是一个 xml 片段:

<layer>         
        <note oct="3" pname="b" stem.dir="up" stem.sameas="#note_17544b" xml:id="note_17544"/>          
</layer>
<layer>
    <note oct="4" pname="d" xml:id="note_17592"/>
    <note sameas="#note_17544" xml:id="note_17544b"/>   
</layer>

我想要做的只是复制从@sameas-attribute 引用的节点,而没有@stem.dir 和@stem.sameas。可能有不同的节点 local-names() 将应用于。所以我宁愿不在copyReference模板的@match-attribute 中指定节点名称。我想如果我通过@select-attribute 传递我需要的节点并添加@mode,它将只匹配我需要的。实际上它有效,但是当我收到警告时,应该是错误的。

4

1 回答 1

1

node()是简写*|text()|comment()|processing-instruction(),所以因为标识模板上面有mode="#all",所以当使用“copyReference”模式时,它将匹配与“copyReference”模板具有相同优先级的任何元素。

解决方案取决于您的样式表还做了什么,但有很多可能性

  1. 从标识模板中删除mode="#all"(这仅在 XSLT 中没有其他模式时才有效)
  2. 添加priority="2"到您的“copyReference”模板中,这样当使用“copyReference”模式时,您的特定模板将获得优先权。
  3. 改为代替并取消模板匹配<xsl:apply-templates mode="copyReference"...xsl:for-each
  4. 更改“copyReference”模板以显式匹配“note”而不是“*”,因为这会给它更高的优先级(但这显然假设您只需要匹配note元素)
于 2019-10-11T08:55:11.497 回答