ThomasM: group by mit XSLT 1.0

Beitrag lesen

Hier noch eine Variante, welche die gruppierten Chart-Wert nur 1x darstellt:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="html" version="5" encoding="UTF-8"/>
  <xsl:key name="chart_group" match="Chart" use="."/>

  <xsl:template match="/">
    <html>
      <head>
        <title>Test</title>
        <style type="text/css">
          table,td,th { border: 1px solid #000; border-collapse: collapse; padding: 0.5em; }
          td[rowspan] { color: #F00; font-weight: bold; }
        </style>
      </head>
      <body>
        <table>
          <tr>
            <th>Chart</th>
            <th>Fact</th>
            <th>Location</th>
          </tr>
          <xsl:for-each select="//Chart[generate-id() = generate-id(key('chart_group', .)[1])]">
            <xsl:sort select="." data-type="number" order="ascending"/>
            <xsl:variable name="akt_chart" select="."/>
            <xsl:variable name="anz_chart" select="count(//Chart[. = $akt_chart])"/>
            <xsl:for-each select="//Chart[. = $akt_chart]">
              <tr>
                <xsl:if test="position() = 1">
                  <td rowspan="{$anz_chart}">
                    <xsl:value-of select="$akt_chart"/>
                  </td>
                </xsl:if>
                <td>
                  <xsl:value-of select="preceding::Fact[1]"/>
                </td>
                <td>
                  <xsl:value-of select="../../Coordinates"/>
                </td>
              </tr>
            </xsl:for-each>
          </xsl:for-each>
        </table>
      </body>
    </html>
  </xsl:template>

</xsl:stylesheet>

Am Beispiel 100:

<tr>
  <td rowspan="3">100</td>
  <td>A</td>
  <td>50,14</td>
</tr>
<tr>
  <td>A</td>
  <td>52,16</td>
</tr>
<tr>
  <td>B</td>
  <td>50.7,14.5</td>
</tr>

Grüße,
Thomas