[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Confusing namespaces and xslt


Subject: Re: [xsl] Confusing namespaces and xslt
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 29 Sep 2008 14:51:42 -0400

At 2008-09-29 14:36 -0400, Paul Ferwerda wrote:
I have a newbie question. I've gone round and around on this issue and
haven't been able to make any headway on my own. I suspect I'm missing
some basic understanding of how to use XPath expressions and how
namespaces are used. so I apologize in advance if the question is a
stupid one.

It isn't stupid at all, it is just *very* common ... perhaps the most common FAQ.


Unprefixed element names in XPath are in no namespace, not in the default namespace, unless you are using XSLT 2.0 and you declare the use of a default namespace in your stylesheets.

The safest, regardless of using XSLT 1 or 2, is to declare in your stylesheet your own prefixes for *all* the namespaces used in the XML, and then prefix *all* element names in your XPath addresses. Even in XSLT 2 I've found myself tripped up by declaring the default namespace in my stylesheet because of my laziness when dealing with multiple namespaces, so I personally don't use the new declaration.

Yes, this is laborious, but it is the way to allow XPath to address elements in either no namespace or with a namespace.

The important point to remember is that namespace-aware XML processing is based on the combination of namespace URI and local name, not on the namespace prefix, because the namespace prefix is arbitrary between different users of the vocabulary.

Oh, and don't forget in XML and XPath that unprefixed attribute names are always in no namespace and never in the default namespace.

I hope this helps.

. . . . . . . . Ken

--
Upcoming XSLT/XSL-FO hands-on courses:      Wellington, NZ 2009-01
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


Current Thread
Keywords