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

grouping/sorting again

Subject: grouping/sorting again
From: Bruce D'Arcus <bdarcus@xxxxxxxxx>
Date: Fri, 29 Apr 2005 13:32:43 -0400
 grouping/sorting again
OK, I went back to the beginning and came up with the minmal example to test.

<?xml version="1.0" encoding="UTF-8"?>
<doc>
  <p><cite><ref href="1"/><ref href="2"/><ref href="4"/></cite></p>
  <p><cite><ref href="3"/><ref href="4"/><ref href="1"/></cite></p>
</doc>

Stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs" version="2.0">

  <xsl:output method="xml" indent="yes"/>

  <xsl:variable name="data">
    <biblist>
      <item id="1" author="one" year="1998"/>
      <item id="2" author="one" year="1998"/>
      <item id="3" author="two" year="2000"/>
      <item id="4" author="two" year="2001"/>
    </biblist>
  </xsl:variable>

  <xsl:template match="doc">
    <result>
      <xsl:apply-templates/>
    </result>
  </xsl:template>

  <xsl:template match="p">
    <para>
      <xsl:apply-templates/>
    </para>
  </xsl:template>

  <xsl:template match="cite">
    <xsl:variable name="citation" select="."/>
    <xsl:variable name="idref" select="ref/@href"/>
    <xsl:variable name="refs">
      <xsl:sequence select="$data/biblist/item[@id=$idref]"/>
    </xsl:variable>
    <xsl:variable name="temp-citation">
      <xsl:for-each-group select="$refs/item" group-by="@author">
        <xsl:for-each-group select="." group-adjacent="@year">
          <xsl:for-each select=".">
            <pos id="{@id}" author="{@author}">
              <xsl:value-of select="position()"/>
            </pos>
          </xsl:for-each>
        </xsl:for-each-group>
      </xsl:for-each-group>
    </xsl:variable>
    <citation>
      <ref>
        <raw>
          <xsl:copy-of select="$refs"/>
        </raw>
        <processed>
          <xsl:copy-of select="$temp-citation"/>
        </processed>
      </ref>
    </citation>
  </xsl:template>

</xsl:stylesheet>

Expected output:

<result>
     <para>
      <citation>
         <ref>
            <raw>
               <item id="1" author="one" year="1998"/>
               <item id="2" author="one" year="1998"/>
               <item id="4" author="two" year="2001"/>
            </raw>
            <processed>
               <pos id="1" author="one">1</pos>
               <pos id="2" author="one">2</pos>
               <pos id="4" author="two">1</pos>
            </processed>
         </ref>
      </citation>
   </para>
     <para>
      <citation>
         <ref>
            <raw>
               <item id="1" author="one" year="1998"/>
               <item id="3" author="two" year="2000"/>
               <item id="4" author="two" year="2001"/>
            </raw>
            <processed>
               <pos id="1" author="one">1</pos>
               <pos id="3" author="two">1</pos>
               <pos id="4" author="two">1</pos>
            </processed>
         </ref>
      </citation>
   </para>
</result>

Actual output:

<result>
     <para>
      <citation>
         <ref>
            <raw>
               <item id="1" author="one" year="1998"/>
               <item id="2" author="one" year="1998"/>
               <item id="4" author="two" year="2001"/>
            </raw>
            <processed>
               <pos id="1" author="one">1</pos>
               <pos id="4" author="two">1</pos>
            </processed>
         </ref>
      </citation>
   </para>
     <para>
      <citation>
         <ref>
            <raw>
               <item id="1" author="one" year="1998"/>
               <item id="3" author="two" year="2000"/>
               <item id="4" author="two" year="2001"/>
            </raw>
            <processed>
               <pos id="1" author="one">1</pos>
               <pos id="3" author="two">1</pos>
            </processed>
         </ref>
      </citation>
   </para>
</result>

Can someone please explain to me what I'm obviously not understanding
here?  I assume this is why I'm not getting expected output in the
realworld example I posted the other day.

Bruce

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.