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

Re: Namespace name from node?

Subject: Re: Namespace name from node?
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 6 Dec 2001 10:33:42 +0000
substring before xhtml current
Hi Andrey,

> How can i figure out the namespace name for a given node?

It depends on what you mean by the namespace name. You can access the
namespace URI with the namespace-uri() function, for example, if you
had:

  <xhtml:element xmlns:xhtml="http://www.w3.org/1999/xhtml" ... />

then you could get the namespace URI http://www.w3.org/1999/xhtml
with:

  <xsl:choose>
    <xsl:when test="namespace-uri() = 'http://www.w3.org/1999/xhtml'">
      ...
    </xsl:when>
    ...
  </xsl:choose>

This would work regardless of the prefix that you had in the the
source document, so it would evaluate as the same thing for:

  <element xmlns="http://www.w3.org/1999/xhtml" ... />
  <foo:element xmlns:foo="http://www.w3.org/1999/xhtml" ... />

Alternatively, if you know what namespace you want to test for, you
can declare it in your stylesheet:

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xhtml="http://www.w3.org/1999/xhtml">
...
</xsl:stylesheet>

And then test by seeing if the current node is a node in that
namespace using the self axis:

  <xsl:choose>
    <xsl:when test="self::xhtml:*">
      ...
    </xsl:when>
    ...
  </xsl:choose>

But you might have meant the namespace *prefix* by 'namespace name', in
which case you can use substring-before() to access the prefix:

  <xsl:choose>
    <xsl:when test="substring-before(name(), ':') = 'xhtml'">
      ...
    </xsl:when>
    ...
  </xsl:choose>

This will test as true for both:

  <xhtml:element xmlns:xhtml="http://www.w3.org/1999/xhtml" ... />
  <xhtml:element xmlns:xhtml="http://www.rubbish.com" ... />

And false for both:

  <element xmlns="http://www.w3.org/1999/xhtml" ... />
  <foo:element xmlns:foo="http://www.w3.org/1999/xhtml" ... />

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.