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

Re: deep "copy-of" a source fragment

Subject: Re: deep "copy-of" a source fragment
From: Peter Davis <pdavis152@xxxxxxxxx>
Date: Wed, 4 Sep 2002 00:06:13 -0700
deep copy xsl
On Tuesday 03 September 2002 23:48, Terence Kearns wrote:
> but if I change
> 	match="/"
> to
> 	match="/html/body"
>
> then I get leaf nodes again :(
> I also tried
...
> makes no difference if I change
>
> 	select="node()"
> to
> 	select="."
> or
> 	select="@*|node()"
>
> Is there no way at all to copy a fragment from the source tree onto the
> result tree?!

The problem is, if you have:

<xsl:template match="/html/body">
  ...
</xsl:template>

then the default template will be applied to all the nodes that aren't part of 
/html/body.  The default template is to copy text nodes and ignore everything 
else, so that might explain your problem.

Instead of changing select to select="node()" and match="/html/body", you 
should try,

<xsl:template match="/">
  <xsl:copy-of select="html/body/node()"/>
</xsl:template>

If that doesn't work, then I don't know what's wrong.

An alternative to using copy-of is to use the "identity template", which can 
look something like this (untested):

<!-- ignore all nodes unless otherwise specified -->
<xsl:template match="node()" priority="0"/>

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

You might want to go this route if you ever want to apply other templates to 
specific elements in the /html/body//* tree.  Using xsl:copy-of doesn't allow 
you to modify the output of the copy with other templates.  If you don't 
think you'll ever need to apply other templates, then copy-of should work 
fine.

-- 
Peter Davis

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.