|
Subject: Re: [xsl] mod position() tests positive all of the time From: Tony Graham <Tony.Graham@xxxxxxxxxxxxxxxxxxxxxx> Date: Sat, 30 Dec 2006 13:44:10 +0000 |
On Sat, Dec 30 2006 12:06:32 +0000, Allen Jones wrote:
> I am new to the list, but I have checked the archive for this particular
> problem and I haven't been able to find a solution to this.
>
> I am using the following stylesheet and everytime it tests for position,
> the results always print the <tr> (rather than printing every 5th
> element). Since I am new to XSLT, I know it is probably in the code.
> Any help would be a lesson.
position() returns the context position within the current node list.
You don't show how many <thumbnail> are within each <object>, but the
context changes with each <object>, so the first <thumbnail> in each
<object> matches your predicate.
If you want to group <thumbnail> across multiple <object>, the simple,
brute-force, and slow way to group them is to change your xsl:for-each
and xsl:apply-templates to:
<xsl:for-each
select="(insightResponse/searchResponse/collectionResultSet/object/thumbnail)[position()
mod 5 = 1]">
<tr>
<xsl:apply-templates
select=". | following::thumbnail[position() < 5]" />
</tr>
</xsl:for-each>
or:
<xsl:for-each
select="insightResponse/searchResponse/collectionResultSet/object/thumbnail[count(preceding::thumbnail) mod 5 = 0]">
...
but if your data is large, you are probably better off to use keys.
Regards,
Tony Graham.
======================================================================
Tony Graham mailto:Tony.Graham@xxxxxxxxxxxxxxxxxxxxxx
Menteith Consulting Ltd http://www.menteithconsulting.com
13 Kelly's Bay Beach
Skerries, Co. Dublin, Ireland
======================================================================
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] mod position() tests posi, Abel Braaksma | Thread | RE: [xsl] mod position() tests posi, cknell |
| RE: [xsl] Managing cross references, Trevor Nicholls | Date | Re: [xsl] mod position() tests posi, Abel Braaksma |
| Month |