Compartir a través de


Función ms:type-namespace-uri( )

Devuelve el identificador URI de espacio de nombres asociado con el tipo de datos XSD del nodo actual o el primer nodo (en el orden de documento) del conjunto de nodos proporcionado.

string ms:type-namespace-uri([node-set])

Comentarios

Para tipos XSD sencillos, la función type-namespace-uri devuelve una cadena vacía. Para tipos XSD complejos que disponen del atributo name especificado, la función type-namespace-uri devuelve un URI completo como "http://www.example.microsoft.com/my-xsd-types."

La siguiente expresión de muestra devuelve nodos cuyo tipo de datos dispone de un espacio de nombres URI de "PurchaseOrderType".

//*[ms:type-namespace-uri()='uri:PurchaseOrderType')]

Ejemplo

En el siguiente ejemplo se utiliza una regla de plantilla XSLT para seleccionar todos los elementos de books.xml y dar como resultado los tipos de datos de los elementos y el URI de espacio de nombres tal y como se define en books.xsd.

Archivo XML (books.xml)

Utilice books.xml.

Archivo XSD (books.xsd)

Utilice books.xsd.

Archivo 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:output method="html"   
     omit-xml-declaration="yes"/>

  <xsl:template match="/">
     <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="*">
    <DIV>
       <xsl:value-of select="name()"/> is of
       "<xsl:value-of select="ms:type-local-name()"/>" in 
       "<xsl:value-of select="ms:type-namespace-uri()"/>" 
    </DIV>
    <xsl:apply-templates/>
  </xsl:template>

</xsl:stylesheet>

Archivo HTML (books.html)

El archivo HTML contiene una instrucción JScript que controla la carga de archivos XML, XSLT y XSD.

<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");

         result += objxml.transformNode(objxsl);
         document.body.innerHTML = result;
         
       }
       catch (e) {
         alert(e.description);
       }
      }
    </script>
  </head>

  <body onload="init()">
  </body>
</html>

Resultados

x:catalog is of "" in "" 
book is of "" in "" 
author is of "string" in "http://www.w3.org/2001/XMLSchema" 
title is of "string" in "http://www.w3.org/2001/XMLSchema" 
genre is of "string" in "http://www.w3.org/2001/XMLSchema" 
price is of "float" in "http://www.w3.org/2001/XMLSchema" 
publish_date is of "date" in "http://www.w3.org/2001/XMLSchema" 
description is of "string" in "http://www.w3.org/2001/XMLSchema"
description is of "string" in "http://www.w3.org/2001/XMLSchema"

Observe que los elementos x:catalog y book contienen tipos de datos anónimos. De este modo, las funciones ms:type-local-name() y ms:type-namespace-uri() devuelven una cadena vacía.

Vea también

Referencia

Referencia de esquemas XML (XSD)
Referencia de tipos de datos XML

Conceptos

Utilización de funciones de extensiones de XPath para conseguir compatibilidad con XSD