[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Re:Excluding a complete branch while identity copy
At 2008-10-11 18:17 +0100, Fraser Goffin wrote:
I was using something similar but with different results. I had this template to exclude 'Evens' and this identity (copy) template :- Yep! I think the problem here (for me) was forgetting that (in this 'recursive descent' style) the sytlesheet is defining the output I teach it more actively as "constructing 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 :- Yes, that is a mistake ... *all* nodes you push at your stylesheet get handled by your template rules or, if not present, then the built-in template rules. 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. Nope ... not quite. It isn't the XSLT processor that "continues through the input document in a recursive fashion", it is the identity template that you had defined in your stylesheet. If you hadn't had a template match for elements then the built-in template rule for elements would have acted on each element's children. Everything is in your hands to catch nodes as the come to the stylesheet ... and you even control *which* nodes come to the stylesheet. The *only* assumption made by the processor is at the very start where it pushes the root node at your stylesheet ... no other assumptions are made ... every node is then handled by your template rules or the built-in template rules. 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) :- Because leaf nodes have no children or attached nodes, the redundant <xsl:apply-templates/> never does anything for those nodes because there are never any nodes addressed to be pushed. If you wanted to avoid that redundancy, then the identity template could be split into two: <xsl:template match="*"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="@*|text()|comment()|processing-instruction()"> <xsl:copy/> </xsl:template> But then I think you are just cycle counting, and the processor probably already optimized out the addressing of child and attached nodes anyway, so you may as well keep with Wendell's use of the "traditional" identity template: <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> I hope this helps. . . . . . . . . . . . . Ken
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|