我有一个如下所示的 XSLT,并且想apply-templates
在元素内部使用,xsl:for-each
因此我不必使用“ ” XML 元素<tr>
的信息重复该元素。cliente
我正在尝试但没有成功创建一个xsl:template
并xsl:apply-templates
放入xsl:for-each
.
我知道我可以使用xsl:call-template
,但是有什么方法可以xsl:apply-templates
在里面或外面使用for-each
吗?
关于如何做到这一点的任何想法?
<?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>
<head><title>Informações</title></head>
<body>
<h1>Relação de Clientes</h1>
<table border="2">
<tr bgcolor="LightBlue">
<th>Nome</th>
<th>Telefone</th>
<th>Cidade</th>
<th>Estado</th>
<th>Crédito</th>
</tr>
<tr>
<th colspan="6" bgcolor="LightPink">Critério usado abaixo: exibir todos os elementos ordenado por nome</th>
</tr>
<xsl:for-each select="informacoes/cliente">
<xsl:sort select="nome" order="ascending" />
<tr>
<td bgcolor="LightGreen"><xsl:value-of select="nome"/></td>
<td><xsl:value-of select="telefone"/></td>
<td><xsl:value-of select="cidade"/></td>
<td><xsl:value-of select="estado"/></td>
<td><xsl:value-of select="credito"/></td>
</tr>
</xsl:for-each>
<tr>
<th colspan="6" bgcolor="LightCyan"> Critério usado abaixo: exibir os clientes da cidade do Rio de Janeiro</th>
</tr>
<xsl:for-each select="informacoes/cliente">
<xsl:if test="cidade='Rio de Janeiro'">
<tr>
<td bgcolor="LightGreen"><xsl:value-of select="nome"/></td>
<td><xsl:value-of select="telefone"/></td>
<td><xsl:value-of select="cidade"/></td>
<td><xsl:value-of select="estado"/></td>
<td><xsl:value-of select="credito"/></td>
</tr>
</xsl:if>
</xsl:for-each>
<tr>
<th colspan="6" bgcolor="LightYellow"> Critério usado abaixo: exibir os clientes do estado do RJ com ordenado pelo nome; </th>
</tr>
<xsl:for-each select="informacoes/cliente">
<xsl:sort select="nome" order="ascending" />
<xsl:if test="estado='RJ'">
<tr>
<td bgcolor="LightGreen"><xsl:value-of select="nome"/></td>
<td><xsl:value-of select="telefone"/></td>
<td><xsl:value-of select="cidade"/></td>
<td><xsl:value-of select="estado"/></td>
<td><xsl:value-of select="credito"/></td>
</tr>
</xsl:if>
</xsl:for-each>
<tr>
<th colspan="6" bgcolor="LightYellow"> Critério usado abaixo: exibir os clientes com crédito entre 250 e 400, em ordem descendente de crédito) </th>
</tr>
<xsl:for-each select="informacoes/cliente">
<xsl:sort select="credito" order="descending" />
<xsl:if test="credito>250 and credito<400">
<tr>
<td bgcolor="LightGreen"><xsl:value-of select="nome"/></td>
<td><xsl:value-of select="telefone"/></td>
<td><xsl:value-of select="cidade"/></td>
<td><xsl:value-of select="estado"/></td>
<td><xsl:value-of select="credito"/></td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>