Question

I will try to make it as clear as possible. I have an XML that has inside a structure that follows:

<NetworkData>
  <NameOfSection1>
    <ChangeHistory>
      <ChangeHistoryItem>
        <Date>2012-06-04</Date>
        <Description>Add the USIM/SIM header</Description>
      </ChangeHistoryItem>
    </ChangeHistory>
  </NameOfSection1>
  <NameOfSection2>
    <ChangeHistory>
      <ChangeHistoryItem>
        <Date>2014-01-17</Date>
        <Description>Not changed</Description>
      </ChangeHistoryItem>
      <ChangeHistoryItem>
        <Date>2014-01-17</Date>
        <Description>Not changed</Description>
      </ChangeHistoryItem>
      <ChangeHistoryItem>
        <Date>2014-01-17</Date>
        <Description>Not changed</Description>
      </ChangeHistoryItem>
    </ChangeHistory>
  </NameOfSection2>
</NetworkData>

I want to create a table in XSL that contains all ChangeHistoryItems from all sections, ordered by date. In the end I want to generate a PDF file through Apache FOP.

I read about for-each-group but I don't know how should I use it, I'm a beginner in XSL/XML. Can you help? Many thanks.

Was it helpful?

Solution

<xsl:template match="/">
  <html>
  <body>
  <h2>Change history</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th style="text-align:left">Date</th>
        <th style="text-align:left">Description</th>
      </tr>
      <xsl:for-each select="//ChangeHistoryItem">
       <xsl:sort select="Date"/>
      <tr>
        <td><xsl:value-of select="Date"/></td>
        <td><xsl:value-of select="Description"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

Here is description:

<xsl:for-each select="//ChangeHistoryItem"> - all changeHistoryItem in any level
<xsl:sort select="Date"/> - Sort by elem date. 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top