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

Re: How to avoid applying templates several times to t

Subject: Re: How to avoid applying templates several times to the same descendant
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 9 May 2001 09:14:52 +0100
avoid default template xsl
Hi Joakim,

> Sadly, it didn't solve all my problems. Your solution still doesn't
> consider other special templates that have to apply to descendants
> of the ATLAS node.

In my solution, the templates are applied in 'copy' mode, with the
default template being:

<xsl:template match="*" mode="copy">
   <xsl:param name="attr" />
   <xsl:if test="not(@ATTR) or @ATTR = $attr">
      <xsl:copy>
         <xsl:copy-of select="@*" />
         <xsl:apply-templates mode="copy">
            <xsl:with-param name="attr" select="$attr" />
         </xsl:apply-templates>
      </xsl:copy>
   </xsl:if>
</xsl:template>

If you want to override that default template, then you need to add
another template, still in copy mode, that matches the nodes that you
want to override it for, so for example:

<xsl:template match="CARE" mode="copy">
   <xsl:param name="attr" />
   <!-- adding wrap tags -->
   <CAREWRAP>
      <xsl:copy>
         <xsl:copy-of select="@*"/>
         <xsl:apply-templates mode="copy">
            <xsl:with-param name="attr" select="$attr" />
         </xsl:apply-templates>
      </xsl:copy>
   </CAREWRAP>
</xsl:template>

Note here that I am still passing the $attr parameter through the
templates, so that if a CARE element has a child that has an @ATTR
attribute that is *not* equal to the value that you're using for the
particular copy then it will not be copied.

However, I think that if you already have all the templates that you
want for certain descendants of ATLAS, then you're probably not
concerned about the @ATTR attribute on those descendants or their
descendants - is that right? If so, I doubt you want to go through
adding 'copy' modes to all of them, so you're better off using Jarno's
solution, which didn't use modes.

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 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.