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

Sorting in A for-each-group

Subject: Sorting in A for-each-group
From: Jeff Sese <jsese@xxxxxxxxxxxx>
Date: Wed, 20 Jun 2007 20:14:19 +0800
 Sorting in A for-each-group
Hi,

I'm doing a merge and sort transformation against a number of xml files and using for-each-group to group common structures together:

<!-- $path is the path to the folder that contains the XML files -->
<xsl:variable name="docs" as="node()*" select="collection(concat($path, '?select=*.xml'))"/>
<xsl:variable name="divs" as="node()*" select="$docs//TEI.2/text/body/div"/>
<xsl:for-each-group select="$divs" group-by="@id">
<div type="{current-grouping-key()}" id="{current-group()[1]/@id}">
<xsl:apply-templates select="current-group()[1]/head"/>
<xsl:for-each-group select="current-group()/node()" group-by="@id">
<div type="{current-group()[1]/@type}" id="{current-grouping-key()}" n="{current-group()[1]/@n}">
<!-- I want to insert a xsl:sort here so that i can sort the current-group() according to the @n -->
<xsl:apply-templates select="current-group()[1]/head"/>
<xsl:for-each-group select="current-group()/div" group-by="@n">
<div type="{current-group()[1]/@type}" id="{current-group()[1]/@id}" n="{current-grouping-key()}">
<xsl:apply-templates select="current-group()[1]/head"/>
<xsl:apply-templates select="div"/>
</div>
</xsl:for-each-group>
</div>
</xsl:for-each-group>
</div>
</xsl:for-each-group>


currently i'm getting:

<div type="edition_title" id="PLBAT">
<head><hi rend="b">Some text</hi></head>
<div type="papyrus_number" id="PLBAT1" n="1">
<head><hi rend="b">1</hi></head>
<!-- this is from file1.xml-->
<div type="nr" id="PLBAT1_10" n="10">
<head><hi rend="b">10</hi></head>
<div type="zeile" id="PLBAT1_10_-" n="-">
<head>-</head>
<div type="entry" id="PLBAT1_10_-_BL5" n="10" part="-" vol="BL5" lang="ger" page="59">
<p>Some Text</p>
</div>
</div>
</div>
<!-- this is from file1.xml-->
<div type="nr" id="PLBAT1_14" n="14">
<head><hi rend="b">14</hi></head>
<div type="zeile" id="PLBAT1_14_11-12" n="11-12">
<head>11-12</head>
<div type="entry" id="PLBAT1_14_11-12_BL5" n="14" part="11-12" vol="BL5" lang="ger" page="59">
<p>Sone text</p>
</div>
</div>
</div>
<!-- this is from file3.xml but i want it to be first because it @n is lesser than the ones above it-->
<div type="nr" id="PLBAT1_3" n="3">
<head><hi rend="b">3</hi></head>
<div type="zeile" id="PLBAT1_10_-" n="-">
<head>-</head>
<div type="entry" id="PLBAT1_10_-_BL5" n="10" part="-" vol="BL5" lang="ger" page="59">
<p>Some Text</p>
</div>
</div>
</div>
<!-- this is from file3.xml but i want it to be first because it @n is lesser than the ones above it-->
<div type="nr" id="PLBAT1_9" n="9">
<head><hi rend="b">9</hi></head>
<div type="zeile" id="PLBAT1_14_11-12" n="11-12">
<head>11-12</head>
<div type="entry" id="PLBAT1_14_11-12_BL5" n="14" part="11-12" vol="BL5" lang="ger" page="59">
<p>Sone text</p>
</div>
</div>
</div>
</div>
<div type="papyrus_number" id="PLBAT2" n="2">
<head><hi rend="b">2</hi></head>
<!-- this is from file2.xml-->
<div type="nr" id="PLBAT2_7" n="7">
<head><hi rend="b">7</hi></head>
<div type="zeile" id="PLBAT2_7_-" n="-">
<head>-</head>
<div type="entry" id="PLBAT2_7_-_BL5" n="7" part="-" vol="BL5" lang="ger" page="59">
<p>Some text</p>
</div>
</div>
</div>
<!-- this is from file2.xml-->
<div type="nr" id="PLBAT2_14" n="14">
<head><hi rend="b">14</hi></head>
<div type="zeile" id="PLBAT2_14_5" n="5">
<head>5</head>
<div type="entry" id="PLBAT2_14_5_BL5" n="14" part="5" vol="BL5" lang="ger" page="59">
<p>Some text</p>
</div>
</div>
</div>
</div>
<div type="papyrus_number" id="PLBAT6" n="6">
<head><hi rend="b">6</hi></head>
<!-- this is from file1.xml-->
<div type="nr" id="PLBAT6_9" n="9">
<head><hi rend="b">9</hi></head>
<div type="zeile" id="PLBAT6_9_24" n="24">
<head>24</head>
<div type="entry" id="PLBAT6_9_24_BL5" n="9" part="24" vol="BL5" lang="ger" page="60">
<p>Some text</p>
</div>
</div>
</div>
<!-- this is from file1.xml-->
<div type="nr" id="PLBAT6_11" n="11">
<head><hi rend="b">11</hi></head>
<div type="zeile" id="PLBAT6_11_1-3" n="1-3">
<head>1-3</head>
<div type="entry" id="PLBAT6_11_1-3_BL5" n="11" part="1-3" vol="BL5" lang="ger" page="60">
<p>Some text</p>
</div>
</div>
</div>
<!-- this is from file1.xml-->
<div type="nr" id="PLBAT6_13" n="13">
<head><hi rend="b">13</hi></head>
<div type="zeile" id="PLBAT6_13_15-16" n="15-16">
<head>15-16</head>
<div type="entry" id="PLBAT6_13_15-16_BL5" n="13" part="15-16" vol="BL5" lang="ger" page="60">
<p>Some text</p>
</div>
</div>
<div type="zeile" id="PLBAT6_13_56" n="56">
<head>56</head>
<div type="entry" id="PLBAT6_13_56_BL5" n="13" part="56" vol="BL5" lang="ger" page="60">
<p>Some text</p>
</div>
</div>
</div>
<!-- this is from file1.xml-->
<div type="nr" id="PLBAT6_21" n="21">
<head><hi rend="b">21</hi></head>
<div type="zeile" id="PLBAT6_21_8" n="8">
<head>8</head>
<div type="entry" id="PLBAT6_21_8_BL5" n="21" part="8" vol="BL5" lang="ger" page="60">
<p>Some text</p>
</div>
</div>
</div>
</div>
</div>


I'm trying to use: <xsl:sort select="current-group()[1]/@n"/> after the for-each-group but i cannot get a sorted output.

How can i get a sorted output?

--
*Jeferson L. Sese*
Asiatype Incorporated
Suite 114, Columbia Tower, Ortigas Ave.,
Greenhills, Mandaluyong City 1550 Philippines

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.