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

Re: replacing nodes during xsl:copy-of

Subject: Re: replacing nodes during xsl:copy-of
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 06 Jan 2011 14:06:35 +0000
Re:  replacing nodes during xsl:copy-of
On 06/01/2011 13:52, Mark Anderson wrote:
Hi Guys

Thanks for the replies. Not sure why I'm having such a hard time getting my head around this. I couldn't get either of the proposed solutions to work, but it may just be a fundamental misunderstanding.

From a high-level, non-technical, viewpoint, what I need to do is convert the XML to HTML and either during the process, or after replace everything in the<replace> elements with something else. I'm guessing a 2-stage process is not the way to do it.

I'm using a pull approach rather than a push approach to do the transformation as the output is different depending on the nesting level. Each section can have text nodes (that contain HTML tags that I need to preserve). Any node can have a<replace> element in it.


My xsl is basically

<apply-templates select="Chapter">
	<xsl:copy-of select="text">
	<apply-templates select="Section">
		<xsl:copy-of select="text">	
		<apply-templates select="Sub-Section">
			<xsl:copy-of select="text">	
			<apply-templates select="clause">
			<xsl:copy-of select="text">	

It's a bit hard to guess what you mean by the above, as apply-templates can not take apply-templates of copy-of as children.



You don't want all those select= attributes, just use <apply-templates/> or equivalently <apply-templates select="node()"/> to let xslt walk the tree in the correct order, otherwise you will get:

If I just use<apply-templates select="replace"> the replaced text is all in the wrong place in the output stream.



So can I use a 2-stage approach: e.g. use identity transform to convert all<replace> elements to required text and then feed this transformed output to my current transforms?

No need to do that, just do it in one pass, use the identity template (matching "*") so that most stuff gets copied, then have a template matching "replace" (which will have a higher priority) that does your replacements. the output of that template will be naturally inserted at the place corresponding to teh position of the replace element in the source.


David



________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. ________________________________________________________________________


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.