Solved

DataTable to XML to XSLT

Posted on 2008-10-27
5
1,003 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
  • 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now