Compartir a través de


Función ms:type-local-name( )

Devuelve el nombre incompleto del tipo XSD del nodo actual o el primer nodo (en el orden de documento) del conjunto de nodos proporcionado.

string ms:type-local-name([node-set])

Comentarios

Para tipos simples, la función type-local-name devuelve un nombre como una "ID" o "ENTITY". Para tipos XSD complejos que disponen del atributo name especificado, la función type-local-name devuelve un nombre no completo como "Class". Los tipos sin nombre hacen que la función devuelva una cadena vacía.

La siguiente expresión de muestra selecciona todos los nodos con el tipo de datos primitivo incorporado XSD "cadena".

"//*[ms:type-local-name()='string')]"

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 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="/">
     <H3>nodes of all data types:</H3>
     <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="*">
     <DIV>
          <xsl:value-of select="name()"/> is of 
          <xsl:value-of select="ms:type-local-name()"/> 
     </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 += "<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>

Resultados

x:catalog is of

book is of

author is of string

title is of string

genre is of string

price is of float

publish_date is of date

description is of string

Observe que los elementos x:catalog y book contienen tipos sin nombre.

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