RE: [xsl] xsl:number and conditional

Subject: RE: [xsl] xsl:number and conditional
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 31 May 2005 23:31:14 +0100
> Example:
> 
> <doc>
>   <p>a <citation/> and a <footnote>and a <citation/> in a
> footnote</footnote> and a <citation/></p>
> </doc>
> 
> Correctly working 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:template match="doc">
>     <list>
>       <xsl:apply-templates
> select="//footnote|//citation[not(ancestor::footnote)]"/>
>     </list>
>   </xsl:template>
> 
>   <xsl:template match="p">
>     <xsl:apply-templates/>
>   </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">
>     <number>
>       <xsl:value-of select="bib:footcite(.)"/>
>     </number>
>   </xsl:template>
> 
>   <xsl:template match="citation[ancestor::footnote]">
>     <nonumber/>
>   </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:stylesheet>
> 
> Yields this output:
> 
> <list>
>    <number>1</number>
>    <number>2<nonumber/>
>    </number>
>    <number>3</number>
> </list>

So this the output that you want? I think this illustrates the point that if
your count pattern matches the same nodes as the ones you select for
numbering, you will get consecutive numbers.

> 
> Now, if I change the function to this:
> 
>   <xsl:function name="bib:footcite" as="xs:string">
>     <xsl:param name="footciteable" as="element()"/>
>     <xsl:number level="any" select="$footciteable"
> count="footnote|citation[not($footciteable/ancestor::footnote)]"/>
>   </xsl:function>

> 
> I get:
> 
> <list>
>    <number>1</number>
>    <number>2<nonumber/>
>    </number>
>    <number>4</number>
> </list>

I don't understand why you've changed a "correctly working stylesheet".

> 
> Saxon (8.4) will not allow me to remove the $footcitable on the count,
> nor to add it as context to the footnote.

Your original "correctly working stylesheet" didn't have $footcitable in the
count pattern, and works with Saxon 8.4, so I don't understand what you mean
by this. And I don't know what you mean by "add it as context to the
footnote" either!

(But thanks for putting together a complete example.)

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

Current Thread