Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8562267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:41:39+00:00 2026-06-11T16:41:39+00:00

I have an xml document that looks something like this: <units> <unit> <year></year> <month></month>

  • 0

I have an xml document that looks something like this:

<units>
    <unit>
       <year></year>
       <month></month>
       <qty></qty>
    </unit>
</units>

I want to create a crosstab view of this data in html with each row represented by a year, each column represented by a month, and each value containing the sum of the qty’s for the specific year/month. Something a little like this:

      Jan  Feb   Mar   Apr.... etc
2010  345    0    12     0
2011    1   23   344     0
2012   99    1    23     0.... etc

My primary question is this: is crosstab even possible with xslt?

My follow-up question would be can you point an xslt newbie, such as myself, in the right direction to get started trying to make this work?

SAMPLE DATA:

<units>
    <unit>
        <year>2010</year>
        <month>9</month>
        <qty>13320</qty>
    </unit>
    <unit>
        <year>2010</year>
        <month>9</month>
        <qty>2445</qty>
    </unit>
    <unit>
        <year>2010</year>
        <month>10</month>
        <qty>8949</qty>
    </unit>
    <unit>
        <year>2010</year>
        <month>10</month>
        <qty>13650</qty>
    </unit>
    <unit>
        <year>2010</year>
        <month>11</month>
        <qty>4091</qty>
    </unit>
    <unit>
        <year>2010</year>
        <month>11</month>
        <qty>6600</qty>
    </unit>
    <unit>
        <year>2010</year>
        <month>12</month>
        <qty>686</qty>
    </unit>
    <unit>
        <year>2010</year>
        <month>12</month>
        <qty>678</qty>
    </unit>

    <unit>
        <year>2011</year>
        <month>1</month>
        <qty>1234</qty>
    </unit>
    <unit>
        <year>2011</year>
        <month>1</month>
        <qty>12345</qty>
    </unit>
    <unit>
         <year>2011</year>
        <month>2</month>
        <qty>4500</qty>
    </unit>
    <unit>
        <year>2011</year>
        <month>2</month>
        <qty>999</qty>
    </unit>
    <unit>
        <year>2011</year>
        <month>3</month>
        <qty>166</qty>
    </unit>
    <unit>
         <year>2011</year>
        <month>3</month>
        <qty>456666</qty>
    </unit>
    <unit>
        <year>2011</year>
        <month>4</month>
        <qty>41113</qty>
    </unit>
    <unit>
        <year>2011</year>
        <month>4</month>
        <qty>1150</qty>
    </unit>
    <unit>
        <year>2011</year>
        <month>5</month>
        <qty>4150</qty>
    </unit>
    <unit>
        <year>2011</year>
        <month>5</month>
        <qty>491</qty>
    </unit>
    <unit>
        <year>2011</year>
        <month>6</month>
        <qty>11250</qty>
    </unit>
    <unit>
        <year>2011</year>
        <month>6</month>
        <qty>3400</qty>
    </unit>
    <unit>
         <year>2011</year>
        <month>7</month>
        <qty>485</qty>
    </unit>
    <unit>
        <year>2011</year>
        <month>7</month>
        <qty>90</qty>
    </unit>
    <unit>
        <year>2011</year>
        <month>8</month>
        <qty>1606</qty>
    </unit>
    <unit>
         <year>2011</year>
        <month>8</month>
        <qty>202000</qty>
    </unit>
    <unit>
        <year>2011</year>
        <month>9</month>
        <qty>45333</qty>
    </unit>
    <unit>
        <year>2011</year>
        <month>9</month>
        <qty>13650</qty>
    </unit>
    <unit>
        <year>2011</year>
        <month>10</month>
        <qty>4050</qty>
    </unit>
    <unit>
        <year>2011</year>
        <month>10</month>
        <qty>431</qty>
    </unit>
    <unit>
        <year>2011</year>
        <month>11</month>
        <qty>45713</qty>
    </unit>
    <unit>
        <year>2011</year>
        <month>11</month>
        <qty>13690</qty>
    </unit>
    <unit>
        <year>2011</year>
        <month>12</month>
        <qty>4050</qty>
    </unit>
    <unit>
        <year>2011</year>
        <month>12</month>
        <qty>431</qty>
    </unit>

    <unit>
        <year>2012</year>
        <month>1</month>
        <qty>2500</qty>
    </unit>
    <unit>
        <year>2012</year>
        <month>1</month>
        <qty>34100</qty>
    </unit>
    <unit>
        <year>2012</year>
        <month>2</month>
        <qty>400</qty>
    </unit>
    <unit>
        <year>2012</year>
        <month>2</month>
        <qty>99</qty>
    </unit>
    <unit>
        <year>2012</year>
        <month>3</month>
        <qty>1606</qty>
    </unit>
    <unit>
        <year>2012</year>
        <month>3</month>
        <qty>202000</qty>
    </unit>
    <unit>
        <year>2012</year>
        <month>4</month>
        <qty>53773</qty>
    </unit>
    <unit>
        <year>2012</year>
        <month>4</month>
        <qty>13650</qty>
    </unit>
    <unit>
        <year>2012</year>
        <month>5</month>
        <qty>4150</qty>
    </unit>
    <unit>
        <year>2012</year>
        <month>5</month>
        <qty>4231</qty>
    </unit>
    <unit>
        <year>2012</year>
        <month>6</month>
        <qty>278</qty>
    </unit>
    <unit>
        <year>2012</year>
        <month>6</month>
        <qty>6100</qty>
    </unit>
    <unit>
        <year>2012</year>
        <month>7</month>
        <qty>406</qty>
    </unit>
    <unit>
        <year>2012</year>
        <month>7</month>
        <qty>95</qty>
    </unit>

</units>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:41:40+00:00Added an answer on June 11, 2026 at 4:41 pm

    Here is an XSLT 1.0 solution (there might be some work needed to make the numbers align properly):

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:key name="kUnitByY" match="unit" use="year"/>
     <xsl:key name="kUnitByYM" match="unit" use="concat(year,'|',month)"/>
    
     <xsl:template match="/*">
    <xsl:text>      Jan  Feb  Mar  Apr  May  Jun  Jul  Aug  Sep  Oct  Nov  Dec</xsl:text>
      <xsl:apply-templates select=
       "unit[generate-id()=generate-id(key('kUnitByY',year)[1])]">
        <xsl:sort select="year" data-type="number"/>
       </xsl:apply-templates>
     </xsl:template>
    
     <xsl:template match="unit">
      <xsl:value-of select="concat('&#xA;',year,'  ')"/>
    
      <xsl:variable name="vCur" select="."/>
    
      <xsl:for-each select="(//node()|//namespace::*)[not(position() >12)]">
        <xsl:value-of select=
        "sum(key('kUnitByYM', concat($vCur/year,'|',position()))/qty)"/>
        <xsl:text>    </xsl:text>
      </xsl:for-each>
     </xsl:template>
    </xsl:stylesheet>
    

    When this transformation is applied on the following XML document (none was provided !!!):

    2010
    2
    3

    2010
    3
    44

    2010
    9
    44

    2011
    1
    5

    2011
    3
    11

    2011
    6
    11

    2011
    4
    15

    the wanted, correct result is produced:

          Jan  Feb  Mar  Apr  May  Jun  Jul  Aug  Sep  Oct  Nov  Dec
    2010  0    3    44    0    0    0    0    0    44    0    0    0    
    2011  5    0    11    15    0    11    0    0    0    0    0    0 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an xml document with multiple nodes that looks something like this: <Result>
I have a XML document that looks something like this: <?xml version=1.0 encoding=UTF-8?> <citizen>
Alright I have an xml document that looks something like this: <xml> <list> <partner>
All, I have an XML document that looks something like this: <root> <profile> <childA>
I have an xml document that looks something like this <?xml version=1.0 encoding=UTF-8?> <mapPoints>
I have some XML that looks something like this: <Root> <Documents> <Document id=1/> </Documents>
I have an xml document that looks like this. <foo> <bar type=artist/> Bob Marley
I have an XML document that matches our site navigation something like this: <page
I have an xml formatted document that looks like this: <?xml version=1.0 encoding=windows-1250?> <
I have a xml doxument that looks like this: <create> <customers> <customer> <first-name>foo</first-name> <last-name>bar</last-name>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.