#562 saxon:evaluate and default namespace

v8.7.3
closed
Michael Kay
5
2012-10-08
2006-07-17
Michael Kay
No

If a default namespace is declared in a stylesheet using

xmlns="abc.uri"

then this is used to qualify any unprefixed name
appearing in an XPath expression submitted to
saxon:evaluate() within that stylesheet (that is, it is
used as the default namespace for elements and types).

The following source patch fixes this. In
net.sf.saxon.functions.Evaluate, line 69, change the
iteration over namespaces to read:

for (Iterator iter = nsContext.iteratePrefixes();
iter.hasNext();) {
String prefix = (String)iter.next();
if (!"".equals(prefix)) {
String uri =
nsContext.getURIForPrefix(prefix, true);

staticContext.declareNamespace(prefix, uri);
}
}

In fixing this permanently, I will probably arrange for
the value of default-xpath-namespace to be taken into
account.

Note that when dynamically-evaluated XPath expressions
are read from source documents, the alternative
function saxon:evaluate-node() is available - this
takes its namespace context from the source document.
In this case, the default namespace declared in the
document is used as the default namespace for elements
in the path expression. I think this is a reasonable
thing to do, and will document it as the correct
behaviour of saxon:evaluate().

Discussion

  • Michael Kay
    Michael Kay
    2006-07-17

    Logged In: YES
    user_id=251681

    The change to take account of xpath-default-namespace can be
    made by adding the line:

    staticContext.setDefaultElementNamespace(

    env.getNamePool().getURIFromURICode(env.getDefaultElementNamespace()));

    It is desirable to add this change for the XQuery case,
    since in XQuery the xmlns="abc.xyz" declaration *should"
    determine the default namespace used by saxon:evaluate().