This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: using xsl:number


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:

<toc>
  <title>
    MAIN COMPONENT 
  </title>
  <break/>
  <toc_num_list>
    <topic toc1="#contactor">
      DC CONTACTOR, 41A296327AM
      <toc_num_list>
        <topic toc1="#func_desc">
          Functional Description
        </topic>
        <topic toc1="#clean">
          Cleaning
        </topic>
        <topic toc1="#lube">
          Lubrication
        </topic>
        <topic toc1="#inspect">
          Inspection
        </topic>
      </toc_num_list>
    </topic>
  </toc_num_list>
</toc>

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:choose>
      <xsl:when test="$sibs = 0" />
      <xsl:when test="$lvl">
        <xsl:value-of select="concat($lvl, '.', $sibs)"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$sibs"/>
      </xsl:otherwise>
   </xsl:choose>
  </xsl:variable>
  
  <ol>
  <xsl:apply-templates>
    <xsl:with-param name="lvl" select="$newparm"/>
  </xsl:apply-templates>
  </ol>

</xsl:template>

And make your topic template look like this:

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


HTH,
Gary

"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.
>[snip]


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]