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>
精彩评论