OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] xml, xslt and namespaces

[ Lists Home | Date Index | Thread Index ]

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




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS