This project is read-only.

Regd. replace() and translate() functions in XPATH

Oct 7, 2009 at 1:12 PM

Hi,

I have an XML like this:

<?xml version="1.0"?>
<purchaseOrder orderDate="1999-10-20">
    <shipTo country="US">
        <name>Alice Smith</name>
        <street>123 Maple Street</street>
        <city>Mill Valley</city>
        <state>CA</state>
        <zip>90952</zip>
    </shipTo>
</purchaseOrder>

I need to replace a string with another string. I tried the following XPath expression with replace but it doesn't work and throws me an error.

/purchaseOrder/shipTo[replace(name, 'Alice','James')]/name

Alternatively, I have tried using translate.

/purchaseOrder/shipTo[replace(name,'Ali','ilA')/name

but the output I 'm getting is Alice Smith only. Could some one give me a suggestion about how to get characters replaced using xpath. I believe the version of XPath I 'm using is 1.0.

 

Regards,

Rajesh