xsl-list
[Top] [All Lists]

Re: [xsl] mod position() tests positive all of the time

2006-12-30 06:42:24
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() &lt; 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(_dot_)Graham(_at_)MenteithConsulting(_dot_)com
Menteith Consulting Ltd              http://www.menteithconsulting.com
13 Kelly's Bay Beach
Skerries, Co. Dublin, Ireland
======================================================================

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--