ms:type-namespace-uri( ) 函数

返回与当前节点或所提供节点集中的第一个节点(按文档顺序)的 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.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>

输出

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"

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

另请参见

参考

XML 架构 (XSD) 参考
XML 数据类型引用

概念

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