This content is not available in your preferred language.

The content is shown in another available language. Your browser may include features that can help translate the text.

How-To Modify a TestStand XML Report

Updated Oct 25, 2024

Environment

Software

  • TestStand

  • I want to add custom data to my TestStand report header when using the XML report format. What is the best way to do this?
  • I want to put information into the report that has been created during the current test run.

TestStand's XML report depends on two files: the XML file (.xml) that is created every time a test is run, and the stylesheet (.xsl) that is created in advance and specified in the report options as well as the first line of the .xml file.  Because of this, to modify the resulting report, we must change both the XSL stylesheet and the TestStand code that generates the XML file.  This document discusses making a change to TestStand to take the value of a variable and add it to the top of the report header for the given sequence file. Many of the concepts discussed should be applicable, with modification, to the rest of your TestStand report.  Because XML is an independently defined standard, it may be helpful to review information about XSLT and XPATH before proceeding.

Note: The instructions for this article start with the stylesheet (.xsl) file that ships with TestStand 2010 SP1.  This stylesheet file is similar, but not necessarily identical, to the stylesheet file that ships with TestStand 4.2.x.  Earlier versions of TestStand have XSL files that will most likely be somewhat different as the structure of the XSL file was reorganized for TestStand 4.2.x.

XML modifications using TestStand:
First, changes need to be made to the test sequence to save the value of a given variable to the generated XML file.  Because we are making a modification to the report header, we can use the ModifyReportHeader callback to make the changes.
  1. In your sequence file, add a callback by right-clicking in the Sequences pane and selecting Sequence File Callbacks...  Add ModifyReportHeader from the list and close the dialog.
  2. In the new ModifyReportHeader sequence, add a new Local variable called CustomText. This variable is a placeholder used in this example, and can be substituted for a variable of your choice, including dynamic variables that are given values during the test run. The value of this variable will be the new value added to the report, so for this example give it a meaningful value such as "My New Report Text".
  3. The last step is to generate XML from the new variable and append this to the Parameters.ReportHeader XML already passed into the callback.  When ModifyReportHeader starts, the Parameters.ReportHeader string contains the XML that was generated by the default TestStand reporting in the specified process model.  We can append to this to add more data to the XML file for use in the second section of this article.  To do this, use the following expression:  
Parameters.ReportHeader += Locals.CustomText.GetXML(XMLOption_NoOptions, 0, "CustomText", Parameters.ReportOptions.NumericFormat)


The GetXML function takes information about a PropertyObject and turns it into a properly-formatted XML string.  See the TestStand help on this function for more information.


XSL modifications external to TestStand: 
Now that the data has been added to the XML file, the XSL file must be modified to display the new data.

Open horizontal.xsl in a text editor and search the document for the the ADD_HEADER_INFO section.  This section should be commented out with the HTML comment tags ("<!--" and "-->").  Using HTML, add information to format and display the information that was added to the XML file in the section previous.  For this example, we will use the following HTML:
<font face = "VERDANA" size = "4" color= "#003366">
    <xsl:value-of select="//Report/Prop[@Name='CustomText']"/>
</font>
This will retrieve the value of the first Prop node (underneath the first Report node) that has the Name attribute of "CustomText " - this is the value we created in TestStand in the previous section.  The value that is retrieved is formatted using the <font> tags.  The value is selected by using XPath.  If you are attempting to retrieve a different value than the one used in this example, take a look at the XPath Tutorial linked below to determine how to reference that value.
 

Additional Information

When examining a .XML file, many machines will open with a default internet browser and display the data of the XML sheet using the stylesheet in the first line of the XML file. In order to view the XML source code, make sure to open the file with a text editor or similar program.

When using the PDF Report Generation tool please note that only absolute XSL filepath are working. Using XSL relative filepath will result in an erroneous PDF report