This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: How to avoid applying templates several times to the same descendant
- To: Jeni Tennison <jeni at tennison dot 2ndmail dot com>, Jeni Tennison <mail at jenitennison dot com>, XSL Mailing list <XSL-List at lists dot mulberrytech dot com>
- Subject: Re: [xsl] How to avoid applying templates several times to the same descendant
- From: Joakim Norlov <jn at uniscope dot co dot jp>
- Date: Wed, 09 May 2001 11:49:52 +0900
- References: <E14x2zX-0002tg-00@mutsuki>
- Reply-To: xsl-list at lists dot mulberrytech dot com
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