共用方式為


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."

下列運算式範例可傳回節點,該節點的資料型別具有 "PurchaseOrderType" 的命名空間 URI。

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

範例

下列範例會使用 XSLT 範本規則,從 books.xml 選取所有項目,以及輸出 books.xsd 中定義的項目資料型別和命名空間 URI。

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 檔案含有 JScript,可處理 XML、XSLT 與 XSD 檔案的載入作業。

<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-tw,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 資料型別參考

概念

使用 XPath 擴充程式函式以獲得 XSD 支援