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

Re: xml, xslt and namespaces


xslt xml default namespace
Waleed Abdulla wrote:
> If you're trying to avoid the extra key strokes then I'd agree with Thomas's
> answer that there is no way around it (IMHO).
> 
> However, if you're generating the XSL documents by some software and you
> don't care about human readability then try this (I haven't tried it, but it
> might work):
> 
> 
> <xsl:value-of xmlns="http://www.mydomain.org/ns/" select="request/title"/>
> 
> 
>    Basically, define the default namespace in each and every XSLT tag where
> there is an XPath expression. Cumbersome and ugly, but it's another
> solution. 

Cumbersome, yes.  Workable, no.  Path expressions in xpath are not aware 
of the default namespace.  More precisely, namespaces have to be 
specified explicitly in an xpath expression.  No matter where the 
default namespace is declared, it is still a default namespace, and 
there is no way to specify it in the path expression.  You can't trick 
xpath that way.

You could have tested your idea in about three minutes. I just did, even 
though I knew what to expect.  You would have found out it doesn't work.

Another three minutes with the xpath Recommendation would have confirmed 
this -

[4]   	Step	        ::= AxisSpecifier NodeTest Predicate*	
			| AbbreviatedStep

[7]   	NodeTest	::= NameTest	
			| NodeType '(' ')'	
			| 'processing-instruction' '(' Literal ')'	

[37]   	NameTest	::= '*'	
			| NCName ':' '*'	
			| QName	

[From section 2.3]
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).

We see definitively that if there is no prefix in the name used in a 
step, then the null namespace is assigned, not the default namespace. 
That's why expressions like request/title do not return anything when 
those elements are in a non-null default namespace.

Cheers,

Tom P

-- 
Thomas B. Passin
Explorer's Guide to the Semantic Web (Manning Books)
http://www.manning.com/catalog/view.php?book=passin

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
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

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.