我是XSLT语言的新手,所以我现在不知道如何做到这一点..我希望按表中的类别对所有行进行排序,除了count产品..我不想影响count_products的顺序。 。请帮助......我到目前为止所做的代码
<?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>
答案 0 :(得分:1)
如果您希望对行进行排序,但count_products
列按文档顺序排列,那么您需要这样的技巧:
<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>
从第n个产品中取出count_products
子项,无论应用于for-each的分类如何。
当然,如果count_products
实际上只是一个计数器(1,2,3,......),那么您可以直接使用<xsl:value-of select="$pos" />
。