[xsl] key() function issue

Subject: [xsl] key() function issue
From: Bruce D'Arcus <bdarcus@xxxxxxxxx>
Date: Wed, 1 Jun 2005 21:09:32 -0400
Can someone confirm for me that what I'm seeing here with the bib:first-reference function is not a bug in this code?

Source:

<doc>
<p>a <citation href="one"/> and a <footnote>and a <citation href="two"/> in a
footnote</footnote> and a <citation href="one"/></p>
</doc>


I want this function to return "false" for the last citation element, but all are returned as true.

Stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    xmlns:xs="http://www.w3.org/2001/XMLSchema";
    xmlns:bib="http://purl.org/NET/xbiblio/citeproc";
    exclude-result-prefixes="xs bib" version="2.0">

<xsl:key name="refs" match="citation" use="@href"/>

    <xsl:template match="doc">
      <list>
        <xsl:apply-templates
          select="//footnote|//citation[not(ancestor::footnote)]"/>
      </list>
    </xsl:template>

    <xsl:template match="footnote">
      <number>
        <xsl:value-of select="bib:footcite(.)"/>
        <xsl:apply-templates select="citation"/>
      </number>
    </xsl:template>

    <xsl:template match="citation">
      <xsl:variable name="first">
        <xsl:value-of select="bib:first-reference(.)"/>
      </xsl:variable>
      <number first="{$first}">
        <xsl:value-of select="bib:footcite(.)"/>
      </number>
    </xsl:template>

    <xsl:template match="citation[ancestor::footnote]">
      <xsl:variable name="first">
        <xsl:value-of select="bib:first-reference(.)"/>
      </xsl:variable>
      <nonumber first="{$first}"/>
    </xsl:template>

    <xsl:function name="bib:footcite" as="xs:string">
      <xsl:param name="footciteable" as="element()"/>
      <xsl:for-each select="$footciteable">
        <xsl:number level="any" select="."
          count="footnote|citation[not(ancestor::footnote)]"/>
      </xsl:for-each>
    </xsl:function>

<xsl:function name="bib:first-reference" as="xs:boolean">
<xsl:param name="cite-ref" as="node()"/>
<xsl:sequence select="$cite-ref is key('refs', $cite-ref/@href, $cite-ref)[1]"/>
</xsl:function>


</xsl:stylesheet>

Expected output:

<list>
   <number first="true">1</number>
   <number>2<nonumber first="true"/>
   </number>
   <number first="false">3</number>
</list>

Actual output:

<list>
   <number first="true">1</number>
   <number>2<nonumber first="true"/>
   </number>
   <number first="true">3</number>
</list>

Note last number/@first value.

If this is indeed a bug in Saxon (maybe related to my other problem from the past days), any suggested workarounds? That I'm not getting the expected output doesn't introduce huge problems for me in the short-run; it'd just be a missing feature I coded around the function.

Bruce

Current Thread