Solved

DataTable to XML to XSLT

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

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

688 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