xsl-list
[Top] [All Lists]

Re: [xsl] Sorting in A for-each-group

2007-06-20 05:35:03
Thanks, I tried that already but i cannot get it right.

Here's a sample input (i left out the top level elements and started with the topmost div):

file1.xml:
<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>
       <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>

file2.xml:
<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>
       <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>
</div>

so using a xsl like this:

<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:template name="body">
<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>
</xsl:template>

<!-- indentity template here -->
</xsl:stylesheet>

I should get:

<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>
      <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>

--
Jeff

David Carlisle wrote:
<xsl:variable name="divs" as="node()*" select="$docs//TEI.2/text/body/div"/>


I believe TEI.2 is always the topmost element of a TEI doc? but //
implies searching to arbitrary depth to find them all, your probably
just want / there.

<!-- 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">

seems like you want to add <xsl:sort select="@n"/> at this point

hard to check without any input though-)


________________________________________________________________________
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. ________________________________________________________________________

--~------------------------------------------------------------------
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>
--~--

<Prev in Thread] Current Thread [Next in Thread>