Re: [xsl] Display count function output as letter value instead of number value

Subject: Re: [xsl] Display count function output as letter value instead of number value
From: Tony Graham <Tony.Graham@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 19 Aug 2008 16:44:59 +0100
On Tue, Aug 19 2008 15:37:58 +0100, Sharon_Harris@xxxxxxxxxxxxxxxxxxxx wrote:
> xsl:number does not output the numbering correctly. I have tried various
> ways of using xsl:number and though I can get a letter to output instead of
> a number, the sequence is wrong. Below are the various ways I have tried
> using xsl:number and the output I received. Please excuse me for the length
> of this post but I wanted to list all the different methods I had tried.
> Also please note that after the 1st listing, I only noted the block that
> contained the xls:number function rather than repeating the entire element
> definition since nothing else had changed.

>                                     <xsl:number format="A"/>
...
>                                     <xsl:number level="single" format="A"/>
...
>                                     <xsl:number level="multiple"
>       format="A"/>

You used every value of the "level" attribute except the one that is
most useful to you.

Use 'level="any"' to count among the union of the members of the
preceding and ancestor-or-self axes.

The description of 'level="any"' in XSLT 2.0 [1] may be more precise,
but the description in XSLT 1.0 [2] may be more understandable first go:

   When level="any", it constructs a list of length one containing the
   number of nodes that match the count pattern and belong to the set
   containing the current node and all nodes at any level of the
   document that are before the current node in document order,
   excluding any namespace and attribute nodes (in other words the union
   of the members of the preceding and ancestor-or-self axes). If the
   from attribute is specified, then only nodes after the first node
   before the current node that match the from pattern are considered.

Here's a similar example that I use for appendices in tables of
contents:

  <xsl:template match="appendix" mode="toc">
    <fo:block xsl:use-attribute-sets="toc-block-attr">
       <xsl:text>Appendix&#xA0;</xsl:text>
      <xsl:number level="any" count="appendix" format="A"/>
      <xsl:text> &#x2013; </xsl:text>
      <fo:inline xsl:use-attribute-sets="toc-attr">
     <xsl:apply-templates select="(tochead | exhibhead)[1]" mode="toc"/>
     </fo:inline>
      <xsl:call-template name="toc-page-number"/>
    </fo:block>
  </xsl:template>

BTW, the '//' in your match pattern doesn't really do anything extra.

Regards,


Tony Graham                         Tony.Graham@xxxxxxxxxxxxxxxxxxxxxx
Director                                  W3C XSL FO SG Invited Expert
Menteith Consulting Ltd
XML, XSL and XSLT consulting, programming and training
Registered Office: 13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland
Registered in Ireland - No. 428599   http://www.menteithconsulting.com
  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
xmlroff XSL Formatter                               http://xmlroff.org
xslide Emacs mode                  http://www.menteith.com/wiki/xslide
Unicode: A Primer                               urn:isbn:0-7645-4625-2


[1] http://www.w3.org/TR/xslt20/#numbering-based-on-position
[2] http://www.w3.org/TR/xslt#number

Current Thread