XML/XSL Transformation: Using Complex Nodes

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

Parent page: Generating Test Reports

Today I present example on dynamically building HTML nodes, with XSL, and from XML data.
Here’s our XML record simulating log data of a test session.

XML Source

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href=".\LogView1.xsl"?>
  <step type="GUI Step">
    <time>21/04/2011 11:45:31 AM</time>
    <description>Pasted data [User1234] in edit box [Username] </description>
  <step type="GUI Step">
    <time>21/04/2011 11:46:03 AM</time>
    <description>Pasted data [Password1234] in edit box [Password]</description>
  <step type="GUI Step">
    <time>21/04/2011 11:46:11 AM</time>
    <description>Clicked on button [Login]</description>
  <step type="Screenshot">
    <time>21/04/2011 11:46:33 AM</time>
    <description>Weird error dialog</description>

Did you notice the following line?

<?xml-stylesheet type=”text/xsl” href=”.\LogView1.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> | TestLog XML/XSL Transformation Example by Albert Gareev</title>

<body bgcolor="#c0c0c0">

<H1 align="center">Test Log</H1>
<H4 align="center">XML/XSL Transformation Example by <A HREF="">Albert Gareev</A></H4>
<BR />
<P />
<h3 align="center">Test Steps</h3>
<BR />
<TABLE id="automation-beyond-2010" BORDER="1" width="650" align="center">
  <TH width="150">Step Name</TH>
  <TH width="500">Step Description</TH>

<xsl:for-each select="log/step">
    <xsl:when test = " @type = 'Screenshot' ">
        <xsl:attribute name="title"><xsl:value-of select = "time" /></xsl:attribute>
        <xsl:value-of select = "@type" />
	  <xsl:attribute name="title">Click on the link to view the image attached</xsl:attribute>
	  <A TARGET="_blank">
		<xsl:attribute name="href">
		  <xsl:value-of select="filename" />
            <xsl:value-of select = "description" />
        <xsl:attribute name="title"><xsl:value-of select = "time" /></xsl:attribute>
        <xsl:value-of select = "@type" /><xsl:value-of select = "$CHAR_SPC" />
      <TD><xsl:value-of select = "description" /><xsl:value-of select = "$CHAR_SPC" /></TD>
<BR />

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



How To

  • Select type of XML node with xsl:choose
  • Insert node values into table cells
  • Add addtributes to HTML nodes with xsl:attribute


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.