[SOLVED] Using XPATH string functions such as replace() do not work

Hi community, I am pretty new to OpenHAB and currently learning my first steps and ran into a “problem”. So I have a HTTP Binding and I am retrieving an XML from my heating unit. The XML looks as follows:

<eta xmlns="http://www.eta.co.at/rest/v1" version="1.0">
<value uri="/user/var/120/10101/0/0/12197" strValue="9,2" unit="°C" decPlaces="1" scaleFactor="10" advTextOffset="0">92</value>

So I want to extract the attribute strValue (9,2) and also send this value to InfluxDB and in the end visualize the values with Grafana. Here now comes my problem, I can extract the value with XPATH - but since the XML returns the wrong number notation (comma instead of a point for decimal points) Grafana interprets this as String and would not plot the values. Thus, I want to send the properly formatted value already to InfluxDB.

My item working definition is as follows:

String ETA_Outside_Temp "Temp [%s C]" { http="<[http://somehost/user/var/120:60000:XPATH(//*[local-name()='eta']/*[local-name()='value']/@strValue"}}

Now I thought that I can easily use XPATH functions, such as replace, to directly return a properly formatted number:

Number ETA_Outside_Temp "Temp [%.1f C]" { http="<[http://somehost/user/var/120:60000:XPATH(replace(//*[local-name()='eta']/*[local-name()='value']/@strValue, ",", ".") "}}

But then I get the following error in the openhab.log: “mismatched input '”, "’ expecting RULE_ID

Maybe someone can help me out on how to properly use XPATH functions (if that is possible at all) or point me to the right direction on how to solve this?

Thanks, Chris

I would use a String item and then a rule to replace the comma and put it in a number item

rule "example"
    Item MyStringItem changed
    var String myString = MyStringItem.state.toString.replace(",",".")

Thanks, that worked - I only had to change part of the script a bit (add “toString”) because I got the error message "‘replace’ is not a member of ‘org.eclipse.smarthome.core.type.State’:

var String myString = MyStringItem.state.toString.replace(",", “.”);

Thanks for your help!

Anyhow, which XPATH implementation is used for the transformation service? Is it 1.0 because I can’t use those functions?

Thanks, Chris

Of course, silly oversight on my part, sorry
Corrected above for future users