Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 5th, 2009, 05:37 PM
Authorized User
 
Join Date: Apr 2008
Posts: 70
Thanks: 17
Thanked 1 Time in 1 Post
Send a message via Yahoo to iceandrews
Default Default Namespace

I'm curious if there's a method in XSLT to get the default namespace of the input document.

I have a situation where I need to get the default namespace of the input document, but the root element node MIGHT be in a prefixed alternate namespace.

If the root element node was IN the default namespace always, I could use something like the following:
Code:
<xsl:template match="/">
    <xsl:value-of select="/*:MYELEMENTNAME/namespace-uri(.)" />
</xsl:template>
Unfortunately, that it's just a work around the real problem. When I have the root element in a prefixed-namespace, the above code obviously does not get the default namespace. I need to be able to get the default namespace when I have a document structure like the following:

Code:
<foo:ROOT xmlns:foo="http://foo.bar" xmlns="http://defaultns.com">
    <CHILD>
         <Description>Data</Description>
    </CHILD>
</foo:ROOT>
In this case, I'm not sure how to directly retrieve the default namespace.

Thanks!
 
Old February 5th, 2009, 06:07 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

string(/*/namespace::*[name()=''])
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
iceandrews (February 6th, 2009)
 
Old February 6th, 2009, 04:42 PM
Authorized User
 
Join Date: Apr 2008
Posts: 70
Thanks: 17
Thanked 1 Time in 1 Post
Send a message via Yahoo to iceandrews
Default

Quote:
Originally Posted by mhkay View Post
string(/*/namespace::*[name()=''])
Yeah that'll do it.

I also figured out you can use this as well:

Code:
namespace-uri-for-prefix('',/*:ROOTELEMENT)





Similar Threads
Thread Thread Starter Forum Replies Last Post
default-xpath-namespace stolte XSLT 1 March 19th, 2008 12:49 PM
Default Namespace - XSLT 1.0 Geierwally XSLT 2 July 9th, 2007 11:08 AM
Dynamic Default Namespace EcceBozo XSLT 2 June 6th, 2007 04:05 PM
How can I change the default namespace allanhu BOOK: ASP.NET Website Programming Problem-Design-Solution 1 November 1st, 2004 01:15 PM
Default Namespace (where is it?) bekim BOOK: ASP.NET Website Programming Problem-Design-Solution 4 June 12th, 2004 03:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.