2

I have a leaf defined in Yang as:

leaf test-must {
    type int32;
    description "Test must";
    must "current() > 0" {
        error-message "test-must value should be > 0";
    }
}

Looks like the underlying library, libxml2, I use does not recognize current() when this is evaluated and returns error:

error: xmlXPathCompOpEval: function current not found

error: Unregistered function

Are there any alternatives to current()? Or where do I find definition for current() and register it?

As an alternative I tried with . and self::node() following this.

But when this expression is evaluated with libxml2 APIs, when test-must value is configured as 0, it returns proper error. However, when test-must value is > 0, it says "invalid expression", which should not return error since value > 1 (which is Success as per must statement).

error: Invalid expression

Can someone provide some help on this?

GileBrt
  • 1,830
  • 3
  • 20
  • 28
Ram
  • 301
  • 2
  • 12
  • 3
    The function current() is defined only for use in XSLT, not in free-standing XPath. The use of "." is allowed in free-standing XPath, but I don't know Yang, so I don't know how you set the initial context item for the expression. – Michael Kay Apr 28 '19 at 12:19
  • Thanks, if we have to implement our own function to support current() and register the same with libxml2 Xpath library, are there any existing examples or open source available? – Ram Apr 29 '19 at 04:27
  • In your example, `current() > 0` and `. > 0` are semantically equivalent. The initial context node would be an instance of `test-must` leaf. I've not used libxml2, but it seems very strange that it would report what appears to be a syntax error depending on values supplied at runtime. Are you sure the only thing you changed between the two tests was the value of your leaf instance? – predi Apr 29 '19 at 06:52
  • Also note, depending on your YANG version, `current()` may not be the only XPath function you'll have to implement. – predi Apr 29 '19 at 06:55
  • @predi, I have posted a follow up question @ https://stackoverflow.com/questions/56375878/xpath-current-for-yang. Could you check? – Ram May 30 '19 at 14:22

0 Answers0