conditions in xpath

Alles, was den Apache betrifft, kann hier besprochen werden.

conditions in xpath

Postby AsafA » 27. November 2012 09:42

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
AsafA
 
Posts: 1
Joined: 27. November 2012 09:03
XAMPP Version: 1.7
Operating System: windows server 2003

Return to Apache

Who is online

Users browsing this forum: No registered users and 2 guests