XML/XSL Transformation: Stats Table

Posted by Albert Gareev on Mar 02, 2011 | Categories: ReportingSource codeXML Data

Parent page: Generating Test Reports

Today I present example of an HTML Table populated with XML data.
Here’s our XML record simulating stats data of a test session.

XML Source

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href=".\StatsTable.xsl"?>
  <description>Test login page</description>
  <reporter>John Doe</reporter>
    <entry name="Start Date / Time">21/04/2011 11:39:24 AM</entry>
    <entry name="End Date / Time">21/04/2011 12:26:33 PM</entry>

Did you notice the following line?

<?xml-stylesheet type=”text/xsl” href=”.\StatsTable.xsl”?>

This is how we instruct the web browser to use XSL script for visualization of XML data.

Web-page Report

And here’s the source code of the script

XSL Source

<xsl:stylesheet version="1.0"  xmlns:xsl=""

<!-- variables -->
<xsl:variable name="CHAR_SPC">&#160;</xsl:variable>

<xsl:template match="/">


<title> | Stats Table XML/XSL Transformation Example by Albert Gareev</title>

<body bgcolor="#c0c0c0">

<H1 align="center">Stats Table</H1>
<H4 align="center">XML/XSL Transformation Example by <A HREF="">Albert Gareev</A></H4>
<BR />
<P />
<h3 align="center">Test Stats</h3>
<BR />
<TABLE BORDER="1" width="650" align="center">

	<TR> <TH colspan="2" align="left">Overview</TH>       </TR>
	<TR> <TD width="200">Description</TD> <TD> <xsl:value-of select="log/description" /> <xsl:value-of select = "$CHAR_SPC" /></TD> </TR>
	<TR> <TD width="200">Reporter</TD> <TD align="center"> <B><xsl:value-of select="log/reporter" /> </B><xsl:value-of select = "$CHAR_SPC" /> </TD> </TR>

		<TD width="200">Execution Status</TD>
		<TD align="center"> <B>
		  <xsl:when test = " log/status = 'FAIL' ">
		    <span> <font color="red"> <xsl:value-of select="log/status" /> </font> </span>
		  <xsl:when test = " log/status = 'PASS' ">
		    <span> <font color="green"> <xsl:value-of select="log/status" /> </font> </span>
		  <xsl:when test = " log/status = 'OK' ">
		    <xsl:value-of select="log/status" />
		    <span> <font color="yellow"> <xsl:value-of select="log/status" /> </font> </span>
            </B> </TD>

	<TR> <TH colspan="2" align="left">Time Log</TH>       </TR>

	<xsl:for-each select="log/timelog/entry">
			<TD> <xsl:value-of select="@name" /> </TD>
			<TD> <xsl:value-of select="text()" /> </TD>
<BR />

<div align="center">
<A HREF="">Home</A>
<BR />



How To

  • Define template of a table
  • Insert node values into table cells
  • To customize appearance use xsl:choose or xsl:if


And here is the package containing the original XML and XSL files.

  • Leave a Reply

    * Required
    ** Your Email is never shared

Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
This work by Albert Gareev is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported.