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

RE: Newbie, question about looping

Subject: RE: Newbie, question about looping
From: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
Date: Wed, 23 Oct 2002 12:53:56 -0400
RE:  Newbie
[Erick Todd]

> Here is my problem.  I have an xml document of items.  And I 
> need to display these items in a table 3 across.
> 
> So every 3 I try to put in a </tr><tr> but that is invalid.  
> Has anyone had to try and do this??
> 

Xslt is mostly about selecting a set of nodes and then doing something
with them.  So you should try to find solutions that select the right
set of nodes, rather than think about looping through.  It is usually
more productive. 

You also have to think in terms of creating complete elements at a time,
not parts.

In this case, you want to select every third item, because those
elements will represent the start of each row.  For each item in that
set of nodes, you want to output it and its next two sibling items,
wrapped in <tr>..</tr> element.  Right?

Here is a simple way to do that, assuming that you have a series of
"item" elements like this:

<root>
   <item>1</item>
   <item>2</item>
   ...
</root>

=================================================
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding='iso-8859-1'/>

<xsl:template match="/root">
<results>
	<xsl:apply-templates select='item[position() mod 3 =0]'/>
</results>
</xsl:template>

<xsl:template match='item'>
<tr>
	<td><xsl:value-of select='.'/></td>
	<td><xsl:value-of select='following-sibling::item[1]'/></td>
	<td><xsl:value-of select='following-sibling::item[2]'/></td>
</tr>
</xsl:template>

</xsl:stylesheet>
====================================================================

Cheers,

Tom P

 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.