<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Select container using XPath expressions in template in NSO Developer Hub Discussions</title>
    <link>https://community.cisco.com/t5/nso-developer-hub-discussions/select-container-using-xpath-expressions-in-template/m-p/4126224#M5502</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following config&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;admin@ncs% show provisioning base-config | display xpath 
/provisioning/base:base-config[zone='AMER']/region/AMER/country/US/dns/name-servers [ 1.1.1.1 1.1.1.2 ]
/provisioning/base:base-config[zone='APAC']/region/APAC/country/SG/dns/name-servers [ 2.2.2.1 2.2.2.2 ]
/provisioning/base:base-config[zone='EMEA']/region/EMEA/country/UK/dns/name-servers [ 3.3.3.1 3.3.3.2 ]
[ok][2020-07-27 12:15:20]&lt;/PRE&gt;&lt;P&gt;I want to configure a CDB template that selects the right DNS servers based on variables $REGION and $COUNTRY. I tried the following&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;admin@ncs% show devices template TM-BASE-DNS              
config {
    junos:configuration {
        system {
            name-server "{/provisioning/base:base-config[zone=$REGION]/region/&lt;STRONG&gt;node()&lt;/STRONG&gt;/country/&lt;STRONG&gt;node()&lt;/STRONG&gt;/dns/name-servers}";
        }
    }
}
[ok][2020-07-27 12:23:59]&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;admin@ncs% request devices device junos1 apply-template template-name TM-BASE-DNS variable { name REGION value 'AMER' } variable { name COUNTRY value 'US' }                        
apply-template-result {
    device junos1
    result ok
}
[ok][2020-07-27 12:15:03]

[edit]&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;admin@ncs% commit dry-run 
cli {
    local-node {
        data  devices {
                  device junos1 {
                      config {
                          junos:configuration {
                              system {
             +                    # first
             +                    name-server 1.1.1.1;
             +                    name-server 1.1.1.2;
                              }
                          }
                      }
                  }
              }
    }
}
[ok][2020-07-27 12:15:05]&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This template works but with node() it just selects any random container. Instead, I would like to select the specific container that matches the name&amp;nbsp;$REGION and the country container that matches the name given in $COUNTRY&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried the following and multiple combinations of this one using XPATH functions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;admin@ncs% show devices template TM-BASE-DNS 
config {
    junos:configuration {
        system {
            name-server "{/provisioning/base:base-config[zone=$REGION]/region/node()/country/contains($current,$REGION)/dns/name-servers}";
        }
    }
}
[ok][2020-07-27 12:29:34]&lt;/PRE&gt;&lt;P&gt;However it always fails with an XPATH expression error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;admin@ncs% request devices device junos1 apply-template template-name TM-BASE-DNS variable { name REGION value 'AMER' } variable { name COUNTRY value 'US' }                                            
Error: Compilation of XPATH expression '/provisioning/base:base-config[zone=$REGION]/region/node()/country/contains($current,$REGION)/dns/name-servers' at 'devices template TM-BASE-DNS config configuration system name-server "{/provisioning/base:base-config[zone=$REGION]/region/node()/country/contains($current,$REGION)/dns/name-servers}"' failed with result: XPath syntax error
[error][2020-07-27 12:32:01]&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know how would the XPATH expression works in this case? It works nicely when selecting nodes from a list, but I haven't figured it out for selecting a container...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 27 Jul 2020 17:45:33 GMT</pubDate>
    <dc:creator>gusmb</dc:creator>
    <dc:date>2020-07-27T17:45:33Z</dc:date>
    <item>
      <title>Select container using XPath expressions in template</title>
      <link>https://community.cisco.com/t5/nso-developer-hub-discussions/select-container-using-xpath-expressions-in-template/m-p/4126224#M5502</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following config&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;admin@ncs% show provisioning base-config | display xpath 
/provisioning/base:base-config[zone='AMER']/region/AMER/country/US/dns/name-servers [ 1.1.1.1 1.1.1.2 ]
/provisioning/base:base-config[zone='APAC']/region/APAC/country/SG/dns/name-servers [ 2.2.2.1 2.2.2.2 ]
/provisioning/base:base-config[zone='EMEA']/region/EMEA/country/UK/dns/name-servers [ 3.3.3.1 3.3.3.2 ]
[ok][2020-07-27 12:15:20]&lt;/PRE&gt;&lt;P&gt;I want to configure a CDB template that selects the right DNS servers based on variables $REGION and $COUNTRY. I tried the following&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;admin@ncs% show devices template TM-BASE-DNS              
config {
    junos:configuration {
        system {
            name-server "{/provisioning/base:base-config[zone=$REGION]/region/&lt;STRONG&gt;node()&lt;/STRONG&gt;/country/&lt;STRONG&gt;node()&lt;/STRONG&gt;/dns/name-servers}";
        }
    }
}
[ok][2020-07-27 12:23:59]&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;admin@ncs% request devices device junos1 apply-template template-name TM-BASE-DNS variable { name REGION value 'AMER' } variable { name COUNTRY value 'US' }                        
apply-template-result {
    device junos1
    result ok
}
[ok][2020-07-27 12:15:03]

[edit]&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;admin@ncs% commit dry-run 
cli {
    local-node {
        data  devices {
                  device junos1 {
                      config {
                          junos:configuration {
                              system {
             +                    # first
             +                    name-server 1.1.1.1;
             +                    name-server 1.1.1.2;
                              }
                          }
                      }
                  }
              }
    }
}
[ok][2020-07-27 12:15:05]&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This template works but with node() it just selects any random container. Instead, I would like to select the specific container that matches the name&amp;nbsp;$REGION and the country container that matches the name given in $COUNTRY&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried the following and multiple combinations of this one using XPATH functions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;admin@ncs% show devices template TM-BASE-DNS 
config {
    junos:configuration {
        system {
            name-server "{/provisioning/base:base-config[zone=$REGION]/region/node()/country/contains($current,$REGION)/dns/name-servers}";
        }
    }
}
[ok][2020-07-27 12:29:34]&lt;/PRE&gt;&lt;P&gt;However it always fails with an XPATH expression error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;admin@ncs% request devices device junos1 apply-template template-name TM-BASE-DNS variable { name REGION value 'AMER' } variable { name COUNTRY value 'US' }                                            
Error: Compilation of XPATH expression '/provisioning/base:base-config[zone=$REGION]/region/node()/country/contains($current,$REGION)/dns/name-servers' at 'devices template TM-BASE-DNS config configuration system name-server "{/provisioning/base:base-config[zone=$REGION]/region/node()/country/contains($current,$REGION)/dns/name-servers}"' failed with result: XPath syntax error
[error][2020-07-27 12:32:01]&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know how would the XPATH expression works in this case? It works nicely when selecting nodes from a list, but I haven't figured it out for selecting a container...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 17:45:33 GMT</pubDate>
      <guid>https://community.cisco.com/t5/nso-developer-hub-discussions/select-container-using-xpath-expressions-in-template/m-p/4126224#M5502</guid>
      <dc:creator>gusmb</dc:creator>
      <dc:date>2020-07-27T17:45:33Z</dc:date>
    </item>
  </channel>
</rss>

