1

Source:

    <Data>
    <heading xmlns="Some Uri">
                <text>aaa</text>


    </heading>
    <Data>

XSLT wrote

            <?xml version="1.0" encoding="utf-8"?>
            <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:link1="Some Uri">
                <xsl:output method="xml" indent="yes"/>

                  <xsl:template match="Data">
                    <xsl:value-of select="link1:heading/namespace-uri()"/>

                  </xsl:template>


            </xsl:stylesheet>

I am getting error.

Can any one help how to do get the namespace.

Thank you.

Patan
  • 17,073
  • 36
  • 124
  • 198

2 Answers2

1

nonnb should have made the comment an answer...

The namespace-uri() function does what you want.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • I tried with that I am getting errors. I have edited the question with the thing I have done. – Patan May 31 '12 at 09:54
  • I have edited the question and I am unable to get the name space of the node. Can you help me how to do that – Patan May 31 '12 at 09:58
1
<xsl:value-of select="link1:heading/namespace-uri()"/>

In XSLT 1.0 / XPath 1.0 this is a syntax error.

Correct this to:

<xsl:value-of select="namespace-uri(link1:heading)"/> 

In XSLT 2.0 / XPath 2.0 this again is an error (the argument for namespace-uri() cannot be ommitted. Correct to:

<xsl:value-of select="link1:heading/namespace-uri(.)"/>
Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
  • I think select="link1:heading/namespace-uri()" should work in XSLT 2.0. – Michael Kay May 31 '12 at 15:51
  • @MichaelKay: Maybe you are right -- I find it difficult and unnecessary to remember exactly which functions can have their argument omitted and which not -- so it is safer to always provide the argument. – Dimitre Novatchev May 31 '12 at 16:04