Re: [xsl] grouping and context (?)

Subject: Re: [xsl] grouping and context (?)
From: Bruce D'Arcus <bdarcus@xxxxxxxxxxxxx>
Date: Fri, 27 Aug 2004 20:52:13 -0400
On Aug 27, 2004, at 10:52 AM, David Carlisle wrote:

key() (as in xslt1) returns nodes only from the current document (where
temporary trees generated in xsl:variable count as new documents)
the solution is as in xslt1

save a variable holding a node in teh original document before you go
off somewhere else

<xsl:variable name="orig" select="/"/>

So where exactly am I putting this variable? At the top-level of my current stylesheet? Within the template?


then when you need to go back there use (in xslt2)

select="$orig/key('citekey', current()/@ID)"

I've tried a couple of variations on this, but I still get the same behavior, where:


<citation><biblioref linkend="doe99a"/></citation>
<citation><biblioref linkend="doe99a" begin="1" end="2"/></citation>

Yields:

(Doe, 1999: 1-2)
(Doe, 1999: 1-2)

Template as it exists now (the top-level element for the bib record would be <mods ID="doe99a">):

<xsl:variable name="orig" select="/"/>

<!-- begin citation processing -->
<xsl:key name="citekey" match="db:biblioref" use="@linkend" />
<!-- author-year class processing -->
<xsl:template match="db:citation[$citation-class='author-year']">
  <xsl:variable name="idref" select="db:biblioref/@linkend"/>
<!-- use a key to access mods records based on lindend value -->
  <xsl:variable name="bibref" select="key('bibref', $idref)" />
  <xsl:value-of select="$citation-before"/>
<!-- group and sort by authors-string -->
  <xsl:for-each-group select="$bibref" group-by="bib:grouping-key(.)">
    <xsl:sort select="current-grouping-key()"/>
<!-- within an authors group, sort by year -->
    <xsl:for-each-group select="current-group()"
			group-by="mods:year">
      <xsl:sort select="current-grouping-key()"/>
      <xsl:for-each select="current-group()">
<!-- since we're now working with the mods source, the only way
I can see to get back to the biblioref code is to use a key again;
unfortunately doesn't work correctly ** -->
	<xsl:variable name="citekey" select="key('citekey', @ID)" />
	<a href="#{@ID}">
	  <xsl:if test="position() = 1">
	    <xsl:choose>
	      <xsl:when test="mods:name">
		<xsl:apply-templates select="mods:name" mode="citation"/>
	      </xsl:when>
	      <xsl:otherwise>
		<xsl:value-of select="mods:noname-substitute"/>
	      </xsl:otherwise>
	    </xsl:choose>
	    <xsl:text>, </xsl:text>
	    <xsl:value-of select="mods:year"/>
	  </xsl:if>
<!-- apply suffix if applicable -->
	  <xsl:apply-templates select="mods:key"/>
<!-- render point citation details if present -->
          <xsl:for-each select="$orig/key('citekey', current()/@ID)">
          <xsl:if test="@begin">
	    <xsl:value-of select="$point-cite-before"/>
	    <xsl:value-of select="@begin" />
	    <xsl:text>-</xsl:text>
	    <xsl:choose>
	      <xsl:when test="string-length(@begin) = 1">
		<xsl:value-of select="@end" />
	      </xsl:when>
	      <xsl:when test="string-length(@begin) = 2">
		<xsl:value-of select="substring(@end, 2, 1)" />
	      </xsl:when>
	      <xsl:otherwise>
		<xsl:value-of select="substring(@end, last() - 1)" />
	      </xsl:otherwise>
	    </xsl:choose>
	  </xsl:if>
	  </xsl:for-each>
	  <xsl:if test="position() != last()">, </xsl:if>
	</a>
      </xsl:for-each>
    </xsl:for-each-group>
    <xsl:if test="position() != last()">; </xsl:if>
  </xsl:for-each-group>
  <xsl:value-of select="$citation-after"/>
</xsl:template>

Bruce

Current Thread