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

Re: Using Position() to display results in groups

Subject: Re: Using Position() to display results in groups
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Mon, 20 Aug 2001 15:43:53 +0100
xml using position
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() &lt; 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


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-2013 All Rights Reserved.