Ok, I'm tried really hard to figure out this. I'm developing a php aplication and decided to try to make a XSLT based datagrid.
I'm generating my XML from a Script, this means, The XSL must read n colluns
A xml like this
Code:
<?xml version="1.0" encoding="utf-8" ?>
- <grid>
- <iten>
<id>1</id>
<nome>Jo?o Amaro Lagedo</nome>
<tel_residencial>2425-3352</tel_residencial>
<tel_comercial>5551-5545</tel_comercial>
<data_nascimento>2006-09-09</data_nascimento>
</iten>
+ <iten>
<id>2</id>
<nome>Neyde De Almeida Ferreida</nome>
<tel_residencial>555-58585</tel_residencial>
<tel_comercial />
<data_nascimento>2006-09-09</data_nascimento>
</iten>
- <iten>
<id>3</id>
<nome>Nilma Almeida Ferreira</nome>
<tel_residencial>256-1248</tel_residencial>
<tel_comercial />
<data_nascimento>2006-09-09</data_nascimento>
</iten>
</grid>
and XSL
Code:
<?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 Itens</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">id</th>
<th align="left">nome</th>
<th align="left">tel_residencial</th>
<th align="left">tel_comercial</th>
<th align="left">data_nascimento</th>
</tr>
<xsl:for-each select="grid/iten">
<tr>
/* Its here... I need to loop these nodes, instead of calling
them by their names, so I can use a xslt file for any xml in my
system */
<td><xsl:value-of select="id" /></td>
<td><xsl:value-of select="nome" /></td>
<td><xsl:value-of select="tel_residencial" /></td>
<td><xsl:value-of select="tel_comercial" /></td>
<td><xsl:value-of select="data_nascimento" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Is there anyway a xsl can deal with dynamic xls ? I mean I need to add more nodes or remove, help ;) ?
EDIT: Nevermind... I found the solution in a very old post
Code:
<?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 Itens</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">id</th>
<th align="left">nome</th>
<th align="left">tel_residencial</th>
<th align="left">tel_comercial</th>
<th align="left">data_nascimento</th>
</tr>
<xsl:for-each select="grid/iten">
<tr>
<xsl:for-each select="descendant::*">
<td>
<xsl:value-of select="."/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>