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

Re: copy-of too powerful or wrong

Subject: Re: copy-of too powerful or wrong
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 09 Aug 2004 17:04:37 -0400
xsl comment out

Yes, copy-of will copy an entire node subtree. In the case of your template, you are instructing that all node children of the root be copied completely to output.

What you actually want can be accomplished using xsl:copy, which copies only the current node, and not its descendants. Accordingly, having copied, you will use xsl:apply-templates to continue traversing "down" the tree, copying descendants as you go (and matching the templates that say not to copy the descendants you don't want). This is what is done by the "identity template", which you can look up in Google or any reasonably-complete reference to XSLT, and which looks like this (the variant of the moment):

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

So you are correct: xsl:copy-of is both too powerful and wrong. xsl:copy will be just right.


At 04:54 PM 8/9/2004, you wrote:
I'd like to be able to do something like this

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

<!--SUMMARY - this comments out the Summary chunk-->
<xsl:template match="/chunk/chunk[chunk-meta/title[(text()='Summary')]]"/>
<!--INSIGHTS commented out-->
<xsl:template match="/chunk/chunk[chunk-meta/title[(text()='Insights')]]"/>
<!--KEYTERMS commented out-->
<xsl:template match="/chunk/chunk[@differentiation='keyterms']"/>
<!--REVIEW QUESTIONS commented out-->
<xsl:template match="/chunk/chunk[@differentiation='review-questions']"/>
<!--INSIGHTS commented out-->
<xsl:template match="/chunk/ref-note-list[title/text()='Additional Readings']"/>

Where the first template match copies everything and the additional template matches comment out those specific chunks. It doesn't work - as you could guess. But I do not know why - I am a beginner and copy-of is very powerful - too powerful. I am looking to rebuild the xml (transformed) using copy-of - is that the wrong thing to do?

Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
  Mulberry Technologies: A Consultancy Specializing in SGML and XML

Current Thread


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.
First Name
Last Name
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.