[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: Joakim Norlov <jn@xxxxxxxxxxxxxx>
Date: Wed, 09 May 2001 11:49:52 +0900
proc template
Thank you for your help, Jeni.

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.
For instance, if there is a CARE node as a descendant, and this CARE node has a specific
template, that is adding wrapping tags around the CARE element, it will not be applied in
your solution. It will just be copied through as a CARE element, without the wrapping tags.
Again, some code to clarify what I'm talking about:

<xsl:template match="CARE">
<!-- adding wrap tags -->
   <CAREWRAP>
      <xsl:copy>
         <xsl:copy-of select="@*"/>
         <xsl:apply-templates/>
      </xsl:copy>
   </CAREWRAP>
</xsl:template>

I have a bunch... a BIG bunch... of templates like this, and they all have to apply to the
descendant nodes of the ATLAS node. Of course I don't want to make "mode='copy'" copies of
all of these templates.

Input/Output:

<ATLAS>
   <PROC>
      <PAR ATTR="Subject III">
         Blabla 1
      </PAR>
      <CARE>
         Blabla 0
      </CARE>
   </PROC>
   <PROC ATTR="Subject I">
      Blabla 2
   </PROC>
   <PAR ATTR="Subject II">
      Blabla 3
   </PAR>
   <PROC>
      <PAR ATTR="Subject II">
         Blabla 4
      </PAR>
   </PROC>
</ATLAS>

should turn out to be

<ATLAS ATTR="Subject III">
   <PROC>
      <PAR ATTR="Subject III">
         Blabla 1
      </PAR>
      <CAREWRAP>
         <CARE>
            Blabla 0
         </CARE>
      </CAREWRAP>
   </PROC>
   <PROC>
   </PROC>
</ATLAS>
<ATLAS ATTR="Subject I">
   <PROC>
      <CAREWRAP>
         <CARE>
            Blabla 0
         </CARE>
      </CAREWRAP>
   </PROC>
   <PROC ATTR="Subject I">
      Blabla 2
   </PROC>
   <PROC>
   </PROC>
</ATLAS>
<ATLAS ATTR="Subject II">
   <PROC>
      <CAREWRAP>
         <CARE>
            Blabla 0
         </CARE>
      </CAREWRAP>
   </PROC>
   <PAR ATTR="Subject II">
      Blabla 3
   </PAR>
   <PROC>
      <PAR ATTR="Subject II">
         Blabla 4
      </PAR>
   </PROC>
   <PROC>
   </PROC>
</ATLAS>

So when you use the following template, it "swallows" whatever element it finds, not caring
if it's a CARE element, or any other special element.

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

I hope you now see my REAL dilemma.

/Joakim



 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.