pdaniel2006
10-03-06, 09:58 AM
This are my files :
dtest.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="dtest.xsl"?>
<masini>
<model>
<producator>AUDI</producator>
<motor>100CP</motor>
<vitezaMaxima>300km/h</vitezaMaxima>
<pret>20</pret>
</model>
<model>
<producator>BMW</producator>
<motor>1000CP</motor>
<vitezaMaxima>500Km/h</vitezaMaxima>
<pret>151</pret>
</model>
<model>
<producator>Renault</producator>
<motor>0,9Cp</motor>
<vitezaMaxima>12km/h</vitezaMaxima>
<pret>10</pret>
</model>
<model>
<producator>VW</producator>
<motor>100CP</motor>
<vitezaMaxima>500Km/h</vitezaMaxima>
<pret>15</pret>
</model>
</masini>
dtest.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<table>
<!--<xsl:for-each select="masini/model">-->
<xsl:apply-templates />
<!-- <xsl:value-of select="producator" />-->
<!--</xsl:for-each>-->
<xsl:for-each select="masini/model">
<xsl:choose>
<xsl:when test="pret mod 2 = 0">
<tr bgcolor="red">
<td>
<xsl:value-of select="producator"/>
</td>
<td>
<xsl:value-of select="motor"/>
</td>
<td>
<xsl:value-of select="vitezaMaxima"/>
</td>
<td>
<xsl:value-of select="pret"/>
</td>
</tr>
</xsl:when>
<xsl:otherwise>
<tr bgcolor="c1c1c1">
<td>
<xsl:value-of select="producator"/>
</td>
<td>
<xsl:value-of select="motor"/>
</td>
<td>
<xsl:value-of select="vitezaMaxima"/>
</td>
<td>
<xsl:value-of select="pret"/>
</td>
</tr>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="masini">
<tr>
<xsl:apply-templates />
</tr>
</xsl:template>
<xsl:template match="model">
<td>
<xsl:value-of select="name(child::node())" />
</td>
</xsl:template>
</xsl:stylesheet>
How you can see, with this expresion : <xsl:value-of select="name(node())" /> i take the child from model node. The problem is that it takes me only the first childe name, in my case "producator". I whant to take all the childrens names of that node (producator,motor,vitezaMaxima,pret). I have tried a for-each but doesen't work. Any ideas?
dtest.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="dtest.xsl"?>
<masini>
<model>
<producator>AUDI</producator>
<motor>100CP</motor>
<vitezaMaxima>300km/h</vitezaMaxima>
<pret>20</pret>
</model>
<model>
<producator>BMW</producator>
<motor>1000CP</motor>
<vitezaMaxima>500Km/h</vitezaMaxima>
<pret>151</pret>
</model>
<model>
<producator>Renault</producator>
<motor>0,9Cp</motor>
<vitezaMaxima>12km/h</vitezaMaxima>
<pret>10</pret>
</model>
<model>
<producator>VW</producator>
<motor>100CP</motor>
<vitezaMaxima>500Km/h</vitezaMaxima>
<pret>15</pret>
</model>
</masini>
dtest.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<table>
<!--<xsl:for-each select="masini/model">-->
<xsl:apply-templates />
<!-- <xsl:value-of select="producator" />-->
<!--</xsl:for-each>-->
<xsl:for-each select="masini/model">
<xsl:choose>
<xsl:when test="pret mod 2 = 0">
<tr bgcolor="red">
<td>
<xsl:value-of select="producator"/>
</td>
<td>
<xsl:value-of select="motor"/>
</td>
<td>
<xsl:value-of select="vitezaMaxima"/>
</td>
<td>
<xsl:value-of select="pret"/>
</td>
</tr>
</xsl:when>
<xsl:otherwise>
<tr bgcolor="c1c1c1">
<td>
<xsl:value-of select="producator"/>
</td>
<td>
<xsl:value-of select="motor"/>
</td>
<td>
<xsl:value-of select="vitezaMaxima"/>
</td>
<td>
<xsl:value-of select="pret"/>
</td>
</tr>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="masini">
<tr>
<xsl:apply-templates />
</tr>
</xsl:template>
<xsl:template match="model">
<td>
<xsl:value-of select="name(child::node())" />
</td>
</xsl:template>
</xsl:stylesheet>
How you can see, with this expresion : <xsl:value-of select="name(node())" /> i take the child from model node. The problem is that it takes me only the first childe name, in my case "producator". I whant to take all the childrens names of that node (producator,motor,vitezaMaxima,pret). I have tried a for-each but doesen't work. Any ideas?