Solved

DataTable to XML to XSLT

Posted on 2008-10-27
5
1,016 Views
Last Modified: 2013-11-19
I am geeting data from a sqldatabase into a datatable:

Here is the output of my SQL Query
Manager     NoofTickets        less_15_days        15_to_30_days            morethan_30_days
X                        2                            0                              1                                   1
Y                        2                            0                              0                                   2
Z                        1                            0                              1                                   0
I have further requirement of converting that to an XML File as shown below:

<results>
<X>
<NoOfTickets>4</NoOfTickets>
<less_15_days >0</less_15_days >
<15_to_30_days  >1</15_to_30_days  >
<morethan_30_days>3</morethan_30_days>
</X>
<Y>
<NoOfTickets>4</NoOfTickets>
<less_15_days >0</less_15_days >
<15_to_30_days  >1</15_to_30_days  >
<morethan_30_days>3</morethan_30_days>
</Y>
<Z>
<NoOfTickets>4</NoOfTickets>
<less_15_days >0</less_15_days >
<15_to_30_days  >1</15_to_30_days  >
<morethan_30_days>3</morethan_30_days>
</Z>
</results>

and then apply XSL:
SO that
Entries of column Age_less_15_days is shown with Green Indicator
Entries of column Age_15_to_30_days is shown with yellow Indicator
Entries of column Age_more_than_30_days is shown with red Indicator

Can anyone help as how can i acheive this
0
Comment
Question by:Needful
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 27

Expert Comment

by:BigRat
ID: 22886868
THis XML will not work, since the element 15_to_30_days starts with an invalid character, namely a digit. Numbers are not allowed to be element names.
0
 

Author Comment

by:Needful
ID: 22887011
That is only dummy data.
Actual xml looks in the same way but it has different naming convention.
0
 
LVL 27

Accepted Solution

by:
BigRat earned 450 total points
ID: 22887020
That being said, here's a stylesheet which does roughly what you want :-

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:ms="urn:schemas-microsoft-com:xslt"
                version="1.0">
               
<xsl:output method="html"/>

   <xsl:template match="/results">
      <table border="2">
      <tr><th>Manager</th><th><15 days</th><th>15..30</th><th>>30 days</th></tr>
      <xsl:for-each select="*">
         <tr>
            <td>
               <xsl:value-of select="name(.)"/>
            </td>
            <td style="color:green">
               <xsl:value-of select="./less_15_days"/>
            </td>
            <td style="color:yellow">
               <xsl:value-of select="./between_15_to_30_days"/>
            </td>
            <td style="color:red">
               <xsl:value-of select="./morethan_30_days"/>
            </td>
         </tr>
      </xsl:for-each>
      </table>
   </xsl:template>
</xsl:stylesheet>
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Post xml via PHP Soap Client 3 74
Grunt script for Build Process 1 68
Add to XML (Powershell) 1 43
ASP AND XML 3 31
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

697 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question