When calling format-number XPath function, I receive error: "Namespace Manager or XsltContext needed."
When calling format-number XPath function, I receive error: "Namespace Manager or XsltContext needed."
我正在尝试计算包含函数 format-number
within the C# method XPathEvaluate(XNode, String)
的 XPath 表达式。简化复现如下:
// In this example, the XML is not actually used; written purely to demonstrate the issue
XElement test = new XElement("test", 12);
object output = test.XPathEvaluate("format-number(2, \"00\")");
运行时,抛出以下异常:
System.Xml.XPath.XPathException: 'Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function.'
我已尝试将 XSLT 命名空间添加到 XmlNamespaceManager
,然后将其提供给 XPathEvaluate
函数,如异常消息和 answer to a similar question 中所建议的那样,但是也没有用:
var manager = new XmlNamespaceManager(new NameTable());
manager.AddNamespace("xsl", "http://www.w3.org/1999/XSL/Transform");
test.XPathEvaluate("format-number(2, \"00\")", manager);
如何在 XPath 语句中调用 format-number
函数?
我正在尝试计算包含函数 format-number
within the C# method XPathEvaluate(XNode, String)
的 XPath 表达式。简化复现如下:
// In this example, the XML is not actually used; written purely to demonstrate the issue
XElement test = new XElement("test", 12);
object output = test.XPathEvaluate("format-number(2, \"00\")");
运行时,抛出以下异常:
System.Xml.XPath.XPathException: 'Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function.'
我已尝试将 XSLT 命名空间添加到 XmlNamespaceManager
,然后将其提供给 XPathEvaluate
函数,如异常消息和 answer to a similar question 中所建议的那样,但是也没有用:
var manager = new XmlNamespaceManager(new NameTable());
manager.AddNamespace("xsl", "http://www.w3.org/1999/XSL/Transform");
test.XPathEvaluate("format-number(2, \"00\")", manager);
如何在 XPath 语句中调用 format-number
函数?