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

Re: Copy excluding some children

Subject: Re: Copy excluding some children
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 20 Oct 2008 15:59:41 -0400
Re:  Copy excluding some children
At 2008-10-20 21:37 +0200, Giacomo wrote:
Is there a way to copy an element excluding some children, at any depth,
using *only* an XPath 2.0 expression without using templates to exclude
such elements?

XPath doesn't copy elements, it only addresses or queries them.


If you had such an XPath expression, how would you use it?

I think you may be misunderstanding the role of XPath to talk about a tree. For example, I can use XPath to *find* all of the elements at any depth not including C and D:

T:\ftemp>type giacomo.xml
<A>
   <B>The pen is <C>not</C> on the table</B>
   <D>...</D>
</A>
T:\ftemp>type giacomo.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="2.0">

<xsl:output method="text"/>

<xsl:template match="/">
  <xsl:for-each select="//* except ( //C | //D )">
Found: <xsl:value-of select="name(.)"/>
  </xsl:for-each>
</xsl:template>

</xsl:stylesheet>
T:\ftemp>xslt2 giacomo.xml giacomo.xsl con

Found: A
Found: B
T:\ftemp>


But now what are you going to do with those nodes once you've addressed them?


In XSLT if you try and use <xsl:copy-of/> that is defined to copy the *entire* structure of *each* element, getting descendent elements twice.

So, you can use XPath to *find* information, but it has no role in copying information, only whatever specification might be using XPath to find information.

I hope this helps.

. . . . . . . . . Ken

For example, given:

<A>
   <B>The pen is <C>not</C> on the table</B>
   <D>...</D>
</A>

I want to copy A without C and D obtaining:

<A>
   <B>The pen is on the table</B>
</A>


Thanks, Giacomo.


--
Upcoming XSLT/XSL-FO hands-on courses:      Wellington, NZ 2009-01
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video sample lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg
Video course overview:  http://www.youtube.com/watch?v=VTiodiij6gE
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

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.