Compartir a través de


Función starts-with

Devuelve un valor verdadero si la cadena del primer argumento comienza con la cadena del segundo argumento; en caso contrario, el valor que devuelva será falso.

boolean starts-with(string, string)

Comentarios

Si un argumento no es de tipo cadena, primero se convierte en una cadena mediante la función string() y, a continuación, se evalúa el resultado de dicha conversión.

Advertencia

Las conversiones de cadenas para conjuntos de nodos que se pasan a esta función como argumentos pueden arrojar resultados inesperados.Para obtener más información, vea Función string.

La función distingue mayúsculas de minúsculas.

Ejemplo

En el siguiente ejemplo se ilustra el uso de la función starts-with() para consultar una colección de libros cuyo título comienza con la letra mayúscula "W".

Archivo XML (starts-with.xml)

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" 

href="contains.xsl"?>      
<bookstore>
  <book>
     <title>The Weather Pattern</title>
     <author>Weather Man</author>
     <price>100.00</price>
  </book>
  <book>
     <title>Weaving Patterns</title>
     <author>Weaver</author>
     <price>150.00</price>
  </book>
  <book>
     <title>Speech Pattern</title>
     <author>Speaker</author>
     <price>15.00</price>
  </book>
  <book>
     <title>Writing Style</title>
     <author>Writer</author>
     <price>1500.00</price>
  </book>
</bookstore>

Archivo XSLT (starts-with.xsl)

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"           

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="html"   
     omit-xml-declaration="yes"/>

  <xsl:template match="/">
    <html>
       <head><title>example</title></head>
    <body>
       <xsl:apply-templates select="//book"/>
    </body>
    </html>
  </xsl:template>

  <xsl:template match="book">
     <xsl:if test="starts-with(title, 'W')">
       <DIV>
         <B><xsl:value-of select="title"/></B> by 
         <I><xsl:value-of select="author"/></I> costs
         <xsl:value-of select="price"/>.
       </DIV>
     </xsl:if>
  </xsl:template>

</xsl:stylesheet>

Resultados

Esta hoja de estilos XSLT, cuando se aplica al archivo XML (starts-with.xml) produce el siguiente resultado:

Weaving Patterns by Weaver cuesta 150,00.

Writing Style by Writer cuesta 1500,00.

Vea también

Referencia

Referencia de tipos de datos XML