Solved

DataTable to XML to XSLT

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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

Suggested Solutions

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
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.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

840 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