alternate grouping approach

OK, I tried to use David’s template-based grouping approach, but it’s
not working. The position stuff is STILL screwed up, and I’m about to
scream!

<xsl:template match=“mods:modsCollection” mode=“sort_author-year”>
bib:bibList
<xsl:variable name=“bibrefs” select=“mods:mods”/>
<xsl:for-each-group select="$bibrefs"
group-by=“bib:grouping-key(.)”>
<xsl:sort select=“current-grouping-key()” />
bib:authorGroup
<xsl:apply-templates select="current-group()"
mode=“sort_year”>
<xsl:sort select=“current-grouping-key()” />
<xsl:sort select=“bib:year(.)” />
<xsl:with-param name="author-position"
select=“position()”/>
</xsl:apply-templates>
</bib:authorGroup>
</xsl:for-each-group>
</bib:bibList>
</xsl:template>

<xsl:template match=“mods:mods” mode=“sort_year”>
<xsl:param name=“author-position”/>


<xsl:value-of select="$author-position"/>


<xsl:value-of select=“mods:titleInfo/mods:title”/>


</xsl:template>

Alas, it doesn’t return the correct results:

<?xml version="1.0" encoding="UTF-8"?>

<bib:bibList xmlns:bib=“http://purl.org/NET/xbiblio/citeproc”>
bib:authorGroup

1
Tremblay v. Québec (Attorney General)

</bib:authorGroup>
bib:authorGroup

2
Perspectives


2
The Grandmas Pay a Visit

</bib:authorGroup>
bib:authorGroup

3
For a New Regional Geography 1

</bib:authorGroup>
bib:authorGroup

4
Review of Moral Economy and Popular Protest


4
Stories, Identities, and Political Change

</bib:authorGroup>
bib:authorGroup

5
Senators Stamp OK on Anti-Terrorism Laws

</bib:authorGroup>
bib:authorGroup

6
Riots and Rituals

</bib:authorGroup>
</bib:bibList>

BTW, one of the reasons I wanted to try this approach is that it then
makes it easy to solve the grouping-by-reference-type issue. So I’m
imaging a temporary tree that looks like:

bib:bibList
bib:uncitedGroup
bib:authorGroup
bib:item

</bib:item>
</bib:authorGroup>
</bib:uncitedGroup>
bib:mainGroup
bib:authorGroup
bib:item

</bib:item>
</bib:authorGroup>
</bib:mainGroup>
bib:bibList

I’'m thinking it might be more efficient to transform mods into a
temporary tree representation that is a perfect mirror of the CSL
language. Does that seem right?

Yo David, where are you??? I gotta go out for a few hours, but I want
to get this working today!

Bruce

Actually, I think the best median approach is to keep my earlier use of
a global variable to hold the enhanced biblist, but to split sorting
into different modes in separate templates.

Testing on my sample doc shows this is quite fast, and it’s a lot
easier to manage than the existing code. And it’s clear the problem
with the damned author position() thing is not a problem of this
approach; it’s just a PITA. I can’t figure it out! I can only hope
someone on the xsl list does!

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0"
xmlns:xdoc="http://www.pnp-software.com/XSLTdoc"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:mods="http://www.loc.gov/mods/v3"
xmlns:cs="http://purl.org/NET/xbiblio/csl"
xmlns:bib="http://purl.org/NET/xbiblio/citeproc"
exclude-result-prefixes=“xdoc mods xs cs bib”>

<xsl:output method=“xml” indent=“yes” encoding=“UTF-8”/>

<xsl:param name=“sort_order” select="‘author-year’"/>

<xsl:template match="/">

<xsl:copy-of select="$enhanced-biblist"/>

</xsl:template>

<xsl:variable name="enhanced-biblist">
  <xsl:choose>
    <xsl:when test="$sort_order='citekey'">
      <xsl:apply-templates select="list" mode="sort_citekey"/>
    </xsl:when>
    <xsl:when test="$sort_order='cited'">
      <xsl:apply-templates select="list" mode="sort_cited"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:apply-templates select="list" mode="sort_author-year"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:variable>

<xsl:template match="list" mode="sort_author-year">
  <xsl:for-each-group select="item" group-by="@author">
    <xsl:sort select="current-grouping-key()"/>
    <xsl:variable name="author-position" select="position()"/>
    <xsl:for-each-group select="current-group()" group-by="@year">
      <xsl:sort select="current-grouping-key()" />
      <xsl:for-each select="current-group()">
        <xsl:variable name="shorten-author" as="xs:boolean"
	select="$author-position > 1" />
   <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:apply-templates select=".">
          <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>

<xsl:template match="item">
  <xsl:param name="shorten-author"/>
  <xsl:param name="year"/>
  <item>
    <shorten-author>
      <xsl:value-of select="$shorten-author"/>
    </shorten-author>
    <year>
      <xsl:value-of select="$year"/>
    </year>
  </item>
 </xsl:template>

</xsl:stylesheet>

Bruce,

A lot is on schedule for the weekend, the next in the list the
clean-up of the code base issues using a grouping approach that will
work. The approach a sampled to xsl-list yesterday will work just
fine. It just needs to be continued to enable the grouping and
subsequent output you are looking for.

I will be starting this in about two hours (my “day” just began about
1/2 hour ago).

It seems I was just posting as you were. The problem is it’s really
difficult for me to evaluate. If you can create the expected output I
posted in the followup to Mike, that’s great.

I’m thinking that the example I just posted – which combines modes, a
global variable temporary tree, and apply-templates – will be the
easiest to handle. One of the things I found when dealing with
multiple trees (as in citeproc) is it’s often really difficult to
localize what’s going on. That why I like having an enhanced-biblist
global variable. You’ll note that it’s a lot cleaner than the existing
code, even if it still doesn’t work!

The grouping problem (still not solved by anyone, I might add) is not
specific to either approach.

Bruce