[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Recursive Templates

Subject: Re: Recursive Templates
From: Tony Graham <tgraham@xxxxxxxxxxxxxxxx>
Date: Sun, 1 Aug 1999 17:04:24 -0400 (EST)
xsl recursive template
At 2 Aug 1999 03:12 +1000, Michael Stillwell wrote:
 > I've just started using XSL and am wondering how to achieve the
 > transformation such as the following.  I want to transform
 > 
 >   <section>Introduction</section>
 >   
 > into (say)
 > 
 >   <caps><strong>Introduction</strong></caps>

<xsl:template match="section">
  <caps>
    <strong>
      <xsl:apply-templates/>
    </strong>
  </caps>
</xsl:template>

 > My first attempt used templates like
 > 
 >   <xsl:template match="emph" name="emph">
 >   <strong>
 >   <xsl:apply-templates/>
 >   </strong>
 >   </xsl:template>
 > 
 >   <xsl:template match="section">
 >   <caps>
 >   <emph>
 >   <xsl:apply-templates/>
 >   </emph>
 >   </caps>
 >   </xsl:template>
 > 
 > Unfortunately, the <emph> ... </emph> tags produced but the "section"
 > template are not transformed into <strong> ... </strong> tags.  I
 > more or less understand why this is, but the best set of templates I
 > have found that do what I want are

You appear to be confusing the source tree and the result tree.  When
it's time to process a particular node in the source tree, the XSL
processor finds the xsl:template with the best matching "match"
attribute and uses the body of that xsl:template to add (or not add)
nodes to the result tree.  The <emph> in your xsl:template is added to
the result tree, and that's all that happens to it.  It doesn't get
any templates applied to it.

 >   <xsl:template match="emph" name="emph">
 >   <strong>
 >   <xsl:copy-of select="$content"/>
 >   </strong>
 >   </xsl:template>
 > 
 >   <xsl:template match="section">
 >   <caps>
 >   <xsl:call-template name="emph">
 >     <xsl:with-param name="content">
 >       <xsl:apply-templates/>
 >     </xsl:with-param>
 >   </xsl:call-template>  
 >   </caps>
 >   </xsl:template>
 > 
 > I cannot help but think there is a better way.

There are many better ways.  I gave a version earlier with a single
xsl:template.  If you really want to do it with multiple xsl:template
elements, try:

<xsl:template match="emph" name="emph">
  <strong>
    <xsl:apply-templates/>
  </strong>
</xsl:template>

<xsl:template match="section">
  <caps>
    <xsl:call-template name="emph"/>
  </caps>
</xsl:template>


Regards,


Tony Graham
======================================================================
Tony Graham                            mailto:tgraham@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9632
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.