05-02-2018 09:43 PM - edited 03-01-2019 04:09 AM
Hi Team ,
Hope you are doing well . I am trying to wrap my head around the ../ or ../../ use in the XPATH with no success . I have read the reference for the same in RFC but does not help much . I would appreciate if someone could explain this to me with an example.
For example on the youtube video on YANG training below , could someone please explain what does "/client[ip=current()/../v-ip]/port" expand to ? What does ip=current() point to and then where does the ../ notation point to in the hierarchy .
Also appreciate if someone could explain the expansion of the path without deref() and with deref() .
Regards,
Vikas Srivastava
05-05-2018 11:58 AM
Hi,
current() means your current node. Imagine it as the linux directory system and current() = pwd().
So, with ../ you go back one level in the tree structure and with ../../ you do it twice.
Example: if video/v-ip="1.1.1.1"
/client[ip=current()/../v-ip]/port
would mean "/client[ip="1.1.1.1"]/port
Roque
05-05-2018 12:21 PM
Thank you Rogue , That helps .
At some places its use of the ../ is clear , like the example you provided. What about the .. in the XML template below ( the one just after the /link[1]/var1_router_name ?
My understanding is that link[1]/var1_router_name expands to /ncs:devices/device[PE11]/config so why is there the two .. in this case ?
XML Template
<address>
{
deref(/link[1]/var1_router_name)/../config/interface/Loopback[name='0']/ip/address/primary/address |
deref(/link[1]/var1_router_name)/../config/interface/Loopback[id='0']/ipv4/address/ip
}
</address>
YANG
module learning_deref2 {
namespace "http://com/example/learning_deref2";
prefix learning_deref2;
import ietf-inet-types { prefix inet; }
import tailf-ncs { prefix ncs; }
import tailf-common { prefix tailf; }
import tailf-ned-cisco-ios { prefix ios;}
augment "/ncs:services" // AUGMENT is used to add to another data model , OR augment it. So in the example we are adding/augumenting the learning_deref to it.
{
list learning_deref2
{
key "name";
uses ncs:service-data;
ncs:servicepoint "learning_deref2";
leaf name
{
mandatory true;
type string;
}
list link
{
min-elements 2;
max-elements 2;
key "var1_router_name";
leaf var1_router_name
{
mandatory true;
type leafref
{
path "/ncs:devices/ncs:device/ncs:name"; // This path points to a list of routers , not a sepcific router
}
} //routername
container ios
{
// name=current()/../var1_router_name = PE11
// ncs:name=current()/../var1_router_name EXPANDS to ncs:name=/ncs:services/learning_deref/link/var1_router_name
when "/ncs:devices/ncs:device[ncs:name=current()/../var1_router_name]/ncs:device-type/ncs:cli/ncs:ned-id='ios-id:cisco-ios'"
{
//tailf:dependency "../device";
//tailf:dependency "/ncs:devices/ncs:device/ncs:device-type";
}
leaf intf-number
{
mandatory true;
type leafref
{
path "deref(../../var1_router_name)/../ncs:config/ios:interface/ios:GigabitEthernet/ios:name";
}
} //intf-number
} //ios
}
}
}
}
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide