
April 29th, 2011, 11:40 AM
|
|
|
please not use for-each for little exsample
xsl:param as variable to modify xsl result
better think xsl
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:output indent="yes" method="html"/>
<xsl:param name="kind_of" select="'fiction'"/>
<xsl:param name="borderprice" select="30"/>
<xsl:template match="/">
<html>
<style><![CDATA[
table{
border: 2px solid black;
}
th,td{
border: 2px solid black;
}
tr{
text-align: center;
}
tr.head{
text-align: center;
background-color:#ff0000;
}
tr.odd{
background-color:#ff9900;
}
tr.even{
background-color:#ff0099;
}
tr.sum{
background-color:#aa0099;
text-align: center;
}
]]>
</style>
<body>
<table border="1">
<tr class="head">
<th>Title</th>
<th>Author</th>
<th>Price</th>
</tr>
<xsl:apply-templates select="books/book[title/@type =$kind_of][price < $borderprice]"/>
<tr class="sum">
<td colspan="2">
<xsl:text>*</xsl:text>
</td>
<td>
<xsl:value-of select="sum(books/book[title/@type =$kind_of][price < $borderprice]/price)"/>
</td>
</tr>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="book">
<tr>
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="position() mod 2 = 1">odd</xsl:when>
<xsl:otherwise>even</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<td>
<xsl:value-of select="title"/>
</td>
<td>
<xsl:value-of select="author"/>
</td>
<td>
<xsl:value-of select="price"/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
result html code with css
Code:
<html>
<style>
table{
border: 2px solid black;
}
th,td{
border: 2px solid black;
}
tr{
text-align: center;
}
tr.head{
text-align: center;
background-color:#ff0000;
}
tr.odd{
background-color:#ff9900;
}
tr.even{
background-color:#ff0099;
}
tr.sum{
background-color:#aa0099;
text-align: center;
}
</style>
<body>
<table border="1">
<tr class="head">
<th>Title</th>
<th>Author</th>
<th>Price</th>
</tr>
<tr class="odd">
<td>The Dilemma</td>
<td>Sonia and Nicole</td>
<td>25</td>
</tr>
<tr class="even">
<td>Secretariat</td>
<td>Harry</td>
<td>20</td>
</tr>
<tr class="sum">
<td colspan="2"> </td>
<td>45</td>
</tr>
</table>
</body>
</html>
__________________
Helmut Hagemann Germany
fallen to the bottom of the facts?
I reach my hand and we go together
wer lesen und google kann ist klar im Vorteil
who read and google is able is clear in the advantage
|