현재 노드의 데이터 형식이 지정된 네임스페이스에 속하는지 여부를 테스트합니다. 인수에 데이터 형식과 네임스페이스를 지정합니다.
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 템플릿 규칙을 사용하여 데이터 형식이 date
인 books.xml에서 요소를 모두 선택합니다. 또한 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