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

Subject: Re: [xsl] Recognize nested element (check for same-name parent)
From: Cas Tuyn <Cas.Tuyn@xxxxxxxx>
Date: Thu, 10 Feb 2005 09:46:05 +0100
David,

This is good. I indeed have a long history of ksh and csh scripting 
(started in 1987 at AT&T, at my current job programmed an entire 
document management system in csh with history, locking and archiving), 
and moved to programming Perl in 1999. Like it very much, but my Perl 
programs indeed look like shell scripts, and my XSLT only recently 
started using the 'xsl:template match=' way of working.

You convinced me with the beauty of the XSLT, I'll improve my two 
templates to work this way.

Thanks very much for teaching me these new methods/way of thinking.

Cas

> <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
> ________________________________________________________________________
> 
> 



-- 
The information contained in this communication and any attachments is confidential and may be privileged, and is for the sole use of the intended recipient(s). Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please notify the sender immediately by replying to this message and destroy all copies of this message and any attachments. ASML is neither liable for the proper and complete transmission of the information contained in this communication, nor for any delay in its receipt.

Current Thread