I am trying to write a function for my XSL Transform.
Basically within the function I have a System.Xml.XPath.XPathNodeIterator
and I want to get the value of an XPath when applied to each of the nodes within that iterator.
In this instance the XPath is concat(name(.) , "_", string(.))
but it could actually be anything.
This is throwing an XPathException: "Expression must evaluate to a node-set." Which kind of makes some sense
I suspect I'm going to be told this is not a valid XPath but is some other xml/xsl related functionality however, consider that in XSL I can do this:
<xsl:value-of select="concat(name(.) , "_", string(.))"/>
And that is what I'm after - but within the function.
I'm using C# but VB answers are acceptable.
System.Xml.XPath.XPathNodeIterator Nodes = whatever;
string KeySelector="concat(name(.), '_', string(.))";
while (Nodes.MoveNext())
{
System.Xml.XPath.XPathNavigator xpnValue = Nodes.Current.SelectSingleNode(KeySelector);
}
You will need to use the Evaluate
method and not SelectSingleNode
. And the result of your XPath is not an XPathNavigator
, it is an XPath String
respectively a .NET System.String
or a C# string
.