[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Recognize nested element (check for same-name parent)


Subject: Re: [xsl] Recognize nested element (check for same-name parent)
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 9 Feb 2005 17:07:02 GMT

<x>
<section>
  <title>PREPARE</title>
  <step>Step 1.</step>
  <step>Do as follows:
    <step>Select: Start</step>
    <step>Select: Yes</step>
  </step>
</section>
<section>
  <title>REMOVE PART</title>
  <step>Step 3.</step>
  <step>Do as follows:
    <step>Select: Initialize Motor</step>
    <step>Select: Yes</step>
  </step>
</section>
</x>



<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">



<xsl:output indent="yes"/>

<xsl:template match="/">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

<xsl:template match="section">
<div>
<h2><xsl:apply-templates select="title"/></h2>
<ul>
 <xsl:apply-templates select="step">
  <xsl:with-param name="prefix" select="''"/>
  <xsl:with-param name="start" select="count(preceding-sibling::*/step)"/>
 </xsl:apply-templates>
</ul>
</div>
</xsl:template>

<xsl:template match="step">
  <xsl:param name="prefix"/>
  <xsl:param name="start"/>
<li><span>
  <xsl:value-of select="$prefix"/>
  <xsl:value-of select="position()+$start"/>
  <xsl:text> </xsl:text>
  </span>
  <span><xsl:value-of select="text()[1]"/></span>
  <xsl:if test="step">
   <ul>
   <xsl:apply-templates select="step">
    <xsl:with-param name="prefix" select="concat($prefix,$start+position(),'.')"/>
    <xsl:with-param name="start" select="0"/>
   </xsl:apply-templates>
  </ul>
  </xsl:if>
</li>
</xsl:template>

</xsl:stylesheet>




<html>
   <body>
      
      <div>
         <h2>PREPARE</h2>
         <ul>
            <li><span>1 </span><span>Step 1.</span></li>
            <li><span>2 </span><span>Do as follows:
                  </span><ul>
                  <li><span>2.1 </span><span>Select: Start</span></li>
                  <li><span>2.2 </span><span>Select: Yes</span></li>
               </ul>
            </li>
         </ul>
      </div>
      
      <div>
         <h2>REMOVE PART</h2>
         <ul>
            <li><span>3 </span><span>Step 3.</span></li>
            <li><span>4 </span><span>Do as follows:
                  </span><ul>
                  <li><span>4.1 </span><span>Select: Initialize Motor</span></li>
                  <li><span>4.2 </span><span>Select: Yes</span></li>
               </ul>
            </li>
         </ul>
      </div>
      
   </body>
</html>

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________


Current Thread