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(_at_)CraneSoftwrights(_dot_)com
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
--~------------------------------------------------------------------
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>
--~--