【发布时间】:2013-08-08 10:26:56
【问题描述】:
我正在尝试为我的 XSL 转换编写一个函数。
基本上在函数中我有一个System.Xml.XPath.XPathNodeIterator,我想在应用于该迭代器中的每个节点时获取 XPath 的值。
在这种情况下,XPath 是 concat(name(.) , "_", string(.)),但它实际上可以是任何东西。
这会引发 XPathException:“表达式必须计算为节点集。” 哪一种有意义
我怀疑我会被告知这不是一个有效的 XPath,而是其他一些与 xml/xsl 相关的功能,但是考虑到在 XSL 中我可以做到这一点:
<xsl:value-of select="concat(name(.) , "_", string(.))"/>
这就是我所追求的——但在功能范围内。
我正在使用 C#,但 VB 答案是可以接受的。
System.Xml.XPath.XPathNodeIterator Nodes = whatever;
string KeySelector="concat(name(.), '_', string(.))";
while (Nodes.MoveNext())
{
System.Xml.XPath.XPathNavigator xpnValue = Nodes.Current.SelectSingleNode(KeySelector);
}
【问题讨论】:
标签: c# .net xpath xpathnavigator xpathnodeiterator