Post

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:

1
2
3
4
5
6
7
8
9
10
11
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;
}
This post is licensed under CC BY 4.0 by the author.