You have misunderstood the specification. Section 5.4.1 states that for any XPath expression, the statically known namespaces are the namespaces that are in scope for the containing element. "Element" here means an element node in the stylesheet module, viewed as an instance of the XPath data model. The set of declarations in a stylesheet is the union of the declarations in all the imported and included modules, but the static context for each declaration comes from its own module: xsl:include is not a process of textual substitution, or even a process of generating a single XPath data model document by grafting together the data model representations of the individual modules.
Section 5.1 on Qualified Names also tries to explain this.
Michael Kay

From: [] On Behalf Of Sembower, Neil R
Sent: 11 August 2005 18:42
Subject: [saxon] import/include namespaces are lost

It appears that namespace declarations are lost inside of an include or import.  Here is an example.

Stylesheet b doesn't declare namespace q but uses it in an xpath expression.

<xsl:stylesheet version="1.0" xmlns:xsl="">

        <xsl:template match="node()">
                <xsl:value-of select="//q:a"/>


This document is processed and not surprisingly saxon reports that q hasn't been declared.

<q:a xmlns:q="">hello</q:a>

Error at xsl:value-of on line 7 of file:/b.xsl:
  XPath syntax error at char 5 on line 7 in {//q:a}: Namespace prefix q has not been declared

If stylesheet b has a declaration for q added then we get the expected output.

Stylesheet a declares namespace q and imports stylesheet b.

<xsl:stylesheet version="1.0"

        <xsl:import href="b.xsl"/>


If saxon processes stylesheet a we see the same error as when b was processed.  Since adding the namespace declaration to b worked I expected this to work as well.  The spec says that 'the children of the xsl:stylesheet element in this document replace the xsl:include element in the including document.' which would put the template in b within the scope of the declaration of q in a.

I ran this against saxon 8.1.