Returns the namespace URI associated with the XSD data type of a current node or the first node (in document order) in the provided node-set.
string ms:type-namespace-uri([node-set])
For simple XSD types, the type-namespace-uri
function returns an empty string. For complex XSD types that have the name
attribute specified, the type-namespace-uri
function returns a complete URI such as "http://www.example.microsoft.com/my-xsd-types."
The following sample expression returns nodes whose data type has a namespace URI of "PurchaseOrderType".
"//*[ms:type-namespace-uri()='uri:PurchaseOrderType')]"
The following example uses an XSLT template rule to select from books.xml all the elements and to output the elements data types and the namesapce URI as defined in books.xsd.
XML File (books.xml)
Use books.xml.
XSD File (books.xsd)
Use books.xsd.
XSLT File (books.xslt)
<?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:output method="html" omit-xml-declaration="yes"/> <xsl:template match="/"> <xsl:apply-templates/> </xsl:template> <xsl:template match="*"> <DIV> <xsl:value-of select="name()"/> is of "<xsl:value-of select="
ms:type-local-name()"/>" in
"<xsl:value-of select="
ms:type-namespace-uri()"/>"
</DIV>
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
HTML File (books.html)
The HTML file contains a JScript that handles loading XML, XSLT, and XSD files.
<html> <head> <script> function init() { try { var objxsd = new ActiveXObject("Msxml2.XMLSchemaCache.5.0"); var objxml = new ActiveXObject("Msxml2.DOMDocument.5.0"); var objxsl = new ActiveXObject("Msxml2.DOMDocument.5.0"); // namespace uri ("urn:books") must be declared as one of the // namespace delarations in the "books.xml" that is an instance // of "books.xsd" objxsd.add("urn:books", "books.xsd"); objxml.schemas = objxsd; objxml.setProperty("SelectionLanguage", "XPath"); objxml.setProperty("SelectionNamespaces", "xmlns:ms='urn:schemas-microsoft-com:xslt'"); objxml.async=false; objxml.validateOnParse=true; objxml.load("books.xml"); objxsl.async=false; objxsl.load("books.xsl"); result += objxml.transformNode(objxsl); document.body.innerHTML = result; } catch (e) { alert(e.description); } } </script> </head> <body onload="init()"> </body> </html>
Output
x:catalog is of "" in "" book is of "" in "" author is of "string" in "http://www.w3.org/2001/XMLSchema" title is of "string" in "http://www.w3.org/2001/XMLSchema" genre is of "string" in "http://www.w3.org/2001/XMLSchema" price is of "float" in "http://www.w3.org/2001/XMLSchema" publish_date is of "date" in "http://www.w3.org/2001/XMLSchema" description is of "string" in "http://www.w3.org/2001/XMLSchema"
description is of "string" in "http://www.w3.org/2001/XMLSchema"
Notice that x:catalog
and book
elements have anonymous data types. Thus, both the ms:type-local-name()
and ms:type-namespace-uri()
function return an empty string.
Using XPath Extension Functions for XSD Support | Data Types in Schemas | XML Schema Reference (XSD) | XML Data Types Reference