XSLT <xsl:value-of>Elemento
Manual de referencia de elementos XSLT
Definición y uso
El elemento <xsl:value-of> puede extraer el valor del nodo seleccionado.
El elemento <xsl:value-of> se puede utilizar para seleccionar el valor de un elemento XML y mostrarlo en la salida.
Sintaxis
<xsl:value-of
select="expression"
disable-output-escaping="yes|no" />
Atributos
| Atributos | Valor | Descripción |
|---|---|---|
| select | expression | Obligatorio. Una expresión XPath que especifica de qué nodo/atributo extraer el valor. Su funcionamiento es similar a la navegación por un sistema de archivos seleccionando subdirectorios mediante barras diagonales (/). |
| disable-output-escaping | yes no |
Opcional. Si el valor es "yes", los nodos de texto generados al instanciar el elemento <xsl:text> no se escaparán al emitirlos. Por ejemplo, "<" se emitirá como "<". Si el valor es "no", entonces "<" se emitirá como "<". El valor predeterminado es "no". |
Ejemplos
El siguiente ejemplo obtiene los valores del primer elemento title y del elemento artist, y los coloca en una tabla:
Ejemplo 1
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Music Collection:</h1>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<tr>
<td><xsl:value-of select="catalog/cd/title" /></td>
<td><xsl:value-of select="catalog/cd/artist" /></td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Music Collection:</h1>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<tr>
<td><xsl:value-of select="catalog/cd/title" /></td>
<td><xsl:value-of select="catalog/cd/artist" /></td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Pruébalo »
El siguiente ejemplo recorre en bucle cada elemento cd y crea filas de tabla con los valores de title y artist de cada elemento cd:
Ejemplo 2
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Music Collection:</h1>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title" /></td>
<td><xsl:value-of select="artist" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Music Collection:</h1>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title" /></td>
<td><xsl:value-of select="artist" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Pruébalo »
Manual de referencia de elementos XSLT Otras extensiones