This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Selection of every second node
- To: Conny Kreyßel <Conny dot Kreyssel at INTER-FORUM dot DE>
- Subject: Re: [xsl] Selection of every second node
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Tue, 21 Aug 2001 13:03:13 +0100
- CC: xsl-list at lists dot mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <C3AD14C7A9EED31188EB00104B0756FD167D9C@NT-EXCHANGE>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Conny,
> I hope you can help me. How can I make a template that match with
> every second node?
You need to test the position() of the node element amongst the other
node elements in its parent root element. Fortunately, this is what
the match pattern does by default. You can look at the position() mod
2 to find the even node elements - if it equals 0 then the node
element is an even node. So try:
<xsl:template match="node[(position() mod 2) = 0]">
...
</xsl:template>
or:
<xsl:template match="node[not(position() mod 2)]">
...
</xsl:template>
Alternatively, you could have a template that matched all node
elements, but only apply templates to every second node element, with:
<xsl:apply-templates select="node[not(position() mod 2)]" />
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list