Re: using xsl:number

Subject: Re: using xsl:number
From: Gary L Peskin <garyp@xxxxxxxxxxxx>
Date: Thu, 24 Aug 2000 11:38:04 -0700
Raheja --

As usual, the easiest way to answer this question is to change the
question to one that's easier to answer.

Your problem would be much easier to solve if you could change the
structure of your input XML document.  If you nest your toc_num_list
directly within the containing topic, you'd be able to use
level=multiple easily.  This way, toc_num_list would directly be the
child of the containing topic (if any) rather than the child of the
containing toc_num_list.

For example, your first toc would look like:

    <topic toc1="#contactor">
      DC CONTACTOR, 41A296327AM
        <topic toc1="#func_desc">
          Functional Description
        <topic toc1="#clean">
        <topic toc1="#lube">
        <topic toc1="#inspect">

Then, you'd have to change your "topic" template to add this
apply-templates after the </a>:

	<xsl:apply-templates select="toc_num_list"/>

Also, you'd have to change your value-of select from "." to "text()".

This is due to the fact that the count attribute of the xsl:number
element is used for two purposes:  (1) to select the node of interest in
the ancestor-or-self tree that is built and (2) to select the siblings
of each node in the tree.  In your case, you want to build the
ancestor-or-self tree but only count "topic" siblings of either topic
nodes or toc_num_list nodes.  I don't think <xsl:number> can do that.

However, to answer your original question, if you're unable to change
the input XML, the following ugly recursive template should work:

Replace your loc_num_list template with:

<xsl:template match="toc_num_list">
  <xsl:param name="lvl" />		<!-- lvl is levels above this one -->
  <xsl:variable name="sibs" select="count(preceding-sibling::topic)" />
  <xsl:variable name="newparm">		<!-- lvl of preceding topic -->
      <xsl:when test="$sibs = 0" />
      <xsl:when test="$lvl">
        <xsl:value-of select="concat($lvl, '.', $sibs)"/>
        <xsl:value-of select="$sibs"/>
    <xsl:with-param name="lvl" select="$newparm"/>


And make your topic template look like this:

<xsl:template match="topic">
  <xsl:param name="lvl" />
    <xsl:when test="$lvl">
      <xsl:value-of select="concat($lvl, '.', count(. |
preceding-sibling::topic))" />
      <xsl:value-of select="count(. | preceding-sibling::topic)" />
    <xsl:attribute name="href"><xsl:value-of
  <xsl:value-of select="."/>


"Raheja, Dhruv (TRANS)" wrote:
> Hello,
>           I am trying to format my table of contents using xsl:number.
> however the concept is not very clear to me and hence i am unable to get the
> output i want. I hope somebody will be able to help me with this.

 XSL-List info and archive:

Current Thread