This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: grouping every three nodes?
- To: xsl-list at mulberrytech dot com
- Subject: RE: grouping every three nodes?
- From: Joel Hughes <joel at redknee dot com>
- Date: Wed, 23 Feb 2000 21:01:57 -0500
- Reply-To: xsl-list at mulberrytech dot com
Search on "Breaking up is hard to do"
There was quite a discussion on just this issue on the weekend.
Joel
joel@redknee.com
-----Original Message-----
From: Seth Ladd [mailto:shl6472@osfmail.isc.rit.edu]
Sent: Wednesday, February 23, 2000 7:42 PM
To: xsl-list@mulberrytech.com
Subject: grouping every three nodes?
Hello,
I've searched the FAQ and tutorials, and I can't seem to find an answer to
this problem. Actually, I don't think it's possible, but I was hoping
someone could lend some advise.
demo xml file:
<group>
<item></item>
<item></item>
<item></item>
<item></item>
<item></item>
</group>
I would love to be able to do this in XSL:
<xsl:template match="group">
"grab every three item tags and send to named template"
</xsl:template>
<xsl:template name="group-of-three">
<td>
<ul>
<xsl:for-each select="item">
<li><xsl:value-of select="."/></li>
</xsl:for-each>
</ul>
</td>
</xsl:template>
I'm not sure how to grab every three nodes from a nodeset. I'm trying to
build a table for every three items in a list. because of the fact that
XSL outputs trees, I'm having a hard time. The following would work,
except it's not valid XML
<!-- won't work -->
<xsl:template match="group">
<table>
<tr>
<xsl:for-each select="item">
<xsl:if test="(position() mod 3) = 0">
<td>
<ul>
</xsl:if
<xsl:value-of select="."/>
<xsl:if test="(position() mod 4) = 0">
</ul>
</td>
</xsl:if>
</xsl:for-each>
</tr>
</table>
</xsl:template>
Is there anything that will help me break up a nodeset into a group of
three? I've solved my problem by using the hack disable-output-encoding,
but I'd like to stay away from that.
Thanks for any help or pointers you can give me,
Seth
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list