xsl-list
[Top] [All Lists]

Re: [xsl] replacing nodes during xsl:copy-of

2011-01-06 08:06:46
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. ________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--