Michael Vincent
Michael Vincent

Reputation: 1660

How do I use starts-with with an attribute value?

My xml look a bit like this ...

<DataItems>
  <DataItem name="Order Number" type="string">ABC1234</DataItem>
  <DataItem name="Customer Id" type="integer">667744</DataItem>
  <DataItem name="Customer Name" type="string">Ronnie Pickering</DataItem>
</DataItems>

I'm trying to use XPath 1.0 to return a boolean based on whether the Order Number start with a certain string - "ABC"

I can't figure it out at all. Help, please.

Upvotes: 0

Views: 424

Answers (1)

kjhughes
kjhughes

Reputation: 111621

This XPath,

//DataItem[@name='Order Number' and starts-with(., 'ABC')]

will return all DataItem elements whose name is 'Order Number' and whose string value starts with 'ABC'.

Upvotes: 1

Related Questions