Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

ms:type-is Function

Tests whether the current node's data type belongs to the given namespace. The data type and the namespace are specified in the arguments.


          boolean ms:type-is(string URI, string local-name)
string URI
The namespace URI for the data type against which the current data type is evaluated.

string local-name
The local name of the data type against which the current data type is evaluated.

The function returns true if the current node is of the specified data type belonging to the given namespace. Otherwise it returns false. If local-name refers to a data type undeclared in the given namespace (URI), the function returns false. Nameless data types defined in the given namespace cause the function to return false as well.

This function is aware of XSD inheritence, so that if type "b" is derived from "a", then for the node of type "b", type-is("http://www.example.microsoft.com/catalog", "a") returns true.

The following example uses an XSLT template rule to select all the elements in books.xml whose data type is date, as defined in books.xsd. The example also shows how to do the query using an XML DOM instance.

XML File (books.xml)

Use books.xml.

XSD File (books.xsd)

Use books.xsd.

XSLT File (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 File (books.html)

The HTML file contains a JScript that handles loading XML, XSLT, and XSD files.

<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>

Output

Publish_date = 2000-10-01




Build Date:

2012-08-02
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.