xsl-list
[Top] [All Lists]

followup on multi-level grouping/sorting/position

2005-04-27 17:59:03
I have a followup to the thread from the other day on grouping and sorting author-year bibliographies.

I managed to integrate Michael Kay's suggestion into my (rather complicated) code, and even refined it by moving a lot of the more complex logic into a series of functions (the real world example is much more complicated than the example I posted).

I've now tried to adapt the same approach to the problem of the in-text citations, which follow the same basic rules, where output should be (Doe, 1999; Smith, 2000) or (Doe, 1999, 2000; Smith, 2001a, b). So, again: multi-level grouping and sorting, with need to pass parameters to know how to handle punctuation.

The problem is that the below code yields the following message with my sample document:

<ref id="TimesP2001a" author-year_pos="1" shorten="false"/>
<ref id="Veer1996a" author-year_pos="1" shorten="false"/>
<ref id="Tilly2000a" author-year_pos="1" shorten="false"/> *
<ref id="Tilly2002a" author-year_pos="2" shorten="true"/> *
<ref id="NW2000-0207" author-year_pos="1" shorten="false"/> *
<ref id="NW2000-0424a" author-year_pos="1" shorten="false"/> *
<ref id="Tremblay2001a" author-year_pos="1" shorten="false"/>
<ref id="Thrift1990a" author-year_pos="1" shorten="false"/>
<ref id="Tilly2000a" author-year_pos="1" shorten="false"/>

The issue is that while the author-year position is being correctly reported, the "shorten-author" parameter is not correctly reported (the ref with the id of NW2000-0424a" should have @shorten="true" because it is the second of two references in a citation with an "author" of Newsweek).

The source is DocBook NG, and so the citations look like:

<citation>
  <biblioref linkend="NW2000-0207"/>
  <biblioref linkend="NW2000-0424a"/>
</citation>

Is there something obvious I'm doing wrong here? I've spent probably five hours trying to figure this out, and haven't really made any progress.

  <xsl:template match="db:citation" mode="sort_citation_author-year">
<!-- store citation for future use; not sure I need this anymore, but I did earlier -->
    <xsl:variable name="citation" select="."/>
    <xsl:variable name="idref"  select="db:biblioref/@linkend"/>
<!-- $enhanced-biblist is a temporary tree that holds the grouped and sorted data from earlier -->
    <xsl:variable name="bibref"
select="$enhanced-biblist/mods:modsCollection/mods:mods[(_at_)ID=$idref]"/>
    <!-- grouping on an attribute value added in the temporary tree -->
    <xsl:for-each-group select="$bibref" group-by="@bib:sort-on">
      <xsl:sort select="current-grouping-key()"/>
      <xsl:variable name="bibrefs-for-author-sorted-by-year"
        as="element(mods:mods)*">
        <xsl:perform-sort select="current-group()">
          <xsl:sort select="bib:year"/>
        </xsl:perform-sort>
      </xsl:variable>
<xsl:variable name="first-bibref-for-author" as="element(mods:mods)"
        select="$bibrefs-for-author-sorted-by-year[1]"/>
<xsl:for-each-group select="current-group()" group-adjacent="bib:year"> <xsl:variable name="author-year_group_position" select="position()"/>
        <xsl:variable name="shorten-author" as="xs:boolean"
          select="not(. is $first-bibref-for-author)"/>
<xsl:apply-templates select="current-group()" mode="citation_author-year"> <xsl:with-param name="local-cite-style" select="$local-cite-style"/> <xsl:with-param name="author-year_group_position" select="position()"/> <xsl:with-param name="shorten-author" select="$shorten-author"/>
        </xsl:apply-templates>
      </xsl:for-each-group>
    </xsl:for-each-group>
  </xsl:template>

  <xsl:template match="*" mode="citation_author-year">
    <xsl:param name="local-cite-style"/>
    <xsl:param name="author-year_group_position"/>
    <xsl:param name="shorten-author"/>
    <xsl:message exclude-result-prefixes="xhtml">
<ref id="{(_at_)ID}" author-year_pos="{$author-year_group_position}" shorten="{$shorten-author}"/>
    </xsl:message>
    <xsl:text>TEST</xsl:text>
    <xsl:if test="$author-year_group_position != last()">, </xsl:if>
    <xsl:if test="position() != last()">
      <xsl:value-of select="$style-citation/cs:entry/@delimiter"/>
    </xsl:if>
  </xsl:template>

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>