hi
I have a XML that I need to store, and the topic is set according to a code.
e.g for /Root/Data/Code = 1 the topic is "Fantasy", for /Root/Data/Code = 2 the topic is "Detective"
I use org.apache.xpath, the Xpath version is 2.0
I thought I could use replace function like this:
Object result = XpathApi.eval(doc, "replace(replace(/Root/Data/Code,'1','Fantasy'),'2','Detective')");
But the replace function is not defined in this version of Xpath. (The exception was: javax.xml.transform.TransformerException: Could not find function: replce)
The solution I found was this:
Object result = XpathApi.eval(doc, "concat(substring-before(concat(string('Fantasy'),/Root/Data/Code), '1'), substring-before(concat(string('Detective'),/Root/Data/Code),'2'))");
Please tell me there is a better way.
Thanks