开发者

XPath expression to select all child elements that are not some specific element

Given the XML

<blockquote>
    <attribution>foo</attribution>
    <para&g开发者_高级运维t;bar</para>
</blockquote>

I have the XSL template

<xsl:template match="dbk:blockquote">
    <blockquote>
        <xsl:apply-templates select="*[not(dbk:attribution)]" />
        <xsl:apply-templates select="dbk:attribution" />
    </blockquote>
</xsl:template>

where the first apply-templates should select all child elements of the dbk:blockquote that are not of type dbk:attribution. (This is necessary to move attributions to the bottom.)

However, it in fact matches every node. Why?


You want to use the self axis:

<xsl:apply-templates select="*[not(self::dbk:attribution)]" />

This selects child elements that are not themselves a dbk:attribution element. Your version selects child elements that do not contain a dbk:attribution child.


I am no xpath expert. But I think this should work.

<xsl:template match="dbk:blockquote">
    <blockquote>
        <xsl:apply-templates select="*[local-name(.) != 'attribution']" />
        <xsl:apply-templates select="*[local-name(.) = 'attribution']" />
    </blockquote>
</xsl:template>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜