You'll find a worked example that includes a solution to this problem at
http://www.idealliance.org/proceedings/xml04/papers/111/mhk-paper.html
Michael Kay
http://www.saxonica.com/
-----Original Message-----
From: Jeff Hatch [mailto:hatchjk(_at_)ldschurch(_dot_)org]
Sent: 18 April 2007 16:44
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] 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.
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--