The problem. When adding custom XPath extension functions as described in "HOW TO: Implement and Use Custom Extension Functions When You Execute XPath Queries in Visual C# .NET" KB article and "Adding Custom Functions to XPath" article at MSDN Extreme XML column you can find that any XPath expressions having namespace prefixes, like "/foo:bar" just can't be evaluated due to nasty System.ArgumentNullException deeply in the XPath engine.
The reason. It turned out that internal XPath classes, e.g. BaseAxisQuery expect custom XsltContext implementation to resolve namespaces prefixes (XsltContext extends XmlNamespaceManager) with respect to the NameTable, just as internal default XsltContext implementation - UndefinedXsltContext class does. The documentaion unfortunately omits that point and sample implementation in the above articles too.
The solution. Just override LookupNamespace(string prefix) method in your XsltContext implementation and pass given prefix through the NameTable:
public override string LookupNamespace(string prefix) { if (prefix == String.Empty) return String.Empty; string uri = base.LookupNamespace(NameTable.Get(prefix)); if (uri == null) throw new XsltException("Undeclared namespace prefix - " + prefix, null); return uri; }Easy, ain't it? I'm stupid spent two hours to get it.
Thank you very much.
Thank you *so* much! I was going nuts!
Thank you very much. I was getting very angry with this problem. You saved my soul :-)
Haha, awesome work dude, that just saved my ass
I think u just saved me 2 hours (probably more). Thanks
Thanks Oleg, that one had me stumped as well, until I saw your solution.