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

Re: Sorting in A for-each-group

Subject: Re: Sorting in A for-each-group
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 20 Jun 2007 14:00:34 +0100
Re:  Sorting in A for-each-group
> (i left out the top level elements and started  with the topmost div):
which meant the stylesheet as posted didn't select anything.

I suspect that your only problem is that 10 is sorting before 3 as it's
doing strings not numbers.
<xsl:sort data-type="number" select="@n"/>


I can't readthis xml by eye to really spot what is being sorted where
but i get:

<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs">
<xsl:strip-space elements="*"/>
<xsl:output indent="yes"/>
<xsl:template name="body">
<xsl:variable name="docs" as="node()*" select="document(('file1.xml','file2.xml'))"/>
<xsl:variable name="divs" as="node()*" 
select="$docs/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">
<xsl:sort data-type="number" select="@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>
</xsl:template>

<!-- indentity template here -->
<xsl:template match="*">
  <xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>




$ saxon8 -it body file.xsl
<?xml version="1.0" encoding="UTF-8"?>
<div type="PLBAT" 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>
      <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>
      <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 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>
      <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>
   </div>
</div>

________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. 
________________________________________________________________________

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.