1

我正在从 XML 和 XSLT 转换为 HTML。我有这个 XSLT 代码:

<html>
  <head>
    <title>Tiskova sestava</title>
  </head>
  <body>
    ...
    <table rules="GROUPS"  frame="BOX">
      <THEAD>
        <tr>
          <th>Typ</th>
           ....
          <th>Středisko</th>
        </tr>
        </THEAD>
      <TBODY>
        <xsl:for-each select="Report/Polozka">
          <tr>
            <td>
              <xsl:value-of select="Kategorie"/>
            </td>
               .....
            <td>
              <xsl:value-of select="Stredisko"/>
            </td>
          </tr>
        </xsl:for-each>
      </TBODY>
    </table>
  </body>
</html>

这是输出:在此处输入图像描述

但是我想创建新表,如果“Stredisko”列的值不同,那么之前的值。因此,在第一个表中应该是列值为“Stredisko”== 4 的行,在第二个表中为值 == 1,在第三个表中为值 ==“”。

输入 XML

4

2 回答 2

1

试试这个 xsl。这不是一个完整的答案,但您可以将其作为起点(当然,如果可以的话):

<?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" encoding="utf-8" indent="yes" />

<!-- for easy selection of Polozka elements: -->
<xsl:key name="reports-by-stredisko" match="/Report/Polozka" use="Stredisko" />

<xsl:template match="/">
  <xsl:for-each select="/Report/Polozka[not(Stredisko = preceding-sibling::Polozka/Stredisko)]">
    <table summary="Stredisko: {Stredisko}">
      <xsl:for-each select="key('reports-by-stredisko',Stredisko)">
      <tr>
        <td>I_Cislo: <xsl:value-of select="I_Cislo"/></td>
        <td>Stredisko: <xsl:value-of select="Stredisko"/></td>
        <td>...</td>
      </tr>
      </xsl:for-each>
    </table>
  </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

此 xsl 生成以下输出:

<table summary="Stredisko: 4">
<tr>
  <td>I_Cislo: 29IM00001</td>
  <td>Stredisko: 4</td>
  <td>...</td>
</tr>
<tr>
  <td>I_Cislo: 29IM00001</td>
  <td>Stredisko: 4</td>
  <td>...</td>
</tr>
<tr>
  <td>I_Cislo: 12D3333</td>
  <td>Stredisko: 4</td>
  <td>...</td>
</tr>
<tr>
  <td>I_Cislo: 10DM00004</td>
  <td>Stredisko: 4</td>
  <td>...</td>
</tr>
<tr>
  <td>I_Cislo: 10DM00005</td>
  <td>Stredisko: 4</td>
  <td>...</td>
</tr>
<tr>
  <td>I_Cislo: 10DM00007</td>
  <td>Stredisko: 4</td>
  <td>...</td>
</tr>
</table>

<table summary="Stredisko:       ">
<tr>
  <td>I_Cislo: 10IM00002</td>
  <td>Stredisko:       </td>
  <td>...</td>
</tr>
<tr>
  <td>I_Cislo: 11IM00002</td>
  <td>Stredisko:       </td>
  <td>...</td>
</tr>
<tr>
  <td>I_Cislo: 12IM00002</td>
  <td>Stredisko:       </td>
  <td>...</td>
</tr>
<tr>
  <td>I_Cislo: 10IM00002</td>
  <td>Stredisko:       </td>
  <td>...</td>
</tr>
<tr>
  <td>I_Cislo: 11IM00002</td>
  <td>Stredisko:       </td>
  <td>...</td>
</tr>
<tr>
  <td>I_Cislo: 12IM00002</td>
  <td>Stredisko:       </td>
  <td>...</td>
</tr>
<tr>
  <td>I_Cislo: 12DM00007</td>
  <td>Stredisko:       </td>
  <td>...</td>
</tr>
<tr>
  <td>I_Cislo: 10LM00002</td>
  <td>Stredisko:       </td>
  <td>...</td>
</tr>
</table>

<table summary="Stredisko: 1">
<tr>
  <td>I_Cislo: 12DM00006</td>
  <td>Stredisko: 1</td>
  <td>...</td>
</tr>
</table>

希望能帮助到你

于 2013-10-28T14:32:51.353 回答
0

Please correct your code as below logic Put your condition and get previous value by using preceding-sibling

<xsl:choose>
<xsl:when test="PLEASE CHECK YOUR CONDITION HERE">
     <xsl:value-of disable-output-escaping="yes" select="preceding-sibling::*[1]/YOUR TAG NAME HERE"/>
    </xsl:when>
    <xsl:otherwise>

    </xsl:otherwise>
</xsl:choose>

Many Thanks Avnish

于 2013-10-24T13:16:33.193 回答