Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting Comments by their inner xml in xpath/xsl

Given the following xml document

<root>
   <childnode0/>
   <childnode2/>
   <!--Comment1-->
   <childnode3/>
   <childnode4/>
   <!--Comment2-->
</root>

I know the xpath to select all the comments at a particular level in xsl

string xPath = "/root/comment()";

However i'd like to select a comment where the inner xml is "Comment2".

Any ideas?

Thanks

Dave

like image 319
CraftyFella Avatar asked Dec 17 '22 04:12

CraftyFella


2 Answers

This

/root/comment()[.='Comment2']

seems to work.

like image 75
Corey Porter Avatar answered Dec 19 '22 18:12

Corey Porter


maybe this would work: /root/comment()[2]

like image 43
Andrei Avatar answered Dec 19 '22 18:12

Andrei