ms:type-namespace-uri([node-set]) 函数

返回与当前节点或所提供节点集中的第一个节点(按文档顺序)的 XSD 数据类型关联的命名空间 URI。

string ms:type-namespace-uri([node-set])

备注

对于简单 XSD 类型,type-namespace-uri 函数返回空字符串。 对于指定了 name 属性的复杂 XSD 类型,type-namespace-uri 函数返回完整的 URI,例如 "http://www.example.microsoft.com/my-xsd-types."

以下表达式示例返回数据类型的命名空间 URI 为“PurchaseOrderType”的节点。

//*[ms:type-namespace-uri()='uri:PurchaseOrderType')]

示例

以下示例使用 XSLT 模板规则,从 books.xml 中选择所有元素并输出元素数据类型和命名空间 URI(按 books.xsd 中的定义)。

XML 文件 (books.xml)

使用 books.xml

XSD 文件 (books.xsd)

使用 books.xsd

XSLT 文件 (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 文件 (books.html)

HTML 文件包含处理加载 XML、XSLT 和 XSD 文件过程的 JScript。

<html>
  <head>
    <script>
      function init() {
       try {
         var objxsd = new ActiveXObject("Msxml2.XMLSchemaCache.6.0");
         var objxml = new ActiveXObject("Msxml2.DOMDocument.6.0");
         var objxsl = new ActiveXObject("Msxml2.DOMDocument.6.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.xslt");

         document.body.innerHTML = objxml.transformNode(objxsl);         
       }
       catch (e) {
         alert(e.description);
       }
      }
    </script>
  </head>

  <body onload="init()">
  </body>
</html>

ms256130.collapse_all(zh-cn,VS.120).gif输出

x:catalog is of "" in "" 
book is of "" in "" 
author is of "string" in "http://www.w3.org/2001/XMLSchema" 
Gambardella, Matthew
title is of "string" in "http://www.w3.org/2001/XMLSchema" 
XML Developer's Guide
genre is of "string" in "http://www.w3.org/2001/XMLSchema" 
Computer
price is of "float" in "http://www.w3.org/2001/XMLSchema" 
44.95
publish_date is of "date" in "http://www.w3.org/2001/XMLSchema" 
2000-10-01
description is of "string" in "http://www.w3.org/2001/XMLSchema" 
An in-depth look at creating applications with XML.

请注意,x:catalog 和 book 元素具有匿名数据类型。 因此,ms:type-local-name() 和 ms:type-namespace-uri() 函数都返回空字符串。

请参见

参考

XML 架构 (XSD) 参考

XML 数据类型引用

概念

使用针对 XSD 的 XPath 扩展函数支持