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

Re: grouping/position problem

Subject: Re: grouping/position problem
From: "M. David Peterson" <m.david.x2x2x@xxxxxxxxx>
Date: Fri, 22 Apr 2005 06:41:20 -0600
xsl position 1
Bruce,

I have finally seen what it is you were refering to with this.  I had
a complete misunderstanding as to what you were suggesting in regards
to sort order and position within the sort order.  This should take
only but a sec, but need to set something else aside first.  Let me
find a stopping point and then I will blast this out real fast.

I will post it back to the group as well in case any of you might find
this useful.

---------- Forwarded message ----------
From: Bruce D'Arcus <bdarcus@xxxxxxxxx>
Date: Apr 22, 2005 6:16 AM
Subject:  grouping/position problem
To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx


I'm having some problems with grouping and position().

For illustration, you could imagine an input source like:

<list>
  <item author="five" year="2001"/>
  <item author="three" year="2003"/>
  <item author="four" year="2002"/>
  <item author="two" year="1998"/>
  <item author="one" year="2005"/>
  <item author="two" year="2000"/>
  <item author="four" year="1999"/>
</list>

I need to group and sort by author, then by year, and then pass some
parameters that are based on the item's position within -- in this case
-- the author group.

I have this template:

  <xsl:template match="mods:modsCollection" mode="sort_author-year">
    <xsl:variable name="bibref" select="mods:mods" />
    <xsl:for-each-group select="$bibref" group-by="bib:grouping-key(.)">
      <xsl:sort select="current-grouping-key()"/>
      <xsl:variable name="author-position" select="position()"/>
      <xsl:variable name="shorten-author" as="xs:boolean"
select="$author-position > 1" />
      <xsl:for-each-group select="current-group()"
group-by="bib:year(.)">
        <xsl:sort select="current-grouping-key()" />
       <xsl:variable name="year">
          <xsl:value-of select="current-grouping-key()"/>
         <xsl:if test="last() > 1">
           <xsl:number value="position()" format="a"/>
         </xsl:if>
       </xsl:variable>
        <xsl:for-each select="current-group()">
          <xsl:apply-templates select="mods:titleInfo">
            <xsl:with-param name="year" select="$year"/>
            <xsl:with-param name="shorten-author"
select="$shorten-author"/>
          </xsl:apply-templates>
        </xsl:for-each>
      </xsl:for-each-group>
    </xsl:for-each-group>
  </xsl:template>

The bib:grouping-key function constructs an author names string to sort.

The problem is the author-position variable.

What I want is for it to measure position within an author group.  But
I'm getting these sorts of results:

    AUTHOR POSITION: 1
    SHORTEN: false
    AUTHOR POSITION: 2
    SHORTEN: true
    AUTHOR POSITION: 2
    SHORTEN: true
    AUTHOR POSITION: 3
    SHORTEN: true
    AUTHOR POSITION: 4
    SHORTEN: true
    AUTHOR POSITION: 4
    SHORTEN: true
    AUTHOR POSITION: 5
    SHORTEN: true
    AUTHOR POSITION: 6

... which tells me it's measuring the position of the group itself.

What I'm wanting is:

    AUTHOR POSITION: 1
    SHORTEN: false
    AUTHOR POSITION: 1
    SHORTEN: false
    AUTHOR POSITION: 2
    SHORTEN: true
    AUTHOR POSITION: 1
    SHORTEN: false
    AUTHOR POSITION: 1
    SHORTEN: false
    AUTHOR POSITION: 2
    SHORTEN: true
    AUTHOR POSITION: 1
    SHORTEN: false
    AUTHOR POSITION: 1
    SHORTEN: false

How do I fix this?

Bruce



--
<M:D/>

:: M. David Peterson ::
XML & XML Transformations, C#, .NET, and Functional Languages Specialist

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.