This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: a namespace problem
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: "Michael Leditschke" <mike at ammd dot com dot au>
- Cc: xsl-list at lists dot mulberrytech dot com
- Date: Tue, 9 Apr 2002 08:46:13 +0100
- Subject: Re: [xsl] a namespace problem
- Organization: Jeni Tennison Consulting Ltd
- References: <LOBBICBLDJIJHPNJFPOLMEJJCDAA.mike@ammd.com.au>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi Michael,
> Hi Jeni. A read of the XPath 2.0 requirements makes no mention of
> default namespace interpretation (that I could find, at least
> amongst all the red and blue :-)). The XSLT 2.0 requirements does
> have a small section adding this requirement.
>
> Your comment would suggest something has to change in XPath to allow
> the XSLT 2.0 default namespace stuff to work. Is that the case?
Sort of, but only minor things (which is why it's not on the
requirements as such).
It's actually XPath 1.0 rather than XSLT 1.0 that states that the
default namespace declaration is not used when resolving attribute or
element names:
A QName in the node test is expanded into an expanded-name using the
namespace declarations from the expression context. This is the same
way expansion is done for element type names in start and end-tags
except that the default namespace declared with xmlns is not used:
if the QName does not have a prefix, then the namespace URI is null
(this is the same way attribute names are expanded). It is an error
if the QName has a prefix for which there is no namespace
declaration in the expression context.
http://www.w3.org/TR/xpath#node-tests
XPath 2.0 instead provides a hook whereby the host language can change
this behaviour. Each expression has a static context, set up by the
language hosting the XPath, as well as its evaluation context (which
includes the usual things like context node, position and size). The
static context includes things like what variables and extension
functions have been declared, and also three things about namespaces:
* In-scope namespaces. This is a set of (prefix, URI) pairs. The
in-scope namespaces are used for resolving prefixes used on QNames
within the expression.
* Default namespace for element names. This is a namespace URI.
This namespace is used for any unprefixed QName appearing in a
position where an element name is expected.
* Default namespace for function names. This is a namespace URI.
This namespace is used for any unprefixed QName appearing as the
function name in a function call.
http://www.w3.org/TR/xpath20/#static_context
Later on, when it talks about resolving QNames, the XPath 2.0 WD
refers to the "default namespace for element names" from this static
context:
A QName in a node test is expanded into an expanded-name using the
in-scope namespaces in the expression context. An unprefixed QName
used as a nametest has the namespaceURI associated with the default
element namespace in the expression context. It is an error if the
QName has a prefix that does not correspond to any in-scope
namespace.
http://www.w3.org/TR/xpath20/#node-tests
The good thing about this is that it means that different "host"
languages for XPath 2.0 can decide how they want the default namespace
for element names to work -- whether it should use the default
namespace declaration (perhaps XML Schema will do this, for example),
some other mechanism (as in XSLT 2.0 and XQuery) or always be null (as
in XSLT 1.0).
What you'd expect is that XSLT 2.0 simply states that the
[xsl:]default-xpath-namespace attribute sets the value of the "default
namespace for element names". Actually, the XSLT 2.0 WD currently
defines the same kind of thing locally, which in some ways isn't
surprising since it has to work for patterns (which aren't defined in
XPath) as well as expressions:
The attribute [xsl:]default-xpath-namespace (see [2.3 Standard
Attributes]) may be used on an element in the stylesheet to define
the namespace URI that will be used for an unprefixed name used as a
NameTest within a step of an XPath PathExpression or an XSLT Pattern
occurring in an attribute of that stylesheet element or an attribute
of a descendant of that stylesheet element.
This default namespace URI applies only to a NameTest applied to an
axis whose principal node type is elements: it does not apply when
the step is using the attribute or namespace axis. The default
namespace URI for such a name is the value of the
[xsl:]default-xpath-namespace attribute on the innermost ancestor
element that has such an attribute, considering all ancestor
elements of the attribute containing the XPath expression or XSLT
pattern. The [xsl:]default-xpath-namespace attribute must be in the
XSLT namespace only if its parent element is not in the XSLT
namespace.
http://www.w3.org/TR/xslt20/#unprefixed-qnames
I suspect this will get neatened up as we get into later Working
Drafts.
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list