XPATH Basic question

B

bjam

Hi, a quick basic question here on XPATH

if I have the following data

<X>
<X1>TEST</X1>
<Z>
<Z1>Item 1</Z1>
<Z2>Item 2</Z2>
<Z3>Item 3</Z3>
</Z>
</X>
<X>
<X1>TEST2</X1>
<Z>
<Z1> ... </Z1>
<Z2> ... etc.
</Z>
</X>

will the following XPATH statement be valid in a template match
statement? My experience has been no, and I have had to get the root
node X and then do an if on X1 before processing. See below for the
statement. Any ideas on how to get this to work in a single XPATH
statement?


<xsl:template match="/X/X1[starts-with(text(),'TEST2']/Z">
<!-- assumption here is that I get the <Z> node to process -->
<!-- however I am thinking that the predicate has to be the last
statement in an XPATH statement, is this true?-->
 
D

Dimitre Novatchev

bjam said:
Hi, a quick basic question here on XPATH

if I have the following data

<X>
<X1>TEST</X1>
<Z>
<Z1>Item 1</Z1>
<Z2>Item 2</Z2>
<Z3>Item 3</Z3>
</Z>
</X>
<X>
<X1>TEST2</X1>
<Z>
<Z1> ... </Z1>
<Z2> ... etc.
</Z>
</X>

will the following XPATH statement be valid in a template match
statement? My experience has been no, and I have had to get the root
node X and then do an if on X1 before processing. See below for the
statement. Any ideas on how to get this to work in a single XPATH
statement?


<xsl:template match="/X/X1[starts-with(text(),'TEST2']/Z">
Yes.

<!-- assumption here is that I get the <Z> node to process -->
<!-- however I am thinking that the predicate has to be the last
statement in an XPATH statement, is this true?-->

No.


Cheers,
Dimitre Novatchev
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,231
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top