1

Consider this xml:

<parent>
    <child name="alpha" />
</parent>

and also this xml

<parent>
    <child name="beta" />
</parent>

There should be only a sinlge node at /parent/child with either alpha or beeta as it's name value.

To clarrify... there will never be 2 child nodes one each named alpha and beta

I'm trying to create a single xpath query which will return the value of name in each of these 2 cases.

I tried this...

/parent/child[@name='alpha' | @name='beta']/@name

...but it does not work.

How should I return this value..?

Update: I ammendedd the samples to ensure they were well formed as one answer indicated they were not.

Rory Becker
  • 15,551
  • 16
  • 69
  • 94

2 Answers2

7

Try with:

/parent/child[(@name='alpha') or (@name='beta')]/@name

It should also work without the parentheses.

rslite
  • 81,705
  • 4
  • 44
  • 47
1

The XML doesn't appear to be well-formed, it should be:

<parent>
    <child name="alpha"/>
</parent>

<parent>
    <child name="beta"/>
</parent>

If the XML isn't well-formed, I wouldn't expect much else to work..

James Goodwin
  • 7,360
  • 5
  • 29
  • 41
  • Absolutely correct. I have readjusted the original sample to be well formed. The Actual data was well formed however so the problem still remained. However the question is now answered by rslite. Upvoting you anyway because this could well help someone else. – Rory Becker Oct 09 '09 at 13:51