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

grouping/position problem

Subject: grouping/position problem
From: Bruce D'Arcus <bdarcus@xxxxxxxxx>
Date: Fri, 22 Apr 2005 08:16:19 -0400
xsl position 1
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

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.