[xsl] temp trees and context switching

Subject: [xsl] temp trees and context switching
From: Bruce D'Arcus <bdarcus@xxxxxxxxxxxxx>
Date: Fri, 12 Nov 2004 19:31:32 -0500
With previous simple example working, I'm now trying to integrate the ideas into my stylesheets.

So the idea is

1) create a "citekey" key that indexes all db:biblioref element linkend attribute values.
2) use distinct-values in the citekey key to construct a mods:modsCollection in the temporary tree (which is what I currently assume is embedded in the db:bibliography element).
3) all subsequent processing would as it had previously been working correctly


Below is my first few templates (I can't post the entire code), with source example below it. Am I doing something wrong with using the call-template below?

<xsl:key name="citekey" match="db:biblioref/@linkend" use="'all'" />

<xsl:template match="/">
<xsl:variable name="temp">
<xsl:apply-templates mode="enhanced-bib"/>
</xsl:variable>
<xsl:apply-templates select="$temp" mode="modified"/>
</xsl:template>
<xsl:template match="db:article" mode="enhanced-bib">
<article>
<xsl:apply-templates mode="enhanced-bib"/>
</article>
</xsl:template>
<xsl:template match="db:info" mode="enhanced-bib">
<xsl:copy-of select="."/>
</xsl:template>
<xsl:template match="db:section[$citation-class='author-year']" mode="enhanced-bib">
<xsl:copy-of select="."/>
</xsl:template>


<xsl:template match="db:bibliography" mode="enhanced-bib">
<bibliography>
<xsl:for-each select="distinct-values(key('citekey', 'all'))">
<xsl:variable name="bibrecord"
select="doc(concat('/Users/darcusb/Desktop/xbiblio-alt/samples/bib- data/', ., '.mods'))/mods:modsCollection/mods:mods"/>
<modsCollection xmlns="http://www.loc.gov/mods/v3";>
<xsl:call-template name="enhanced-bib">
<xsl:with-param name="bibrecord" select="$bibrecord"/>
</xsl:call-template>
</modsCollection>
</xsl:for-each>
</bibliography>
</xsl:template>


<xsl:template name="enhanced-bib">
<xsl:param name="bibrecord"/>
<xsl:copy>
<xsl:variable name="bibref" select="$bibrecord" />
<xsl:for-each-group select="$bibrecord" group-by="bib:grouping-key(.)">
<xsl:sort select="current-grouping-key()"/>
<xsl:for-each-group select="current-group()"
group-by="substring((mods:originInfo/mods:dateIssued ,
mods:relatedItem/mods:originInfo/mods:dateIssued ,
mods:relatedItem/mods:part/mods:date )[1],1,4)">
<xsl:sort select="current-grouping-key()" />
<xsl:variable name="refclass">
<xsl:choose>
<xsl:when test="mods:relatedItem[@type='host']">
<xsl:choose>
<xsl:when
test="mods:relatedItem[@type='host']/mods:originInfo/mods: issuance='monographic'">part-inMonograph</xsl:when>
<xsl:otherwise>part-inSerial</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>monograph</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="reftype">
<xsl:choose>
<xsl:when test="$refclass='part-inSerial'">
<xsl:text>article</xsl:text>
<xsl:text>-</xsl:text>
<xsl:value-of select="mods:relatedItem/mods:genre"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="mods:genre"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="year"
select="current-grouping-key()"/>
<xsl:variable name="first" as="xs:boolean" select="position() = 1" />
<xsl:variable name="noname-substitute">
<xsl:choose>
<xsl:when test="not(mods:name) and $refclass='part-inSerial'">
<xsl:value-of
select="mods:relatedItem[@type='host']/mods:titleInfo[not(@type)]/mods: title"/>
</xsl:when>
<xsl:when test="not(mods:name) and not($refclass='part-inSerial')">
<xsl:text>Anonymous</xsl:text>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:for-each select="current-group()">
<mods ID="{@ID}">
<!-- We create enhanced virtual elements to help subsequent processing. -->
<refclass>
<xsl:value-of select="$refclass"/>
</refclass>
<reftype>
<xsl:value-of select="$reftype"/>
</reftype>
<year>
<xsl:value-of select="current-grouping-key()"/>
</year>
<!-- noname-substitute element determines what to do when there is no author name. -->
<noname-substitute>
<xsl:value-of select="$noname-substitute"/>
</noname-substitute>
<xsl:if test="last() > 1">
<key type="year-suffix">
<xsl:number value="position()" format="a"/>
</key>
</xsl:if>
<xsl:copy-of select="*"/>
</mods>
</xsl:for-each>
</xsl:for-each-group>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>


=== source ===

<?xml version="1.0" encoding="utf-8"?>
<article xmlns="http://docbook.org/docbook-ng";>
<info>
<title>Test</title>
</info>
<section>
<info>
<title>Introduction</title>
</info>
<para>Some citations: <citation><biblioref linkend="one"/><biblioref
linkend="two"/><biblioref linkend="three"/></citation>.</para>
<para>A citation with page number detail: <citation><biblioref linkend="one"
units="page" begin="23" end="24" /></citation>. A
citation <footnote><para>... in a footnote <citation><biblioref
linkend="three" begin="234"/></citation></para></footnote>.</para>
</section>
<bibliography/>
</article>


Current Thread