测试当前节点的数据类型是否属于给定的命名空间。 数据类型和命名空间在参数中指定。
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 文件包含处理加载 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");
// 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