Transforming XML into HTML using XSL
Hi,
I need the following XML to be transformed into HTML table using XSL.
<TestCase>
<DisplayName>Test1</DisplayName>
<RunDetails>
<Run>
<Location>Fargo</Location>
<Target>10</Target>
<Actual>8.344</Actual>
</Run>
<Run>
<Location>Veldhoven</Location>
<Target>12</Target>
<Actual>9.642</Actual>
</Run>
<Run>
<Location>Chicago</Location>
<Target>5</Target>
<Actual>4.642</Actual>
</Run>
</RunDetails>
</TestCase>
<TestCase>
<DisplayName>Test2</DisplayName>
<RunDetails>
<Run>
<Location>Fargo</Location>
<Target>10</Target>
<Actual>11.547</Actual>
</Run>
<Run>
<Location>Veldhoven</Location>
<Target>27</Target>
<Actual>16.193</Actual>
</Run>
<Run>
<Location>Chicago</Location>
<Target>8</Target>
<Actual>6.368</Actual>
</Run>
</RunDetails>
</TestCase>
<TestCase>
<DisplayName>Test3</DisplayName>
<RunDetails>
<Run>
<Location>Fargo</Location>
<Target>120</Target>
<Actual>100.093</Actual>
</Run>
<Run>
<Location>Veldhoven</Location>
<Target>130</Target>
<Actual>110.00</Actual>
</Run>
<Run>
<Location>Chicago</Location>
<Target>100</Target>
<Actual>88.976</Actual>
</Run>
</RunDetails>
</TestCase>
Expected HTML output :
--------------------------
DisplayName Location Target Value Actual Value
--------------------------
Test1 Fargo 10 8.344
Veldhoven 12 9.642
Chicago 5 4.642
--------------------------
Test2 Fargo 10 11.547
Veldhoven 27 16.193
Chicago 08 6.368
--------------------------
Test3 Fargo 120 100.09
Veldhoven 130 110.00
Chicago 100 88.976
--------------------------
Any help in creating the XSL for the above transformation is appreciated.
Thanks
CRPATEL
[3101 byte] By [
csrpatel] at [2007-11-19 8:15:36]

# 1 Re: Transforming XML into HTML using XSL
The XML code you posted does not make a vaild XML file. And I'am not at all sure how to interpret the mess you posted.
I have created a stylesheet for you with a few of the templates needed to preform the transformation, completing it is left as an excercises for you. (hint: you will need templates for Location, Target and Actual, each creating <td> elements containing their data.)
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates/>
<body>
</hmtl>
</xsl:template>
<xsl:template match="RunDetails">
<table>
<tr><td>Location</td><td>target</td><td>actual</td><tr>
<tr>
<xsl:apply-templates select="Location|Target|Actual"/>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>
khp at 2007-11-10 3:27:35 >

# 2 Re: Transforming XML into HTML using XSL
Hi,
I have created few templates that transform XML results into an HTML format. Still I was not able to get the desired format in HTML. Any help in transforming the results into the format I am looking for is appreciated.
I have attached a zip file that contains:
1)results.xml
2)results.xsl
3)sample.html
The attached results.xsl transforms results.xml into the HTML output. I am looking for the HTML format similar to sample.html. Looking for some help in updating the XSL to generate the sample.html format.
Thanks
CSRPATEL
# 3 Re: Transforming XML into HTML using XSL
You posted a lot of code, which is good, code is good.
But it would be even better, if you would also explain what problems you are having.
Explanations and code are not mutally exclusive, on the contary, they should always go together.
khp at 2007-11-10 3:29:40 >
