def yang_to_xpath(self, xpe): """Transform YANG's `xpath` to a form suitable for Schematron. 1. Prefixes are added to unprefixed local names. Inside global groupings, the prefix is represented as the variable '$pref' which is substituted via Schematron abstract patterns. 2. '$root' is prepended to every absolute location path. """ if self.gg_level: pref = "$pref:" else: pref = self.prefix_stack[-1] + ":" toks = xpath.tokens(xpe) prev = None res = "" for tok in toks: if tok[0] == "/" and prev not in (".", "..", ")", "]", "name", "wildcard", "prefix-test"): res += "$root" elif tok[0] == "name" and ":" not in tok[1]: res += pref res += tok[1] if tok[0] != "whitespace": prev = tok[0] return res
def yang_to_xpath(self, xpe): """Transform YANG's `xpath` to a form suitable for Schematron. 1. Prefixes are added to unprefixed local names. Inside global groupings, the prefix is represented as the variable '$pref' which is substituted via Schematron abstract patterns. 2. '$root' is prepended to every absolute location path. """ if self.gg_level: pref = "$pref:" else: pref = self.prefix_stack[-1] + ":" toks = xpath.tokens(xpe) prev = None res = "" for tok in toks: if tok[0] == "/" and prev not in (".", "..", ")", "]", "name", "wildcard", "prefix-test"): res += "$root" elif tok[0] == "name" and ":" not in tok[1]: res += pref res += tok[1] if tok[0] != "whitespace": prev = tok[0] return res