共用方式為


ms:type-local-name([node-set]) 函式

針對目前節點或提供之節點集內的第一個節點傳回 XSD 型別的非限定名稱 (依文件順序)。

string ms:type-local-name([node-set])

備註

若為簡單型別,type-local-name 函式會傳回名稱,例如 "ID" 或 "ENTITY"。 若為已指定 name 屬性的複雜 XSD 型別,type-local-name 將傳回非限定的名稱,例如 "Class"。 無名稱型別會使得函式傳回空字串。

下列範例運算式會選取含 XSD 內建基本資料型別 "string" 的所有節點。

"//*[ms:type-local-name()='string')]"

範例

下列範例使用 XSLT 範本規則來選取 books.xml 中的所有項目,以及輸出 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="/">
     <H3>nodes of all data types:</H3>
     <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="*">
     <DIV>
          <xsl:value-of select="name()"/> is of 
          <xsl:value-of select="ms:type-local-name()"/> 
     </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");
         result = "<h2>Used in an XSLT</h2>";

         result += objxml.transformNode(objxsl);
         document.body.innerHTML = result;

       }
       catch (e) {
         alert(e.description);
       }
      }
    </script>
  </head>

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

ms256098.collapse_all(zh-tw,VS.120).gif輸出

x:catalog is of

book is of

author is of string

Gambardella, Matthew

title is of string

XML Developer's Guide

genre is of string

Computer

price is of float

44.95

publish_date is of date

2000-10-01

description is of string

An in-depth look at creating applications with XML.

請注意,x:catalog 和 book 項目具有無名稱的資料型別。

請參閱

參考

XML 結構描述 (XSD) 參考

XML 資料型別參考

概念

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