Reputation: 17
I'm new at XSLT language so i don't now how to do that..i want to sort all rows by category from table except the count products..i don't want to affect the order off count_products..please help..the code i have made so far
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<head>
<title></title>
<link rel="stylesheet" href="css/xsl_style.css" type="text/css"/>
</head>
<body>
<div class="tableStyle" >
<table>
<tr bgcolor="#B5E4EA">
<td>A/A</td>
<td>Product Name</td>
<td>Price</td>
<td>Corpration</td>
<td>Category</td>
</tr>
<xsl:for-each select="auction_products/product">
<xsl:sort select="category"/>
<tr>
<td><a href="live_auctions.php"><xsl:value-of select="count_products"/></a></td>
<td><a href="live_auctions.php"><xsl:value-of select="product_name"/></a></td>
<td><a href="live_auctions.php"><xsl:value-of select="price"/></a></td>
<td><a href="live_auctions.php"><xsl:value-of select="corporation"/></a></td>
<td><a href="live_auctions.php"><xsl:value-of select="category"/></a></td>
</tr>
</xsl:for-each>
</table>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Upvotes: 1
Views: 763
Reputation: 122394
If you want the rows to be sorted but the count_products
column to come out in document order then you'd need a trick like this:
<xsl:variable name="allProducts" select="auction_products/product" />
<xsl:for-each select="$allProducts">
<xsl:sort select="category"/>
<xsl:variable name="pos" select="position()" />
<tr>
<td><a href="live_auctions.php"><xsl:value-of select="$allProducts[$pos]/count_products"/></a></td>
<td><a href="live_auctions.php"><xsl:value-of select="product_name"/></a></td>
<td><a href="live_auctions.php"><xsl:value-of select="price"/></a></td>
<td><a href="live_auctions.php"><xsl:value-of select="corporation"/></a></td>
<td><a href="live_auctions.php"><xsl:value-of select="category"/></a></td>
</tr>
</xsl:for-each>
to take the count_products
child from the nth product regardless of the sorting applied to the for-each.
Of course, if count_products
is really just a counter (1, 2, 3, ...) then you could just use <xsl:value-of select="$pos" />
directly.
Upvotes: 1