Re: [xsl] Node set

Subject: Re: [xsl] Node set
From: YueMa <may@xxxxxxxxxxxxxxxx>
Date: Tue, 06 Feb 2001 15:24:36 -0500
Well, got a good news that we decided to display elements by document

The problem was there is no certain "odd" and "even" rules there(or just I
can not find it), means I can not predict
the position of next node, we have  the XML file just like my sample one,
and then we have
to display those nodes by certain order based on "logic".
If I have the order in XML  file like:

The order we should display MAY be:
title1,title3,title2(on the left column)
title5,title4(on the right column)
again, any title element may not be in the XML file, means if I don't find
title3, I should display:
title1,title2(on the left column)
title5,title4(on the right column)

That was a pain to me....

I studied your solution, and I felt that I could use it in any other

Thanks for the help!

Jeni Tennison wrote:

> 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">
>    <tr>
>       <td><xsl:value-of select="." /></td>
>       <td><xsl:value-of select="following-sibling::title[1]" /></td>
>    </tr>
> </xsl:template>
> 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
> ---
> Jeni Tennison
>  XSL-List info and archive:

 XSL-List info and archive:

Current Thread