[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

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

Subject: Re: mod position() tests positive all of the time
From: Tony Graham <Tony.Graham@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 30 Dec 2006 13:44:10 +0000
kelly s bay beach skerries
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.Graham@xxxxxxxxxxxxxxxxxxxxxx
Menteith Consulting Ltd              http://www.menteithconsulting.com
13 Kelly's Bay Beach
Skerries, Co. Dublin, Ireland
======================================================================

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.