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

Grouping a List into A Grid Structure

Subject: Grouping a List into A Grid Structure
From: Jeff Sese <jeferson.sese@xxxxxxxxxxxx>
Date: Mon, 23 Jun 2008 11:20:31 +0800
 Grouping a List into A Grid Structure
Hi,

I have this XML:

<root>
	<list>
		<item type="a">list 1 item 1</item>
		<item type="b">list 1 item 2</item>
	</list>
	<list>
		<item type="a">list 2 item 1</item>
		<item type="b">list 2 item 2</item>
		<item type="b">list 2 item 3</item>
		<item type="b">list 2 item 4</item>
	</list>
	<list>
		<item type="a">list 3 item 1</item>
		<item type="b">list 3 item 2</item>
		<item type="b">list 3 item 3</item>
	</list>
</root>

But I want to have this:

<root>
	<list>
		<item type="a">list 1 item 1</item>
		<item type="a">list 2 item 1</item>
		<item type="a">list 3 item 1</item>
		<item type="b">list 1 item 2</item>
		<item/>
		<item/>
		<item/>
		<item type="b">list 2 item 2</item>
		<item type="b">list 3 item 2</item>
		<item/>
		<item type="b">list 2 item 3</item>
		<item type="b">list 3 item 3</item>
		<item/>
		<item type="b">list 2 item 4</item>
		<item/>
	</list>
</root>

I manage to group the items into their corresponding type using for each group. The problem is how can i group the b items according to their position with respect to the list (all first item goes together, all second item goes together, etc.).

This is what i have so far:

<xsl:template match="root">
	<xsl:for-each-group select="list/item" group-by="@type">
		<xsl:choose>
			<xsl:when test="current-grouping-key()='a'">
				<xsl:copy-of select="current-group()"/>
			</xsl:when>
			<xsl:otherwise>
				<!-- grouping logic here -->
			</xsl:otherwise>
		</xsl:choose>
	</xsl:for-each-group>
</xsl:template>

Thanks in advance,
-- Jeff

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.