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

Re: [xsl] How to avoid applying templates several times to the same descendant


Subject: Re: [xsl] How to avoid applying templates several times to the same descendant
From: Joakim Norlov <jn@xxxxxxxxxxxxxx>
Date: Thu, 10 May 2001 12:28:01 +0900

I want to start by thanking both Jeni and Jarno for your help.

In Jeni's last post, she adviced me to use Jarno's solution instead. But
Jarno's solution won't work either in special cases when specific
templates have to be applied to descendants of the ATLAS node. To show a
special case, I have expanded my example code to this:

Remember the specific template for CARE (see earlier post), that adds
wrapping tags around the CARE element:

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

So what if a CARE element would be the parent (or ancestor) of one of the
elements with an ATTR attribute?

<ATLAS>
   <CARE>
      <PAR ATTR="Subject III">
         Blabla 1
      </CARE>
      <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">
   <CAREWRAP>
      <CARE>
         <PAR ATTR="Subject III">
            Blabla 1
         </PAR>
         <CAREWRAP>
            <CARE>
               Blabla 0
            </CARE>
         </CAREWRAP>
      </CARE>
   </CAREWRAP>
   <PROC>
   </PROC>
</ATLAS>
<ATLAS ATTR="Subject I">
   <CAREWRAP>
      <CARE>
         <CAREWRAP>
            <CARE>
               Blabla 0
            </CARE>
         </CAREWRAP>
      </CARE>
   </CAREWRAP>
   <PROC ATTR="Subject I">
      Blabla 2
   </PROC>
   <PROC>
   </PROC>
</ATLAS>
<ATLAS ATTR="Subject II">
   <CAREWRAP>
      <CARE>
         <CAREWRAP>
            <CARE>
               Blabla 0
            </CARE>
         </CAREWRAP>
      </CARE>
   </CAREWRAP>
   </PROC>
   <PAR ATTR="Subject II">
      Blabla 3
   </PAR>
   <PROC>
      <PAR ATTR="Subject II">
         Blabla 4
      </PAR>
   </PROC>
   <PROC>
   </PROC>
</ATLAS>

The tags are starting to get a bit messy. Sorry about that. I just want to
illustrate the difficulties I'm facing here.
Both Jeni's and Jarno's solutions will not work with the specific
templates that are needed in my document. In Jeni's case, I would need to
add copies of ALL my templates in a "copy" mode. In Jarno's case, I would
need to add parameters and parameter passing to ALL my templates to handle
the parameter testing. Well, I don't like doing any of this. Is there not
any other way?

/Joakim Norlov



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



Current Thread