This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Fwd: complex XPATH test


Nate,

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"
>select="$containing-block/descendant::node()[.=current()]/position()"/>
>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?

Cheers,
Wendell

======================================================================

Wendell Piez                            mailto:wapiez@mulberrytech.com
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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]