cancel
Showing results for 
Search instead for 
Did you mean: 

xpath substring expression

Former Member
0 Kudos

Hi,

I need to get a substring from a xml document via xpath expression which has data. Can someone help.

Here's the data and what I want to do is via xpath expression return "20" only (1 thru 2nd position) of the BookingCode node.

Not sure how to substring via xpath expression.

Thanks for your help


 <?xml version="1.0" encoding="UTF-8" ?> 
 <ns0:BookingOrders xmlns:ns0="urn:prueba:abap_mapping">
  <Order>
   <BookingCode>20Y34L</BookingCode> 
   <Passenger>
    <Name>Smith</Name> 
    <Address>123 Main St.</Address> 
   </Passenger>
   <Flight>
    <Date>04042004</Date> 
    <AirlineID>SX</AirlineID> 
    <FlightNumber>21</FlightNumber> 
    <From>ZRH</From> 
    <To>FRA</To> 
   </Flight>
  </Order>
 </ns0:BookingOrders>

This Xpath expression does not work

<b>/p1:BookingOrders/Order/BookingCode[(substring(.,2)]</b>

With the second operand = "20"

Accepted Solutions (0)

Answers (3)

Answers (3)

udo_martens
Active Contributor
0 Kudos

Hi Luis,

it is

substring(//Order/BookingCode,1,2)

Regards,

Udo

stefan_grube
Active Contributor
0 Kudos

Check this blog:

/people/shabarish.vijayakumar/blog/2006/06/07/customise-your-xpath-expressions-in-receiver-determination

You can do your request similar.

Regards

Stefan

Former Member
0 Kudos

Normal usage for XPath function is

substring-before(<xpath>,arg1,arg2)

So usage would be something like

substring-before("/p1:BookingOrders/Order/BookingCode","Y")

But question wherein context are you calling this fucntion?

Assuming its an XSL mapping.. then u wud call this within <xsl:value-of select="...> stmt.

Shabarish_Nair
Active Contributor
0 Kudos

/people/shabarish.vijayakumar/blog/2006/06/07/customise-your-xpath-expressions-in-receiver-determination

Chk tht blog. It sud give you an idea of how to build ur xpath query.

Former Member
0 Kudos

Hi,

You have missed on one closing bracket. Try this:

/p1:BookingOrders/Order/BookingCode[(substring(.,2))]

/p1:BookingOrders/Order/BookingCode[substring(.,2)]

Regards

vijaya