RE: [xsl] key() function issue

Subject: RE: [xsl] key() function issue
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 2 Jun 2005 02:58:27 +0100
This one had me stumped for a little while, but Saxon is behaving correctly.
The treatment of the third argument to key() changed recently, and the
change is in Saxon 8.4. It now searches not the whole document containing
$citekey, but only the subtree rooted at $citekey - this is to allow keyed
searches within a subtree of a document. So you need to write the third
argument as root($citekey) or $citekey/(/)

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: Bruce D'Arcus [mailto:bdarcus@xxxxxxxxx] 
> Sent: 02 June 2005 02:10
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] key() function issue
> 
> 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