[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re:Excluding a complete branch while identity copying

Subject: Re:Excluding a complete branch while identity copying
From: "Fraser Goffin" <goffinf@xxxxxxxxxxxxxx>
Date: Sat, 11 Oct 2008 18:17:59 +0100
 Re:Excluding a complete branch while identity copying
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.