Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. Print Values in XSLT

Print Values in XSLT

Scheduled Pinned Locked Moved XML / XSL
xmlsaleshelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dotnetquery
    wrote on last edited by
    #1

    I have an XML File: 10 11 9 8 8 7 6 9 2 4 6 3 Now I want to print the sales of each car Year wise in a tabular format. Something like a pivot table. If the car does not have sales for a particular year, it should display blank space. The output should be in the format like: Maruti Fort Mercedes 2000 10 8 2 2001 11 - 4 2002 9 7 - 2003 - 6 6 2004 8 9 3 I am not able to print the values particularly. Please help.

    P 1 Reply Last reply
    0
    • D dotnetquery

      I have an XML File: 10 11 9 8 8 7 6 9 2 4 6 3 Now I want to print the sales of each car Year wise in a tabular format. Something like a pivot table. If the car does not have sales for a particular year, it should display blank space. The output should be in the format like: Maruti Fort Mercedes 2000 10 8 2 2001 11 - 4 2002 9 7 - 2003 - 6 6 2004 8 9 3 I am not able to print the values particularly. Please help.

      P Offline
      P Offline
      Phil Hobgen
      wrote on last edited by
      #2

      Hi, This doesn't seem like a very elegant solution. I'm sure there must be a better way, but I couldn't get there :( Hope this helps.

      <?xml version="1.0" ?>
      <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:template match="/">
      <xsl:variable name="unique-years" select="/ROOT/CAR/SALES[not(@Year=preceding::*/@Year)]/@Year" />
      <xsl:variable name="unique-carnames" select="/ROOT/CAR[not(@Name=preceding::*/Name)]/@Name" />
      <html>
      <body>
      <table>
      <tr>
      <td> </td>
      <xsl:for-each select="$unique-carnames">
      <xsl:sort select="." />
      <td><xsl:value-of select="." /></td>
      </xsl:for-each>
      </tr>
      <xsl:for-each select="$unique-years">
      <xsl:sort select="." />
      <tr>
      <xsl:variable name="this-year" select="."/>
      <td><xsl:value-of select="$this-year" /></td>
      <xsl:for-each select="$unique-carnames">
      <xsl:sort select="." />
      <xsl:variable name="this-car" select="."/>
      <td><xsl:value-of select="/ROOT/CAR[@Name=$this-car]/SALES[@Year=$this-year]" /></td>
      </xsl:for-each>
      </tr>
      </xsl:for-each>
      </table>
      </body>
      </html>
      </xsl:template>
      </xsl:stylesheet>

      Cheers Phil Hobgen barbari.co.uk Southampton, UK

      D 1 Reply Last reply
      0
      • P Phil Hobgen

        Hi, This doesn't seem like a very elegant solution. I'm sure there must be a better way, but I couldn't get there :( Hope this helps.

        <?xml version="1.0" ?>
        <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:template match="/">
        <xsl:variable name="unique-years" select="/ROOT/CAR/SALES[not(@Year=preceding::*/@Year)]/@Year" />
        <xsl:variable name="unique-carnames" select="/ROOT/CAR[not(@Name=preceding::*/Name)]/@Name" />
        <html>
        <body>
        <table>
        <tr>
        <td> </td>
        <xsl:for-each select="$unique-carnames">
        <xsl:sort select="." />
        <td><xsl:value-of select="." /></td>
        </xsl:for-each>
        </tr>
        <xsl:for-each select="$unique-years">
        <xsl:sort select="." />
        <tr>
        <xsl:variable name="this-year" select="."/>
        <td><xsl:value-of select="$this-year" /></td>
        <xsl:for-each select="$unique-carnames">
        <xsl:sort select="." />
        <xsl:variable name="this-car" select="."/>
        <td><xsl:value-of select="/ROOT/CAR[@Name=$this-car]/SALES[@Year=$this-year]" /></td>
        </xsl:for-each>
        </tr>
        </xsl:for-each>
        </table>
        </body>
        </html>
        </xsl:template>
        </xsl:stylesheet>

        Cheers Phil Hobgen barbari.co.uk Southampton, UK

        D Offline
        D Offline
        dotnetquery
        wrote on last edited by
        #3

        Thanks a lot Phil. It works.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups