Quantcast
Viewing all articles
Browse latest Browse all 27

Closed Issue: Cannot get XpathCache to replace variables.

I cannot get XpathCache to replace dynamic xpath variables in my xpath expression. I know the expression evaluates if I hardcode some test values.

This works:
string MenuDepthXpathStr = "/descendant-or-self::ul[count(ancestor-or-self::ul) >= $depth]";
string Depth = "1";

XPathNodeIterator TempList = XPathCache.Select(MenuDepthXpathStr, MenuDocXml, new XmlNamespaceManager(MenuDocXml.NameTable), new XPathVariable("depth", Depth));

However this doesnt:
string MenuDepthXpathStr = "/descendant-or-self::ul[count(ancestor-or-self::ul) >= $depth $highlighted]";
string Depth = "1";
string Highlighted = (SomeBoolVal? "and contains(@class, 'expanded')" : "");

XPathNodeIterator TempList = XPathCache.Select(MenuDepthXpathStr, MenuDocXml, new XmlNamespaceManager(MenuDocXml.NameTable), new XPathVariable("depth", Depth), new XPathVariable("highlighted", Highlighted));

It seems as though my variable cannot contain xpath it can only be values. Why is this? Is there any way to dynamically generate the xpath itself and not just insert values?
Comments: By Design

Viewing all articles
Browse latest Browse all 27

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>