每秒的真假总数

时间:2018-04-24 17:58:55

标签: xslt-2.0 xpath-2.0

我正在提到这个问题Total of true and false in current time。我想知道是否可以像链接一样获得相同的结果,但总的真假将是每秒。

想要的结果

<html>
   <head>
   </head>
   <body>
      <h2>audi</h2>
      <table>
         <thead>
            <tr>
               <th>Total of samples per second</th>
               <th>Time</th>
               <th>Total of TRUE</th>
               <th>Total of FALSE</th>
            </tr>
         </thead>
         <tbody>
            <tr>
               <td>3</td>
               <td>1950</td>
               <td>2</td>
               <td>1</td>
            </tr>
            <tr>
               <td>2</td>
               <td>2300</td>
               <td>1</td>
               <td>1</td>
            </tr>
         </tbody>
      </table>
      <h2>renault</h2>
      <table>
         <thead>
            <tr>
               <th>Total of samples per second</th>
               <th>Time</th>
               <th>Total of TRUE</th>
               <th>Total of FALSE</th>
            </tr>
         </thead>
         <tbody>
            <tr>
               <td>2</td>
               <td>1500</td>
               <td>2</td>
               <td>0</td>
            </tr>
            <tr>
               <td>2</td>
               <td>2800</td>
               <td>1</td>
               <td>1</td>
            </tr>
         </tbody>
      </table>
   </body>
</html>

感谢你的想法

1 个答案:

答案 0 :(得分:0)

因此,您不必直接输出已排序的序列,而是希望按@time idiv 1000

进行分组
  <xsl:template match="trade">
      <xsl:for-each-group select="car" group-by="@brand">
          <h2>{current-grouping-key()}</h2>
          <table>
              <thead>
                  <tr>
                      <th>Total of samples</th>
                      <th>Time</th>
                      <th>Total of TRUE</th>
                      <th>Total of FALSE</th>
                  </tr>
              </thead>
              <xsl:variable name="sorted-cars" as="element(car)*">
                  <xsl:perform-sort select="current-group()">
                      <xsl:sort select="xs:integer(@time)"/>
                  </xsl:perform-sort>
              </xsl:variable>
              <tbody>
                  <xsl:for-each-group select="$sorted-cars" group-adjacent="@time idiv 1000">
                      <tr>
                          <td>{count(current-group())}</td>
                          <td>{current-group()[last()]/@time}</td>
                          <td>{count(current-group()[@trend = 'true'])}</td>
                          <td>{count(current-group()[@trend = 'false'])}</td>
                      </tr>
                  </xsl:for-each-group>
              </tbody>
          </table>
      </xsl:for-each-group>
  </xsl:template>

https://xsltfiddle.liberty-development.net/nc4NzQ1/1

或者您不需要排序,而是使用group-by="@time idiv 1000",也许是按current-grouping-key()对组进行排序。