次の方法で共有


ms:type-namespace-uri( ) 関数

指定されたノード セット内の現在のノード、または (ドキュメント順で) 最初のノードの XSD データ型に関連付けられている名前空間 URI を返します。

string ms:type-namespace-uri([node-set])

解説

XSD の単純型の場合、type-namespace-uri 関数は空の文字列を返します。name 属性が指定されている XSD の複合型の場合、type-namespace-uri 関数は、"http://www.example.microsoft.com/my-xsd-types." などの完全な URI を返します。

次のサンプル式は、"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 ファイルには、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:catalog 要素と book 要素は、匿名データ型であることに注意してください。そのため、ms:type-local-name()ms:type-namespace-uri() のどちらの関数も空の文字列を返します。

参照

リファレンス

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

概念

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