| namespace-uri() Function | |
| Returns the namespace URI of the first node in the argument node-set. | |
| Inputs | |
|
A node-set. If the node-set is omitted, the namespace-uri() function creates a node-set that has the context node as its only member. |
|
| Output | |
|
The namespace URI of the first node in the argument node-set. If the argument node-set is empty, the first node has no namespace URI, or the first node has a namespace URI that is null, an empty string is returned. Be aware that the namespace-uri() function returns an empty string for all nodes other than element and attribute nodes. |
|
| Defined in | |
|
XPath section 4.1, Node Set Functions. |
|
| Example | |
|
Here is a stylesheet that uses the document() function to examine its own nodes and then invoke the namespace-uri() against each of them:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:months="Lookup table for month names">
<months:name sequence="01">January</months:name>
<months:name sequence="02">February</months:name>
<months:name sequence="03">March</months:name>
<months:name sequence="04">April</months:name>
<months:name sequence="05">May</months:name>
<months:name sequence="06">June</months:name>
<months:name sequence="07">July</months:name>
<months:name sequence="08">August</months:name>
<months:name sequence="09">September</months:name>
<months:name sequence="10">October</months:name>
<months:name sequence="11">November</months:name>
<months:name sequence="12">December</months:name>
<xsl:output method="text"/>
<xsl:variable name="newline">
<xsl:text>
</xsl:text>
</xsl:variable>
<xsl:template match="/">
<xsl:value-of select="$newline"/>
<xsl:text>A test of the namespace-uri() function:</xsl:text>
<xsl:value-of select="$newline"/>
<xsl:value-of select="$newline"/>
<xsl:for-each select="document('')//*">
<xsl:text>namespace URI: </xsl:text>
<xsl:value-of select="namespace-uri()"/>
<xsl:value-of select="$newline"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Here are the results of our stylesheet: A test of the namespace-uri() function: namespace URI: http://www.w3.org/1999/XSL/Transform namespace URI: Lookup table for month names namespace URI: Lookup table for month names namespace URI: Lookup table for month names namespace URI: Lookup table for month names namespace URI: Lookup table for month names namespace URI: Lookup table for month names namespace URI: Lookup table for month names namespace URI: Lookup table for month names namespace URI: Lookup table for month names namespace URI: Lookup table for month names namespace URI: Lookup table for month names namespace URI: Lookup table for month names namespace URI: http://www.w3.org/1999/XSL/Transform namespace URI: http://www.w3.org/1999/XSL/Transform namespace URI: http://www.w3.org/1999/XSL/Transform namespace URI: http://www.w3.org/1999/XSL/Transform namespace URI: http://www.w3.org/1999/XSL/Transform namespace URI: http://www.w3.org/1999/XSL/Transform namespace URI: http://www.w3.org/1999/XSL/Transform namespace URI: http://www.w3.org/1999/XSL/Transform namespace URI: http://www.w3.org/1999/XSL/Transform namespace URI: http://www.w3.org/1999/XSL/Transform namespace URI: http://www.w3.org/1999/XSL/Transform namespace URI: http://www.w3.org/1999/XSL/Transform |
|