次の方法で共有


ms:type-local-name( ) 関数

指定されたノード セット内の現在のノード、または (ドキュメント順で) 最初のノードの 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.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 += "<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>

出力

x:catalog is of

book is of

author is of string

title is of string

genre is of string

price is of float

publish_date is of date

description is of string

x:catalog 要素と book 要素は、名前のないデータ型であることに注意してください。

参照

リファレンス

XML スキーマ (XSD) リファレンス
XML データ型リファレンス

概念

XSD サポートに XPath 拡張関数を使用する