[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Confusing namespaces and xslt

Subject: Re: Confusing namespaces and xslt
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 29 Sep 2008 14:51:42 -0400
Re:  Confusing namespaces and xslt
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.