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

The use of xsl:copy (Was RE: Retraction: I've modified my pa

Subject: The use of xsl:copy (Was RE: Retraction: I've modified my parser to copy attributes. )
From: Khun Yee Fung <KFung@xxxxxxxxxx>
Date: Wed, 12 Apr 2000 12:39:15 -0400
retraction template
The <xsl:copy> element is actually a rather nice element to use in the cases
where you want to handle only part of an XML tree. The <xsl:copy> element
gives you the ability to not know much of the current node and yet allow you
to copy it to the result tree.

Suppose you have an XML document with an element and its descendents that
you want to remove. Suppose the name of the element is called 'remove'. You
want to keep the rest of the XML tree in the result tree.

These are the templates I use to perform that:

<xsl:template match='/'>
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match='remove'/>

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

(xt says node() is not implemented in step patterns so the above templates
are no good for xt. Saxon and Xalan have no problem with it.)

The <xsl:copy> element is also not redundant in the specific example you
showed here. The element copies the current node to the result tree without
knowing much about what the current node is (according to the value of the
match attribute, it can be any kind of node). If the current node is an
element, <xsl:copy> will construct an element in the result tree. If it is
an attribute, <xsl:copy> will construct an attribute and put it inside the
containing element. The <xsl:copy> element handles the other types of nodes
too.*

Regards,
Khun Yee

* My version of Xalan (1.0.3) strips comments from the input tree when the
above templates are used. Saxon does not. Both do not strip processing
instructions. I wonder which behaviour is proper.


-----Original Message-----
From: Dan Morrison [mailto:dman@xxxxxxxx]

I've been directed to the spec 7.5:
-----------------------------------
For example, the identity transformation can be written using xsl:copy
as follows:

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

... which implies my construct is fine ( s/@/@*/ ) so apologies all.
I'd referred to only xsl:copy-of & xsl:attribute.

Isn't 'xsl:copy' a bit redundant?


 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.