RE: [xsl] position() test for processing boundaries

Subject: RE: [xsl] position() test for processing boundaries
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 19 Nov 2004 15:55:53 -0500
Hey Ron,

To add to what Mike says, if you don't have the option of using XPath 2.0, you could work around the difficulty he describes with xsl:copy-of by using xsl:apply-templates instead (probably with a mode), and using the templates then applied to further constrain exactly what you want to happen. Maybe you want to use xsl:copy instead of copy-of (which will do a "shallow copy" of the current node only, not a "deep copy") -- which you could do in any templates matching in the applied mode.

It's nice to see all those apps and rdgs.

Cheers,
Wendell

At 08:47 AM 11/19/2004, Mike wrote:
The test is the same in both cases. The third item in .//* is the <rdg
n="3"> element. The two elements before this are the <q n="1"> element and
the <app n="2"> element, and you have obtained deep copies of these two
elements, just as you requested.

However, this isn't going to help with your problem. Doing xsl:copy-of gives
you a deep copy of all the selected nodes, and therefore xsl:copy-of
select=".//*" is going to contain many duplicated nodes: each element will
be copied once its own right, and once as a side-effect of copying its
parent, once when copying its grandparent, and so on.

This kind of problem becomes much easier with the << and >> operators in
XPath 2.0. Select the first and last nodes you want to process (say A and
B), and then you can process all the required nodes using

select="$A | //*[. >> $A and . << $B] | $B"

Michael Kay
http://www.saxonica.com/


======================================================================
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