xslt与html表排序特定的td



我是XSLT语言的新手,所以我现在不知道如何做到这一点。。除了计数乘积外,我想按类别对表中的所有行进行排序。。我不想影响订单。。请帮忙。。到目前为止我做的代码

<?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>

如果您希望对行进行排序,但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个乘积中取CCD_ 2子项,而不管应用于for each的排序如何。

当然,如果count_products实际上只是一个计数器(1,2,3,…),那么您可以直接使用<xsl:value-of select="$pos" />

最新更新