xsl-list
[Top] [All Lists]

Re: [xsl] XSLT transformation using counters

2011-04-26 10:37:44
Bubba O'Reily wrote:

I can't seem to get a handle on how to set a counter or variable then then 
output the results. I have a XML file (snippet) tagged like so:


Input:

<body>

<lev>
<hd>heading</hd>

     <lev>
     <hd>heading</hd>

         <lev>
         <hd>heading</hd>

             <lev>
             <hd>heading</hd>

             </lev>

         </lev>

     </lev>

</lev>

</body>


How can I set a counter and insert the results in the<HD?>  tag below?

  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="hd">
    <xsl:variable name="c">
      <xsl:number level="any"/>
    </xsl:variable>
    <xsl:element name="hd{$c}">
      <xsl:apply-templates select="@* | node()"/>
    </xsl:element>
  </xsl:template>

might do.
--

        Martin Honnen
        http://msmvps.com/blogs/martin_honnen/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--