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

Re: node selection problem

Subject: Re: node selection problem
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 10 Mar 2004 11:46:47 -0500
selection node
Jakob,

Mike suggested using a processor that supports intersection, which is an excellent approach.

If you must use unextended XSLT 1.0, keys can help. Associate the nodes you want (in your illustration the "X" nodes) with their "owner" using its generated id; then when processing you can grab all the X nodes with their owners.

For the illustrated case the key declaration would look something like:

<xsl:key name="X-by-owner" match="X" use="generate-id((ancestor::sub|ancestor::chap)[last()])"/>

which assigns to each X a key value representing the unique id of the closest sub or chap ancestor.

Then when you match "chap" you can select="key("X-by-owner", generate-id())" and get back just the X nodes you want.

Setting up that key to your particular criteria can be a bit tricky, and will exercise your XPath skills.

Good luck,
Wendell

At 03:16 AM 3/10/2004, you wrote:
Hi,

I would like to retrieve all the nodes "X" inside one
node, but before another node.  The second node is always
a descendant of the first node.

book
+-- chap
+-- chap            <== inside this node
    +-- X           <== select this node
    +-- sect
        +-- X       <== select this node
        +-- sub     <== but before this node
            +-- X   <== i.e. do not select this X node
        +-- sub
        ...
    +-- sect
    +-- sect
    ...
+-- chap
...


This example is somewhat simplified, of course. Currently, my best bet is this:

<xsl:variable name="inside.this.node"
select="/book/chap[2]"/>
<xsl:variable name="before.this.node"
select="$inside.this.node/sect[1]/sub[1]"/

<xsl:variable name="the.X.nodes"
  select="$before.this.node/preceding::X[
    ancestor::*[@ID=$inside.this.node/@ID]
  ]"
/>

This method doesn't seem very efficient given that it must
first select all preceding X nodes, and then filters this
nodeset using the predicate that matches ID values.

As I have to do this many times over a big document, I
would be interested in better ways.


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


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.