<element> <bye>do not delete me</bye> <hello>do not delete me</hello> <hello>delete me</hello> <hello>delete me</hello> </element> applied above xml, deletes nodes except first hello child of /element:
<xsl:template match="hello[not(current() = parent::element/hello[1])]" /> why these ones doesn't work? (assuming first node not text node)
<xsl:template match="hello[not(self::hello/position() = 1)]" /> <xsl:template match="hello[not(./position() = 1)]" /> or one?
<xsl:template match="hello[not(self::hello[1])]" /> what self axis selecting? why isn't last example equivalent not(hello[1])?
first, wrong when that:
this deletes nodes except first
hellochild of/element
the truth deletes (if that's correct word) hello child of /element value not same value of first 1 of these. example, given:
xml
<element> <hello>a</hello> <hello>b</hello> <hello>c</hello> <hello>a</hello> </element> the template:
<xsl:template match="hello[not(current() = parent::element/hello[1])]" /> will match second , third hello nodes - not first or fourth.
now, regard question: in xslt 1.0, position() not valid location step - this:
<xsl:template match="hello[not(self::hello/position() = 1)]" /> should return error.
in xslt 2.0, pattern hello[not(self::hello/position() = 1)] not match any hello element - because there 1 node on self axis, , therefore position 1.
similarly:
<xsl:template match="hello[not(./position() = 1)]" /> is invalid in xslt 1.0.
in xslt 2.0, ./position() return 1 same reason before: . short self::node() , there 1 such node.
finally, template:
<xsl:template match="hello[not(self::hello[1])]" /> is looking node doesn't have (the first instance of) itself. of course, no such node can exist.
Comments
Post a Comment