Solved

DataTable to XML to XSLT

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Strange html entity encoding by tidy 14 84
Does a Google search find images with the word being searched? 11 75
Formatting issues in XSL FO 3 37
write xml in vb.net 2 24
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

776 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