ms:type-is 函式
測試目前節點的資料型別是否屬於指定的命名空間。 資料型別與命名空間都指定於引數中。
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。
範例
下列範例使用 XSLT 範本規則來選取 books.xml 之中所有資料型別為 date 的項目,如 books.xsd 中所定義。 此範例也說明如何使用 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 檔案含有 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");
// 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