Implementing your own custom XsltContext objects, cont'd

In my previous post, I mentioned that the only changes are prefacing your XPath function with a namespace prefix.

However, thanks to a post from Oleg Tkachenko, I found a way around this.

In the CustomContext class, override LookupNamespace(string prefix) with the following code:

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;