Well, I didn’t hear back, so I took a look again at the earlier code
that correctly handled grouping and sorting, and incorporated it into a
file with the existing functions. Result of messages are:
author-position: <value-of select="1"/>
author-year-position: <value-of select="1"/>
author-position: <value-of select="2"/>
author-year-position: <value-of select="1"/>
author-position: <value-of select="2"/>
author-year-position: <value-of select="1"/>
author-position: <value-of select="3"/>
author-year-position: <value-of select="1"/>
author-position: <value-of select="4"/>
author-year-position: <value-of select="1"/>
author-position: <value-of select="4"/>
author-year-position: <value-of select="2"/>
author-position: <value-of select="5"/>
author-year-position: <value-of select="1"/>
… which is close, but the author-position values are wrong. Also,
this take about 700 ms on my machine when run against the mods test
doc, which is not that fast (even if I have a slow machine, and am
running an older version of Saxon).
David, is this a better approach, just passing the parameter through?
Or did you have something else in mind?
<?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:variable name=“biblist”>
<xsl:copy-of select=“mods:modsCollection”/>
</xsl:variable>
<xsl:template match="/">
<xsl:apply-templates mode=“enhanced-biblist”/>
</xsl:template>
<xsl:template name=“bib-enhanced-biblist” match=“mods:modsCollection"
mode=“enhanced-biblist”>
<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:for-each-group select="current-group()“
group-by=“bib:year(.)”>
<xsl:sort select=“current-grouping-key()” />
<xsl:variable name=“author-year-position"
select=“position()”/>
<xsl:variable name=“year” select=“current-grouping-key()”/>
<xsl:variable name=“first” as=“xs:boolean” select=“position() = 1” />
<xsl:for-each select=“current-group()”>
<xsl:copy-of select=”.”/>
xsl:message
author-position:
author-year-position:
</xsl:message>
</xsl:for-each>
</xsl:for-each-group>
</xsl:for-each-group>
</xsl:template>
<xsl:variable name=“primary-contributors” select="(‘author’,
‘editor’, ‘creator’)"/>
<xsl:variable name=“secondary-contributors” select="(‘translator’)"/>
<xsl:function name=“bib:contributor-role” as=“xs:string”>
<xsl:param name=“name” as=“element(mods:name)?”/>
xsl:value-of
xsl:choose
<xsl:when
test="$name/mods:role/mods:roleTerm[@type=‘text’]=$primary-
contributors">
xsl:textprimary</xsl:text>
</xsl:when>
<xsl:when
test="$name/mods:role/mods:roleTerm[@type=‘text’]=$secondary-
contributors">
xsl:textsecondary</xsl:text>
</xsl:when>
</xsl:choose>
</xsl:value-of>
</xsl:function>
<xsl:function name=“bib:year”>
<xsl:param name=“bibref” as=“element(mods:mods)”/>
<xsl:for-each select="$bibref">
<xsl:value-of
select=“substring((mods:originInfo/mods:dateIssued,
mods:relatedItem/mods:originInfo/mods:dateIssued,
mods:relatedItem/mods:part/mods:date)[1],1,4)”
/>
</xsl:for-each>
</xsl:function>
xdoc:docCollapses a page range according to the Chicago algorithm.
Probably
needs to be generalized.</xdoc:doc>
<xsl:function name=“bib:number-condense”>
<xsl:param name=“begin”/>
<xsl:param name=“end”/>
xsl:choose
<xsl:when test="$begin castable as xs:integer">
<xsl:variable name=“begin” select=“xs:integer($begin)“
as=“xs:integer”/>
xsl:choose
<xsl:when
test=”$begin gt 100 and $begin mod 100 and $begin idiv 100
eq $end idiv 100”>
<xsl:value-of select="$end mod 100"/>
</xsl:when>
xsl:otherwise
<xsl:value-of select="$end"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
xsl:otherwise
<xsl:value-of select="$end"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<xsl:function name=“bib:grouping-key” as=“xs:string”>
<xsl:param name=“bibref” as=“element(mods:mods)”/>
xsl:choose
<xsl:when
test="$bibref/mods:name[bib:contributor-role(.)=‘primary’]">
<xsl:value-of separator=";">
<xsl:for-each select="$bibref/mods:name">
<xsl:value-of
select=“string-join((mods:namePart[@type =
‘family’]|mods:namePart[not(@type)], mods:namePart[@type = ‘given’]),
’,’)”
/>
</xsl:for-each>
</xsl:value-of>
</xsl:when>
xsl:otherwise
xsl:choose
<xsl:when
test="$bibref/mods:relatedItem[@type=‘host’]/mods:originInfo/mods:
issuance = ‘continuing’">
<xsl:for-each select="$bibref">
<xsl:value-of
select=“mods:relatedItem[@type=‘host’]/mods:titleInfo[not(@type)]/mods:
title”
/>
</xsl:for-each>
</xsl:when>
xsl:otherwise
xsl:textAnonymous</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<xsl:function name=“bib:refclass” as=“xs:string”>
<xsl:param name=“bibref” as=“element(mods:mods)?”/>
xsl:choose
<xsl:when test="$bibref/mods:relatedItem[@type=‘host’]">
<xsl:variable name=“issuance”
select="$bibref/mods:relatedItem/mods:originInfo/mods:issuance"/>
xsl:choose
<xsl:when
test="$issuance=‘monographic’">part-inMonograph</xsl:when>
xsl:otherwisepart-inSerial</xsl:otherwise>
</xsl:choose>
</xsl:when>
xsl:otherwisemonograph</xsl:otherwise>
</xsl:choose>
</xsl:function>
<xsl:function name=“bib:reftype” as=“xs:string”>
<xsl:param name=“bibref” as=“element(mods:mods)?”/>
xsl:value-of
xsl:choose
<xsl:when test="$bibref/mods:relatedItem/@type = ‘host’">
<xsl:variable name=“issuance”
select="$bibref/mods:relatedItem/mods:originInfo/mods:issuance"/>
xsl:choose
<xsl:when test=“bib:refclass($bibref) = ‘part-inSerial’”>
<xsl:if
test="$bibref/mods:relatedItem/mods:genre=‘periodical’">
xsl:textarticle</xsl:text>
xsl:text-</xsl:text>
</xsl:if>
<xsl:value-of
select="$bibref/mods:relatedItem/mods:genre"/>
</xsl:when>
<xsl:when test=“bib:refclass($bibref) = ‘part-inMonograph’”>
xsl:choose
<xsl:when test="$bibref/mods:genre">
<xsl:value-of select="$bibref/mods:genre"/>
</xsl:when>
xsl:otherwise
xsl:textchapter</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
xsl:otherwise
<xsl:value-of select="$bibref/mods:genre"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
xsl:otherwisebook</xsl:otherwise>
</xsl:choose>
</xsl:value-of>
</xsl:function>
</xsl:stylesheet