Latest web development tutorials

<: Elegir XSL> elemento XSLT

<Xsl: choose> se utiliza en conjunción <xsl: when> y <xsl: otherwise> para expresar múltiples pruebas condicionales.


elemento: <Xsl elegir>

gramática

<xsl:choose>
<xsl:when test="expression">
... some output ...
</xsl:when>
<xsl:otherwise>
... some output ....
</xsl:otherwise>
</xsl:choose>


Lugar donde los criterios de selección

Para insertar el archivo XML para múltiples condiciones de ensayo, agregar al archivo XSL <xsl: choose>, <xsl: when> y <xsl: otherwise> elemento:

Ejemplos

<?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>
<h2>My CD Collection</h2>
<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>
<xsl:choose>
<xsl:when test="price &gt; 10">

<td bgcolor="#ff00ff">
<xsl:value-of select="artist"/></td>
</xsl:when>
<xsl:otherwise>

<td><xsl:value-of select="artist"/></td>
</xsl:otherwise>
</xsl:choose>

</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

Trate »

El código de seguridad será más alto que el precio del CD 10 columnas añadir un color de fondo de color rosa a "Artista".


Otro ejemplo

Esta es otra contiene dos <xsl: when> elemento de ejemplo:

Ejemplos

<?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>
<h2>My CD Collection</h2>
<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>
<xsl:choose>
<xsl:when test="price &gt; 10">

<td bgcolor="#ff00ff">
<xsl:value-of select="artist"/></td>
</xsl:when>
<xsl:when test="price &gt; 9">

<td bgcolor="#cccccc">
<xsl:value-of select="artist"/></td>
</xsl:when>
<xsl:otherwise>

<td><xsl:value-of select="artist"/></td>
</xsl:otherwise>
</xsl:choose>

</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

Trate »

El código de seguridad es mayor al 10 o "artista" columna para añadir un color de fondo de color rosa en el precio del CD, y más de 9 y menos que el precio del CD es igual a 10 a la columna de "artista" para añadir un color de fondo gris.