Re: [xsl] xPath and default namespaces.

Subject: Re: [xsl] xPath and default namespaces.
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 12 Apr 2001 09:09:19 +0100
Hi Dwight,

> Is it legal XHTML to give an alias to the XHTML name space ?

XHTML is an attempt to marry HTML and XML so that *both* HTML
applications *and* XML applications can use it. Using a prefix for the
XHTML within a document is perfectly fine as far as an XML application
is concerned, but it's not acceptable by HTML applications.

But that's by-the-by because David C. was talking about adding a
prefixed namespace declaration *within the stylesheet*, not within the
XHTML document.  Obviously, HTML applications are never going to look
at an XSLT stylesheet, so you're not constrained by what they can or
can't read.

In the stylesheet, you have to associate a prefix with the namespaces
of any nodes that you want to select or match (unless they're all in
the null namespace). Importantly, this doesn't have to be the same as
the prefix that you use in the document you're processing. So you can
have your XHTML document use the default namespace (have no prefix)
while using 'xhtml' as the prefix in your stylesheet. The XSLT
processor uses the *namespace URI* that's associated with each of
them, rather than the prefix, to do the matching.

So in the stylesheet, you can do things like:

<xsl:stylesheet version="1.0"

<xsl:template match="xhtml:html">
   <xsl:apply-templates select="xhtml:body" />

<xsl:template match="xhtml:body">

Not interpreting XPaths using the default namespace is something that
can be very useful, but it's recognised as being confusing. From the
XSLT 2.0 Requirements, it seems that in XSLT 2.0 there will be a flag
or something that you can set that tells the processor to use the
default namespace for unprefixed names in XPaths.

> I don't include the XHTML DTD because the parser doesn't seem to
> like it.

Which parser are you talking about? How does it object? An XML parser
should be able to use the XHTML DTD to validate your XHTML page, and I
think that an HTML application should just ignore it.

I hope that helps,


Jeni Tennison

 XSL-List info and archive:

Current Thread