ms:namespace-uri Function

Resolves the prefix part of a qualified name into a namespace URI.

string ms:namespace-uri(string)

Remarks

The ms:namespace-uri() function assumes that the parameter is a qualified name (for example, q:mine or coffee:beans) and attempts to resolve its prefix in the context of the current node. If the argument is not a qualified name or a noncolon name, this function returns an empty string. For nonstring arguments, this function behaves as if a string() function were applied.

Example

The following example uses an XSLT template rule to select all the elements in books.xml, and to output the elements' data types and the namesapce URI as defined in books.xsd.

XML File (books.xml)

Use the XML file in Using XPath Extension Functions for XSD Support.

XSD File (books.xsd)

Use the XSD file in Using XPath Extension Functions for XSD Support.

HTML File (books.html)

The HTML file is the same as that listed in the ms:type-namespace-uri([node-set]) Function topic.

XSLT File (books.xsl)

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" 
     xmlns:ms="urn:schemas-microsoft-com:xslt"   
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="text()"/>
  <xsl:output method="html"   
     omit-xml-declaration="yes"/>

  <xsl:template match="/">
     <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="*">
    <xsl:if test="ms:type-namespace-uri() != ''">
      <DIV>
          (ms:) 
          <xsl:value-of select="ms:namespace-uri(name())"/>:
          <xsl:value-of select="ms:local-name(name())"/>
      </DIV>
      <DIV>
          (std:) 
          <xsl:value-of select="namespace-uri()"/>:
          <xsl:value-of select="local-name()"/>
      </DIV>
      <DIV>
          (name():) 
          <xsl:value-of select="name()"/> 
      </DIV>
    </xsl:if>
    <xsl:apply-templates/>
  </xsl:template>

</xsl:stylesheet>

Output

(ms:) urn:books:catalog

(std:) urn:books:catalog

(name():) x:catalog

The first line of the output is the result returned by the ms:namespace-uri(string) plusms:local-name(string). The second line is the results from the standard XPath function, namespace-uri(nodeset), local-name(nodeset). The third line is the result from the standard XPath function,name(nodeset).

See Also

Reference

XML Schemas (XSD) Reference
XML Data Types Reference