Re: [xsl] Understanding Identity Transformations

Subject: Re: [xsl] Understanding Identity Transformations
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Sat, 12 Feb 2005 19:28:13 +0100
Tempore 18:09:53, die 02/12/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Karl Stubsjoen <kstubs@xxxxxxxxx>:

Is the nature of identifty transformations recursive?  How does the
engine know that eventually the recursive call is going to run out?
Recursive algorithms are not a priori infinite. The copying stops when all nodes have been copied.

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
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.

Maybe you could learn be studying an example:

Consider this fictional sample:

		<!--I will be copied-->
		<node copy="yes">So do <b>I</b>.</node>
		<node copy="no">I <b>don't</b> feel like being copied today</node>

* You want an identity transform for 'part1', with the execption of 'b' which should become 'bold'
* 'part2' must be processed without any identity transform, but with templates and algorithms you define.

	<part1>		<!--I will be copied-->

		<node copy="yes">So do <bold>I</bold>.</node>
	<p>I don't feel like being copied today</p>
	<p>Sum= 6</p>

How can this be achieved, while we don't have to be afraid of templates messing up each-other? By using modes:

<xsl:stylesheet xmlns:xsl=""; version="1.0">

<xsl:output method="xml" indent="yes"/>

<xsl:template match="root">
		<xsl:apply-templates select="part1" mode="IdTr"/>
		<xsl:apply-templates select="part2"/>

<xsl:template match="node">

<xsl:template match="data">
	<p>Sum= <xsl:value-of select="sum(value)"/></p>

<xsl:template match="@* | node()" mode="IdTr">
     <xsl:apply-templates select="@* | node()" mode="IdTr"/>

<xsl:template match="b" mode="IdTr">


Joris Gillis (
Gaudiam omnibus traderat W3C, nec vana fides

Current Thread