Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to do an xpath OR on nodes? 1

Status
Not open for further replies.

lookitsdre

Programmer
Jun 18, 2008
3
US
Hi Tek-Tips Users,

Greetings from a first poster.

I'm trying to do an xpath on an xml file that has two possible paths. One is :
//ja:head/ce:title

and the other is
//ja:simple-head/ce:title

Is it possible to combine the two? I've tried :
//ja:head|ja:simple-head/ce:title
and
//(ja:head|ja:simple-head)/ce:title

but neither seems to work?
Any tek-tips?(haha)

Thanks!
Andre

 
It is supported in xslt 2.0. Make sure you declare the version in the xslt document and use xslt2 processor. The expression
[tt] //(ja:head|ja:simple-head)/ce:title[/tt]
 
I thought you were doubting xpath/xslt 2.0. But if you mean generally, it is supported since xslt/xpath 1.0.
 
tsuji,
Thanks for responding.

When I set it as //(ja:head|ja:simple-head)/ce:title, I get an xsl error about formatting with ( from the compiler. This is .net 2.

I tried to set the xsl to version 2 by switching <xsl:transform version="1.0" to <xsl:transform version="2.0" but I still get the same error.

Tho I interpret your last comment to mean that its already in xpath 1? So it should work anyway.

Any more thoughts?
 
In .net, try to compile instead this as xpath.
[tt] "//ja:head/ce:title|//ja:simple-head/ce:title"[/tt]
 
Tsuji,

Thanks! That was right. It is a bit bloated and I'm surprised that they implement this but not the nested case. I've only got two cases so its ok.

Andre
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top