943,786 Members | Top Members by Rank

Ad:
Jul 2nd, 2009
0

XSLT Help

Expand Post »
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:

xml Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
Tamir09 is offline Offline
27 posts
since Feb 2009
Jul 2nd, 2009
0

Re: XSLT Help

Just for those who might need the solution for this, I have it as:

xml Syntax (Toggle Plain Text)
  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>
Reputation Points: 10
Solved Threads: 0
Light Poster
Tamir09 is offline Offline
27 posts
since Feb 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in XML, XSLT and XPATH Forum Timeline: Parse JavaScript Variable to a XSLT Variable
Next Thread in XML, XSLT and XPATH Forum Timeline: xslt help for links in html





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC