[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: Wed, 09 May 2001 11:49:52 +0900 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] IE msXML scripting Q on s, Chris Bayes | Thread | Re: [xsl] How to avoid applying tem, Jeni Tennison |
[xsl] IE msXML scripting Q on seara, Walter Torres | Date | [xsl] XSL Processors supporting XPa, Kavithak |
Month |