what is in-scope namespace in relation to XPath?

xml, xpath

Solution

For the XSLT/XPath 1.0 data model the XPath 1.0 specification in http://www.w3.org/TR/xpath/#namespace-nodes says the following about `namespace nodes`:

Each element has an associated set of namespace nodes, one for each distinct namespace prefix that is in scope for the element (including the xml prefix, which is implicitly declared by the XML Namespaces Recommendation [XML Names]) and one for the default namespace if one is in scope for the element.

Namespace declarations and their scope are defined in the XML namespaces specification, http://www.w3.org/TR/xml-names/#scoping says:

The scope of a namespace declaration declaring a prefix extends from the beginning of the start-tag in which it appears to the end of the corresponding end-tag, excluding the scope of any inner declarations with the same NSAttName part. In the case of an empty tag, the scope is the tag itself.

Such a namespace declaration applies to all element and attribute names within its scope whose prefix matches that specified in the declaration.

And http://www.w3.org/TR/xml-names/#defaulting says the following about the scope of any default namespace declaration (i.e. `xmlns="http://example.com/ns1`):

The scope of a default namespace declaration extends from the beginning of the start-tag in which it appears to the end of the corresponding end-tag, excluding the scope of any inner default namespace declarations. In the case of an empty tag, the scope is the tag itself.

To give you an example, with

<root xmlns="http://example.com/n1" xmlns:pf2="http://example.com/ns2">
  <foo>
    <bar xmlns="http://example.com/ns3">whatever</bar>
  </foo>
</root>

the default namespace declaration `http://example.com/n1` is in scope for the `root` element and the `foo` element, but not for the `bar` element as that has its own default namespace declaration overriding the one of the outer scope. The namespace declaration `xmlns:pf2="http://example.com/ns2"` however is in scope for the root element and all its descendants.

Problem

what is exactly an in-scope namespace in relation to XPath? Thanks

Original source