現在のノードのデータ型が指定された名前空間に属しているかどうかをテストします。データ型と名前空間は、引数で指定されます。
boolean ms:type-is(string URI, string local-name)
パラメータ
- string URI
現在のデータ型を評価するときの基準となるデータ型の名前空間 URI。
- string local-name
現在のデータ型を評価するときの基準となるデータ型のローカル名。
解説
現在のノードが指定された名前空間に属する指定されたデータ型であれば、関数は true を返します。それ以外の場合は、false を返します。local-name
が指定された名前空間 (URI
) で宣言されていないデータ型を参照する場合、関数は false を返します。指定された名前空間で定義されている名前のないデータ型を指定した場合も、関数は false を返します。
この関数は、XSD の継承を認識します。したがって、型 "b
" が "a
" から派生している場合、ノード型 "b
" を指定すると、type-is("http://www.example.microsoft.com/catalog", "a")
は true
を返します。
例
次の例では、books.xsd の定義に従い、XSLT テンプレート規則を使用して、books.xml 内でデータ型が date
であるすべての要素を選択します。また、XML DOM インスタンスを使用したクエリの実行方法も示しています。
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:template match="text()"/>
<xsl:output method="html"
omit-xml-declaration="yes"/>
<xsl:template match="/">
<H3>nodes of date data types:</H3>
<xsl:apply-templates select=
"//*[ms:type-is('http://www.w3.org/2001/XMLSchema','date')]"/>
</xsl:template>
<xsl:template match="*">
<DIV>
<xsl:value-of select="name()"/> =
<xsl:value-of select="."/>
</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");
// Select nodes of 'date" type using DOM:
var nodes = objxml.selectNodes("//*[ms:type-is(
'http://www.w3.org/2001/XMLSchema','date')]");
result ="<h2>used in a DOM</h2> ";
result += "<h3>nodes of date data types</h3>";
for (i=0; i<nodes.length; i++) {
result += "<DIV>"+nodes.item(i).nodeName
+"=>"+nodes.item(i).text+"</DIV>";
}
// Select nodes of 'date" type using 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>
出力
Publish_date = 2000-10-01
参照
リファレンス
XML スキーマ (XSD) リファレンス
XML データ型リファレンス