Re: [xsl] Understanding Identity Transformations

Subject: Re: [xsl] Understanding Identity Transformations
From: Karl Stubsjoen <kstubs@xxxxxxxxx>
Date: Sat, 12 Feb 2005 10:09:53 -0700
Thanks for all the help.
Dimitre:  this is where I was to get all of my samples, and then also
this list : )

Now that I think I have a good understanding of the identity
transform, except one final question, and that is:

Is the nature of identifty transformations recursive?  How does the
engine know that eventually the recursive call is going to run out?

Now the what I really need do question.  Which is:

I have a large document, I am interested in transforming it.  I want
to reproduce the xml source but restricted for a specific value match.
 I totally understand how to write the appropriate select in an
apply-template rule to get the desired results, but do not understand
how to mix this call up with the recursive template identity
tranformation.
So, starting with SAMPLE_002, where would I stub out and add the
qualifying select?  What confuses me, is that in the sample we are
saying (basically) grab everything from the top to the bottom and at
every level.  I'm affraid that my select on an element who's value is
'1234' is going to mess up the results.  I hope this makes sense and I
understand the concept of changing a single element, or single
attribute by setting up the match, but in this case, I need the parent
node, and all of the child nodes.

Thanks.


On Sat, 12 Feb 2005 11:30:49 +0100, Joris Gillis <roac@xxxxxxxxxx> wrote:
> Tempore 23:56:58, die 02/11/2005 AD, hinc in
> xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Karl Stubsjoen <kstubs@xxxxxxxxx>:
> 
> > Seems like this is pretty standard:
> >
> > SAMPLE_001:
> > <xsl:template match="node()|@*">
> >   <xsl:copy>
> >     <xsl:apply-templates select="@*"/>
> >     <xsl:apply-templates/>
> >   </xsl:copy>
> > </xsl:template>
> >
> > But then I've also seen this:
> >
> > SAMPLE_002:
> > <xsl:template match="/ | @* | node()">
> >    <xsl:copy>
> >      <xsl:apply-templates select="@* | node()"/>
> >    </xsl:copy>
> > </xsl:template>
> >
> > How do they compare?  I make not of the SAMPLE_001 within the xsl:copy
> > there are 2 apply templates, what does each do?
> 
> Since <xsl:apply-templates/> is an abbreviation for <xsl:apply-templates
> select="node()"/>, and attributes occur first in document order, the two
> consecutive 'apply-templates' of the first simple do exactly the same as
> the one 'apply-templates' in sample 2.
> 
> As for the extra '/' in the second sample, I don't think it is necessary.
> 
> > Then, understanding what is happening, is the following sample true
> > that this will strip an XML doc of all attribute elements?
> >
> > SAMPLE_003:
> > <xsl:template match="*">
> >   <xsl:copy>
> >     <xsl:apply-templates select="*"/>
> >   </xsl:copy>
> > </xsl:template>
> >
> Yes indeed, it will strip off attributes BUT also text nodes, comments,
> processing instructions...
> (only elements will remain)
> 
> 
> > And finally, when I identity transform the following my document i
> > quadrupled in size, but I though I was following standard practices
> > from previous example.
> >
> > SAMPLE_004:
> > <xsl:template match="*">
> >   <xsl:copy>
> >     <xsl:apply-templates select="*"/>
> >     <xsl:apply-templates />
> >   </xsl:copy>
> > </xsl:template>
> >
> 
> > Ahh, I think I understand what is going on in SAMPLE_004 (please
> > confirm) I am basically applying templates for all nodes twice
> 
> Not entirely true. You first apply templates to all child element nodes.
> And then you apply all child node (including again the elements)
> 
> regards,
> --
> Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
> Gaudiam omnibus traderat W3C, nec vana fides

Current Thread