XPath filtering behavior when using current()
Hi!
I've noticed when checking different XPath filters, that the current()
function behaves differently when using <get> and <get-data>.
For example:
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="">
<get>
<filter type="xpath" select="/t:basics/t:animals[species=current()/t:text]" xmlns:t="urn:com:test"/>
</get>
</rpc>
Returns:
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-
id="18">
<data>
<basics xmlns="urn:com:test">
<animals>
<species>cat</species>
<weight>4</weight>
</animals>
</basics>
</data>
</rpc-reply>
Meanwhile, using the same XPath filter with get-data:
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"
xmlns:ncds="urn:ietf:params:xml:ns:yang:ietf-netconf-nmda"
message-id="1">
<get-data xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-nmda">
<datastore xmlns:ds="urn:ietf:params:xml:ns:yang:ietf-datastores">ds:running</datastore>
<xpath-filter xmlns:t="urn:com:test">/t:basics/t:animals[t:species=current()]/t:weight</xpath-filter>
</get-data>
</rpc>
Will return:
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="20">
<data xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-nmda"/>
</rpc-reply>
libyang1 shows the same behavior in both cases (the behavior of <get>).
Am I using current() incorrectly, or one of the filters is wrong?
I'm using the latest devel of libyang, sysrepo, libnetconf2 and netopeer2.
I've attached the example config and the test schema. xpath_current_issue.tar.gz
Thanks!
The examples you provided have different XPath filters, could you please use a single filter and check that the behavior really differs?
Sorry, it was a typo. The proper <get-data> XML was meant to be:
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"
xmlns:ncds="urn:ietf:params:xml:ns:yang:ietf-netconf-nmda"
message-id="1">
<get-data xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-nmda">
<datastore xmlns:ds="urn:ietf:params:xml:ns:yang:ietf-datastores">ds:running</datastore>
<xpath-filter xmlns:t="urn:com:test">/t:basics/t:animals[species=current()/t:text]</xpath-filter>
</get-data>
</rpc>
So, the same xpath-filter as <get>, and it returns the empty data just the same.
Okay, lots of minor fixes were needed because no one has tried using current() in the filter, since it is useless. But it should work correctly with latest versions, anyway.