Thread Solved
Reply

Join Date: Feb 2009
Posts: 27
Reputation: Tamir09 is an unknown quantity at this point 
Solved Threads: 0
Tamir09 Tamir09 is offline Offline
Light Poster

XSLT Help

 
0
  #1
Jul 2nd, 2009
Im trying to format my xslt form to a table that I have:

Horsepower-Electric Values
Revolutions Number of Disks
blank num 1 num 2 num 3
rev1 hpe1 hpe2 hpe3
rev2 hpe4 hpe5 hpe6
rev3 hpe7 hpe8 hpe9

And so far, Ive gotten the xslt form to come out somewhat similarly to that table, but the way its formatting just cant get fixed. I tried different ways, but I know Im missing something, and I cant figure out what. Heres the code for the xslt form:

  1. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  2. <xsl:output method="xml" indent="yes"/>
  3. <xsl:template match="/">
  4.  
  5. <html>
  6. <body>
  7. <table border="2">
  8. <tr>
  9. <th colspan ="4" bgcolor="darkgrey">Horsepower-Electric Values</th>
  10. </tr>
  11. <tr>
  12. <th bgcolor="lightblue">Revolutions</th>
  13. <th colspan="7" bgcolor="tan">Number of Disks</th>
  14. </tr>
  15. <tr><xsl:for-each select="ArrayOfMyHPEData/MyHPEData">
  16. <td>
  17. <xsl:value-of select="n"/>
  18. </td>
  19. </xsl:for-each>
  20. </tr>
  21. <tr>
  22. <xsl:for-each select="ArrayOfMyHPEData/MyHPEData">
  23. <td>
  24. <xsl:value-of select="HPE"/>
  25. </td>
  26. </xsl:for-each>
  27. </tr>
  28. <xsl:for-each select="ArrayOfMyHPEData/MyHPEData">
  29. <tr>
  30. <td>
  31. <xsl:value-of select="Rev"/>
  32. </td>
  33. <!--<td>
  34. <xsl:value-of select="HPE"/>
  35. </td> -->
  36. </tr></xsl:for-each>
  37. </table>
  38. </body>
  39. </html>
  40.  
  41. </xsl:template>
  42. </xsl:stylesheet>

Does anyone know how I can fix this? Could it be the formatting problem is in my xml? Heres what the table is actually looking like when the xml combines with the xslt form.

HPEData.html
Last edited by Tamir09; Jul 2nd, 2009 at 2:11 am.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 27
Reputation: Tamir09 is an unknown quantity at this point 
Solved Threads: 0
Tamir09 Tamir09 is offline Offline
Light Poster

Re: XSLT Help

 
0
  #2
Jul 2nd, 2009
Just for those who might need the solution for this, I have it as:

  1. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  2. <xsl:output method="html" indent="yes"/>
  3.  
  4. <xsl:key name="key-revolution" match="Rev" use="text()"/>
  5. <xsl:key name="key-number" match="n" use="text()"/>
  6.  
  7.  
  8. <xsl:template match="/">
  9. <html>
  10. <body>
  11. <xsl:apply-templates select="ArrayOfMyHPEData" />
  12. </body>
  13. </html>
  14. </xsl:template>
  15.  
  16. <xsl:template match="ArrayOfMyHPEData">
  17. <table border="2">
  18. <tr>
  19. <th colspan ="8" bgcolor="darkgrey">Horsepower-Electric Values</th>
  20. </tr>
  21. <tr>
  22. <th bgcolor="lightblue">Revolutions</th>
  23. <th colspan="7" bgcolor="tan">Number of Disks</th>
  24. </tr>
  25. <xsl:call-template name="PrintNumbers" />
  26. <xsl:for-each select="MyHPEData/Rev[generate-id() = generate-id(key('key-revolution', text()))]">
  27. <xsl:variable name="rev" select="." />
  28. <tr>
  29. <td>
  30. <xsl:value-of select="$rev" />
  31. </td>
  32. <xsl:for-each select="/ArrayOfMyHPEData/MyHPEData/n[generate-id() = generate-id(key('key-number', text()))]">
  33. <td>
  34. <xsl:value-of select="/ArrayOfMyHPEData/MyHPEData[Rev = $rev and n = current()]/HPE"/>
  35. </td>
  36. </xsl:for-each>
  37. </tr>
  38. </xsl:for-each>
  39. </table>
  40. </xsl:template>
  41.  
  42. <xsl:template name="PrintNumbers">
  43. <tr>
  44. <td />
  45. <xsl:for-each select="MyHPEData/n[generate-id() = generate-id(key('key-number', text()))]">
  46. <td>
  47. <xsl:value-of select="."/>
  48. </td>
  49. </xsl:for-each>
  50. </tr>
  51. </xsl:template>
  52. </xsl:stylesheet>
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the XML, XSLT and XPATH Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC