This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Using Position() to display results in groups
- To: "Andrew Welch" <andrew at thebristoldirectory dot com>
- Subject: Re: [xsl] Using Position() to display results in groups
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Mon, 20 Aug 2001 15:43:53 +0100
- CC: xsl-list at lists dot mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <POEMLHLHPPILCJKHBIAAAEKDCEAA.andrew@thebristoldirectory.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Andrew,
> Writing ten or so 'when' tests probably isnt the best way to go
> about this. What is required is some code to iterate through the
> list, decide if it as the 10th item ( or a multiple of 10) and
> output some code.
I think that you want to group a load of items into card elements by
position. I would select the first of each group of 10 to process (the
1st, 11th, 21st etc.), using the mod operator to select them:
<xsl:for-each select="item[position() mod 10 = 1]">
<card id="{position()}">
...
<a href="#{position() + 10}">next 10</a>
</card>
</xsl:for-each>
Within that xsl:for-each, to get the 10 items that should be displayed
on the card, you want this item and its following 9 siblings, e.g.:
<xsl:for-each select=".|following-sibling::item
[position() < 10]">
...
</xsl:for-each>
Actually, I'd be a bit wary of using numbers for IDs like that -- IDs
in XML should start with a letter, and you might have validity
and linking problems if you use something a number. You can just do:
<card id="card{position()}">
...
</card>
instead.
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list