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

nested grouping problem using group-adjacent

Subject: nested grouping problem using group-adjacent
From: Jeff Hatch <hatchjk@xxxxxxxxxxxxx>
Date: Wed, 18 Apr 2007 09:44:00 -0600
 nested grouping problem using group-adjacent
All,

Having tried to code for this for the past several ... well, I won't admit how long ... I throw it to you for help and beg for mercy. If the solution exists in an archive or faq somewhere, and I've just missed it in my searches, please refer me to it.

Input xml:

<objects>
	<object depth="1">data</object>
	<object depth="1">data</object>
	<object depth="2">data</object>
	<object depth="2">data</object>
	<object depth="3">data</object>
	<object depth="3">data</object>
	<object depth="3">data</object>
	<object depth="2">data</object>
	<object depth="2">data</object>
	<object depth="1">data</object>
	<object depth="2">data</object>
	<object depth="1">data</object>
</objects>

Required output:

<objects>
	<group-1>
		<object depth="1">data</object>
		<object depth="1">data</object>
		<group-2>
			<object depth="2">data</object>
			<object depth="2">data</object>
			<group-3>
				<object depth="3">data</object>
				<object depth="3">data</object>
				<object depth="3">data</object>
			</group-3>
			<object depth="2">data</object>
			<object depth="2">data</object>
		</group-2>
		<object depth="1">data</object>
		<group-2>
			<object depth="2">data</object>
		</group-2>
		<object depth="1">data</object>
	</group-1>
</objects>

My futile attempt:

<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="objects">
<xsl:for-each-group select="*" group-adjacent="(@depth >= 1)">
<xsl:element name="group-1">
<xsl:for-each-group select="current-group()" group- adjacent="(@depth >= 2)">
<xsl:element name="group-2">
<xsl:for-each-group select="current-group()" group- adjacent="(@depth >= 3)">
<xsl:element name="group-3">
<xsl:apply-templates select="current-group()"/>
</xsl:element>
</xsl:for-each-group>
</xsl:element>
</xsl:for-each-group>
</xsl:element>
</xsl:for-each-group>
</xsl:template>


My attempt is producing the wrong output, in that (for example) the depth-1 elements are inappropriately being nested in group-2 and group-3 elements. I've done quite a bit of grouping work with xslt 2.0 for other applications, but for some reason this one escapes me.

The input example is a scaled-down structure that would represent flat lists in document-oriented xml that need to be up-translated for structure and depth nesting.

Thanks in advance for any help you could provide ...

Jeff Hatch
Electronic Media Group
Curriculum Department
Church of Jesus Christ of Latter-day Saints




---------------------------------------------------------------------- NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.

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-2011 All Rights Reserved.