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 文件包含处理加载 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");
         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-cn,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 数据类型引用

概念

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