2018-08-01 13:18:30.940 [ERROR] [.i.s.XsltTransformationService] - transformation throws exception
javax.xml.transform.TransformerConfigurationException: Element type "xsl:value-of" must be followed by either attribute specifications, ">" or "/>".
What do you mean by that ? If I want to extract few values I need to have xsl file for each item/value, am I right ?
The error is some problem with the XSL syntax. I avoid XSL at almost all costs so I can’t really help solve that error. And since you are not actually transforming the XML into some other XML or into some other format and just pulling the value of an attribute, XSL is the wrong tool for the task. You should be using XPATH transform for that.
If you are running OH 2.x you should be using https://www.openhab.org/docs/ as the source of the documentation. If you are using OH 1.8 and using any binding newer than 1.8 you should be using https://www.openhab.org/addons/ for your documentation. The OH 1 wiki has not been maintained for almost two years now.
I provided a link above to the Xpath documentation.
Yes error was XSL Syntax. Then I recognized that I can use XPATH transformation directly, so it looks working:
Number Energy_Prod "Energia produkowana [%.0f W]" <energy> (Energy) {http="<[http://192.168.1.71/measurements.xml:10000:XPATH(/root/Device/Measurements/Measurement[@Type='AC_Power']/@Value)]"}
Before I had a problem as well with syntax, because “AC_Power” was interpreted as end of http link, but I have changed " to ’ and it works
Thanks for that.
BTW. Here in item I can provide refresh time in ms, but it is for PV inventer which works only during a day, so there is no sense to refresh it every seconds or minute. Can I somehow write a rule which will triger refresh every minute during day only (I can use time crone and assume fix daylights hours) ?
Not with the HTTP binding unfortunately. Personally, hitting the URL every 10 seconds or a minute at night is a problem not worth solving. But if you want to try to solve that, you will have to switch to the sendHttpGetRequest Actions and a cron triggered Rule. Use the Quartz cron builder (search google) to construct the expression; that’s the best tool I’ve used for this purpose.
In the Rule you will have:
rule "Get Power"
when
// cron expression
then
val results = sendHttpGetRequest("http://192.168.1.71/measurements.xml")
Energy_Prod.postUpdate(transform("XPATH", "/root/Device/Measurements/Measurement[@Type='AC_Power']/@Value", results)
end
If you want to get really clever, you can use Astro to calculate sunrise and sunset and only update between those times.
rule "Get Power"
when
Time cron "0 * * * ? *" // this expression is probably wrong, should be every minute
then
if((Sunrise.state as DataTimeType).isAfter(now.millis) || (Sunset.state as DateTimeType).isBefore(now.millis)) return;
val results = sendHttpGetRequest("http://192.168.1.71/measurements.xml")
Energy_Prod.postUpdate(transform("XPATH", "/root/Device/Measurements/Measurement[@Type='AC_Power']/@Value", results)
end
The added if statement will exit the Rule if the current time is before sunrise or after sunset.