Over a million developers have joined DZone.

Find And Replace Inside An XML File With XSLT

// description of your code here
//This XSL will search inside certain nodes of a given XML file
//for certain values and replace them.
//In my example I have a UnitOfMeasure node that contains "EA" or "FT" but I want to change
//the EA to 1 and the FT to 0.
//Also in my ObsoleteIndicator node I want to replace OBS with 1 and this other value I don't care about, 
//DNR to empty string to basically remove it.
//So we end up with the exact same XML we started with just with those values translated.
//You could do the same with regular string.replace but it would be very slow for large XML files
//as it would have to visit every character in the entire file each time you called it (in my case
// four times.)






Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}