Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 323
  • Last Modified:

populating xml using xslt horizontally

I'm trying to transform XML file sample below:

<ticket>
   <month name="June">
       <item id="one">45</item>
       <item id="two">65</item>
       <item id="three">94</item>
  </month>
   <month name="July">
       <item id="one">34</item>
       <item id="two">23</item>
       <item id="three">12</item>
  </month>
</ticket>

to HTML table below:

      June      July
one      34      44
two      12      23
three      45      76

using XSLT.   However I am not able to populate 'June' and 'July' in the HTML table.
0
kaushalshah
Asked:
kaushalshah
  • 2
1 Solution
 
owenli27Commented:
Try use this XSL to see if it work:

<?xml version="1.0" encoding="ISO-8859-1" ?>  
 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="html" />
 <xsl:template match="/">
 <html><body>
 <table>
  <tr>
  <td> </td>
  <xsl:for-each select="ticket/month">
  <td> <xsl:value-of select="@name"/></td>
  </xsl:for-each>
  </tr>

 <tr><td>one</td>
  <xsl:for-each select="ticket/month">
  <xsl:for-each select="item">
   <xsl:if test="'one'=@id">
   <td> <xsl:value-of select="." /></td>
   </xsl:if>
 </xsl:for-each>
 </xsl:for-each>
</tr>

<tr><td>two</td>
  <xsl:for-each select="ticket/month">
  <xsl:for-each select="item">
   <xsl:if test="'two'=@id">
   <td> <xsl:value-of select="." /></td>
   </xsl:if>
 </xsl:for-each>
 </xsl:for-each>
</tr>

 <tr><td>three</td>
  <xsl:for-each select="ticket/month">
  <xsl:for-each select="item">
   <xsl:if test="'three'=@id">
   <td> <xsl:value-of select="." /></td>
   </xsl:if>
 </xsl:for-each>
 </xsl:for-each>
</tr>
 </table>
  </body>
  </html>
  </xsl:template>
  </xsl:stylesheet>
0
 
kaushalshahAuthor Commented:
awesome.   just one question;  in '<td> <xsl:value-of select="." /></td>', what is select="."?
0
 
owenli27Commented:
It is an expression to tell xsl to return and output the current element value
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now