1

Imagine this XML file (sorry for sick example!!)

<DOC>
<Test>
    <Name>1 vs 100 Pre pre History</Name>
    <Type>Dinasors</Type>
</Test>

<Test>
    <Name> 1 vs 100 Post moderns</Name>
    <Type>Aliens</Type>
</Test>
</Doc>

The idea is returning the Type value, By checking if Name node contains a specific character or string. For example I want a XPath Query like:

/Doc//Test[contains "Pre" and "History" and 1]/Type

That is check if Test contains "Pre" and "History" and number 1, What will be the xpath query? Alo I like this query to not be CASE SENSITIVE.

Thanks.

Saeid Yazdani
  • 13,065
  • 50
  • 172
  • 279

2 Answers2

2

I think this should work (haven't tested it):

/Doc//Test[contains(Name,'Pre') and contains(Name,'History') and contains(Name,1)]/Type

However that is case sensitive. If you want it case insensitive, then you may want to have a look at this question or this question: you must use translate to convert your Name to lower-case (or upper-case) and then match.

Community
  • 1
  • 1
MarcoS
  • 13,110
  • 6
  • 39
  • 62
  • 2
    +1 Correct, but do note tha `//` operator is not needed. Also it could be reduce to `/Doc/Test[Name[contains(.,'Pre')][contains(.,'History'][contains(.,'1')]]/Type` –  Apr 12 '11 at 15:06
0

it works when:

/Doc//Test[contains(Name,'Pre')][contains(Name,'History')][contains(Name,1)]/Type;
Bkillnest
  • 712
  • 8
  • 16