xsl-list
[Top] [All Lists]

grouping confusion

2004-12-16 06:33:45
As I've reworked my stylesheets, I've gotten stuck on some code that was previously working. It formats a citation by doing a multi-level grouping and sorting by author and then year. If there is more than one author, only the first should be printed. Likewise, if there's more than one author-year combination, then only the suffix gets printed. Example:

        (Thrift, 1990; Tilly, 2000a, 2002b; Times, 2001)

.... or (Thrift, 1990; Tilly, 1999a, b; Times, 2001)

However, I'm getting this for the first one:

        (Thrift, 1990; Tilly, 2000a, Tilly, 2002b; Times, 2001)

It's clear the problem is in how I'm using the position() function within the groups, but I can't figure out how to fix it. I suspect it may be something about the bibref variable. In the previous approach, I had used a key for that indexed all the bibliographic records by their ID attribute, while here I'm just accessing a variable that holds all those records. Is there something different conceptually about the two approaches that would cause position() to behave differently in this context?

  <xsl:template match="db:citation">
    <!-- store citation for future use -->
    <xsl:variable name="citation" select="."/>
    <xsl:variable name="idref" select="db:biblioref/@linkend"/>
<xsl:variable name="bibref" select="$enhanced-biblist/mods:modsCollection/mods:mods[(_at_)ID=$idref]"/>
    <xsl:value-of select="$style-citation/cs:prefix"/>
    <xsl:choose>
      <xsl:when test="$citeclass='author-year'">
<xsl:for-each-group select="$bibref" group-by="bib:grouping-key(.)">
          <xsl:sort select="current-grouping-key()"/>
<xsl:for-each-group select="current-group()" group-by="bib:year">
            <xsl:sort select="current-grouping-key()"/>
            <xsl:variable name="position" select="position()"/>
            <xsl:for-each select="current-group()">
              <a href="#{(_at_)ID}">
                <xsl:if test="position() = 1">
                  <xsl:choose>
                    <xsl:when test="mods:name">
<xsl:apply-templates select="mods:name" mode="short"/>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:value-of select="bib:noname-substitute"/>
                    </xsl:otherwise>
                  </xsl:choose>
<xsl:value-of select="$style-citation/cs:entry/cs:creator/cs:suffix"/>
                  <xsl:value-of select="bib:year"/>
                </xsl:if>
                <xsl:apply-templates select="bib:key"/>
    <!--+ ==============================================================
    | render point citation details if present
    +-->
                <xsl:if test="$citation/db:biblioref/@begin">
<xsl:value-of select="$style-citation/cs:entry/cs:point/cs:prefix"/>
                  <xsl:value-of select="$citation/db:biblioref/@begin"/>
                  <xsl:if test="$citation/db:biblioref/@end">
                    <xsl:text>–</xsl:text>
<xsl:value-of select="bib:number-condense($citation/db:biblioref/@begin, $citation/db:biblioref/@end)"/>
                  </xsl:if>
                </xsl:if>
              </a>
            </xsl:for-each>
            <xsl:if test="$position != last()">, </xsl:if>
          </xsl:for-each-group>
          <xsl:if test="position() != last()">
            <xsl:value-of select="$style-citation/cs:entry/@delimiter"/>
          </xsl:if>
        </xsl:for-each-group>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$style-citation/cs:prefix"/>
        <xsl:for-each select="db:biblioref">
          <xsl:variable name="linkend" select="@linkend"/>
          <xsl:variable name="number">
            <xsl:choose>
              <xsl:when test="$sort_order-bib='cited'">
<xsl:value-of select="$cite-position/bib:refs/bib:unique/bib:ref[(_at_)key=$linkend]/ @position"/>
              </xsl:when>
              <xsl:when test="$sort_order-bib='citekey'">
                <xsl:value-of select="$linkend"/>
              </xsl:when>
              <xsl:otherwise>
<xsl:value-of select="$formatted-biblist/xhtml:p[(_at_)id=$linkend]/xhtml: span[(_at_)class='mark']"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:variable>
          <a href="#{$linkend}">
            <xsl:value-of select="$number"/>
          </a>
          <xsl:if test="position() != last()">, </xsl:if>
          <xsl:if test="position() != last()">
            <xsl:value-of select="$style-citation/cs:entry/@delimiter"/>
          </xsl:if>
        </xsl:for-each>
        <xsl:value-of select="$style-citation/cs:suffix"/>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:value-of select="$style-citation/cs:suffix"/>
  </xsl:template>

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