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

Re: Understanding Identity Transformations

Subject: Re: Understanding Identity Transformations
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Sat, 12 Feb 2005 19:28:13 +0100
xsl identity tranformation
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
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.

Maybe you could learn be studying an example:


Consider this fictional sample:

XML:
<root>
	<part1>
		<!--I will be copied-->
		<node copy="yes">So do <b>I</b>.</node>
	</part1>
	<part2>
		<node copy="no">I <b>don't</b> feel like being copied today</node>
		<data>
			<value>1</value>
			<value>2</value>
			<value>3</value>
		</data>
	</part2>
</root>

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


OUTPUT:
<result>
	<part1>		<!--I will be copied-->

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

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="http://www.w3.org/1999/XSL/Transform" version="1.0">

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

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

<xsl:template match="node">
	<p><xsl:apply-templates/></p>
</xsl:template>

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

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

<xsl:template match="b" mode="IdTr">
	<bold><xsl:apply-templates/></bold>
</xsl:template>

</xsl:stylesheet>

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
Gaudiam omnibus traderat W3C, nec vana fides

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.