xsl-list
[Top] [All Lists]

grouping/position problem

2005-04-22 05:16:19
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


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