xsl-list
[Top] [All Lists]

RE: get immediat preceeding node, if it is a comment

2002-10-04 05:47:50

It seems that any predicates after the positional predicate refer to
that node, not to the node that the predicates before the positional
predicate refer to... 

So,

on this data:

<root>
   <!--   test     -->
   <test>test1</test>
   <test>test2</test>
   <!--   test     -->
   <test>test3</test>
   <test>test4</test>
</root>

preceding-sibling::node()[normalize-space()][1][self::comment()]

this gets 'test1' and 'test3' as we would expect

preceding-sibling::node()[normalize-space()][self::comment()][1]

this gets all of them, as they all have a preceding-sibling that returns
true for all three predicates individually

preceding-sibling::node()[normalize-space()][3][contains(self::test,'tes
t2')]

this returns 'test4' as the third preceding-sibling contains 'test2'

So is it the case that all predicates to the right of the positional
predicate refer to that node? (they change the context node)

In which case, as Joerg pointed out, it definetly does matter when the
positional predicate goes as this alters which node the following
predicates refer to.

But what about multiple positional predicates:

preceding-sibling::node()[normalize-space()]
  [3][contains(self::test,'test2')]
  [1][contains(self::test,'test2')]

this also returns 'test4', why doesnt the [1] alter the evaluation of
the second contains()?

Also, why if I change the second [1] to [2] (and even drop the final
test) does it return nothing:

preceding-sibling::node()[normalize-space()]
  [3][contains(self::test,'test2')]
  [2]

why would this fail, when this is fine:

preceding-sibling::node()[normalize-space()]
  [3][contains(self::test,'test2')]
  [1]

hmm, confused.

 

-----Original Message-----
From: David Carlisle [mailto:davidc(_at_)nag(_dot_)co(_dot_)uk]
Sent: 04 October 2002 13:03
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] get immediat preceeding node, if it is a comment



Sure.  But aren't they both the same (they select the same node)? 

No.

If you are in <a/> in 

<x>
 <a/><b>b</b><!--x--><c/>
</x>

 preceding-sibling::node()[normalize-space()][self::comment()][1]

selects the comment <!--x--> as that is the first node that is
non empty string value and is a comment.

preceding-sibling::node()[normalize-space()][1][self::comment()]

selects the empty node set as the first node with non empty 
string value
is not a comment.

David

_____________________________________________________________________
This message has been checked for all known viruses by Star Internet
delivered through the MessageLabs Virus Scanning Service. For further
information visit http://www.star.net.uk/stats.asp or 
alternatively call
Star Internet for details on the Virus Scanning Service.

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.394 / Virus Database: 224 - Release Date: 03/10/2002
 


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.394 / Virus Database: 224 - Release Date: 03/10/2002
 

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list