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

Re: Node set

Subject: Re: Node set
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Tue, 6 Feb 2001 10:09:08 +0000
Re:  Node set
Hi Yue,

> The reason I asked about ordered node set was that I have to group
> those title elements in the sample XML... (Now I'm clearly
> understand thata node set is not ordered.... ;-)) Say I may have 8
> or 10 title elements and finally, I'm going to display them within
> an HTML table, 4 on the left and 4 on the right column....without
> specific ordering, it's easy. And the bad news is the rule used to
> grouping them is "logic", so looks like nothing I can follow.... and
> as I said, the total number of title element is not guaranteed, if
> 4th element was missing, I have to move the 5th element to the left
> column! ;(

There's an XSLT solution to this kind of 'grouping by position'.  You
pick out the 'odd' title elements, apply templates to them, and get
them to output a row containing themselves and their 'even' partner
(if there is one).

Picking out the odd titles involves looking at their position() and
doing a calculation on it - if you do position() mod 2, you'll get 1
for odd items and 0 for even items - so you can pick out your odd
title elements with:

  <xsl:apply-templates select="title[position() mod 2 = 1]" />

Now have a template that matches title elements (it'll only be applied
to the odd ones) and outputs a row containing themselves and their
immediately following title element:

<xsl:template match="title">
      <td><xsl:value-of select="." /></td>
      <td><xsl:value-of select="following-sibling::title[1]" /></td>

This might not do precisely what you want it to do, but the
principle's there.  If you give a better sample of what your source
XML looks like (and what you want the table to look like in the end)
then we can probably give a more specific solution if you need it.

I hope that helps,


Jeni Tennison

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread
  • Node set
    • YueMa - Mon, 5 Feb 2001 11:45:24 -0500 (EST)
      • David Carlisle - Mon, 5 Feb 2001 12:05:10 -0500 (EST)
      • Jeni Tennison - Mon, 5 Feb 2001 13:50:45 -0500 (EST)
        • YueMa - Mon, 5 Feb 2001 15:57:30 -0500 (EST)
          • Jeni Tennison - Tue, 6 Feb 2001 05:14:12 -0500 (EST) <=
          • YueMa - Tue, 6 Feb 2001 15:25:59 -0500 (EST)
          • Jeni Tennison - Wed, 7 Feb 2001 05:10:13 -0500 (EST)


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.
First Name
Last Name
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.