RE: Fwd: [xsl] complex XPATH test

Subject: RE: Fwd: [xsl] complex XPATH test
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 17 Jul 2001 16:04:26 -0400

Nice go at it.

At 02:58 PM 7/17/01, you wrote:
For starters, there has to be a better way of returning the position of a
node within a node set than what I used here (the for-each block).  Anyone
have any ideas?  I tried
<xsl:variable name="currPos"
knowing it wouldn't work (from previous posts to the list, etc.) and I
wasn't disappointed.

The name of the function, position(), is somewhat misleading here, as it really has nothing to do with the position of a node in a node set, but rather of the context node within the current node list.

Closer would be (count(preceding-sibling::node()) + 1), if you only want to count nodes within a given level. Unfortunately, I think this problem is a bit tougher. What you want is more like (count($containing-block/descendent::node()[ ... ]) with a predicate that will filter out the ones before the current node. Still tricky to write, still slow.

  So the question I have is:  How do you return the
position of a node in a node set given the node and the node set, so that
the position can be used in a comparison or a variable?
Second, why is it that ".=$curr" tests the value of each against each other,
rather than a 'node id' or something?  Wouldn't it make sense for that to
actually check that the nodes are equivalent since if I wanted to check
their string values I could do "string(.)=string($curr)" but I can't do the
reverse. (ie. "node(.)=node($curr)" or something).  I'm I overlooking
something here?

A true node identity test would be very useful for this as for similar problems. That's just not the way = works in XSLT 1.0.

Solutions to similar problems have approached it by using, e.g., generate-id() to do node comparisons for identity. I can imagine creative uses of <xsl:number> that could be used to calculate priority etc., but still slow and klugey.

Where are the mathematicians?



Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.      
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:

Current Thread