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: ** Comment from web user: dcazzulino **
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: ** Comment from web user: dcazzulino **
That's just now how xslt variables work. We're just making it easier to use a feature that's provided by the System.Xml.Xsl namespace. We can't make changes, and I don't anticipate MS doing them either.
Again, if you're invoking Sprocs, you cannot do that. I'm afraid this is internally (.NET) the same.