|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Namespace name from node?
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








