Subject: [xsl] Re:Excluding a complete branch while identity copying From: "Fraser Goffin" <goffinf@xxxxxxxxxxxxxx> Date: Sat, 11 Oct 2008 18:17:59 +0100 |
Thanks Wendell (and Ryan). I see where I was going wrong. But does raise a couple of further questions as you suspected it might. I was using something similar but with different results. I had this template to exclude 'Evens' and this identity (copy) template :- <xsl:template match="Evens"> <xsl:apply-templates/> </xsl:template> <xsl:template match="*|@*|text()"> <xsl:copy-of select="."/> </xsl:template> The problem that you have helped me spot is the 'apply-templates' inside the Evens template, results in all of 'Evens' children being processed, which then led me down the path of defining similar templates for each child and ultimately to the text() node for each of these. <xsl:template match="Evens"> <xsl:apply-templates/> </xsl:template> <xsl:template match="Evens/Four"> <xsl:apply-templates/> </xsl:template> <xsl:template match="Four"> <xsl:apply-templates/> </xsl:template> <xsl:template match="Four/text()"> <xsl:apply-templates/> </xsl:template> Whilst this does produce the correct result it is very messy and unnecessary. I think the problem here (for me) was forgetting that (in this 'recursive descent' style) the sytlesheet is defining the output rather than controlling the way that input is processed (i.e. I was thinking procedurally). So we get to the questions to clarify the behaviour :- 1. I had put apply-templates into the 'exclude this node' templates because I was mistakenly thinking that unless I did that the processing of the input would stop. So the clarification is, when you're not taking control of how the input is processed (by NOT using apply-templates but explicitly pulling data from the input) then the XSLT processor continues through the input document in a recursive fashion from top to bottom and nodes are either processed by specific templates that contain a match expression that selects that node, or they are processed by the default template rules. Is that correct ? 2. The 'near' identity template that I used does appear to produce the same results as the one you provided. I suspect that the one provided by Ryan does also (thanks Ryan) :- MINE :- <xsl:template match="*|@*|text()"> <xsl:copy-of select="."/> </xsl:template> YOURS :- <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> RYANs :- <xsl:template match="@*|*"> <xsl:copy> <xsl:apply-templates select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> Can you tell me which one of these is prefable and why ? Thanks Fraser.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] document tree fragments, Joe Barwell | Thread | Re: [xsl] Re:Excluding a complete b, G. Ken Holman |
Re: [xsl] document tree fragments, G. Ken Holman | Date | Re: [xsl] Re:Excluding a complete b, G. Ken Holman |
Month |