Academic Company Events Community Support Solutions Products & Services Contact NI MyNI
1 ratings:
 5 out of 5     Rate this Document

How to Modify a TestStand XML Report Header



Primary Software:
Primary Software Version: 2010
Primary Software Fixed Version: N/A
Secondary Software: N/A

Problem:
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?

Solution:
TestStand's XML report depends on two files: the XML file that is created every time a test is run, and the XSL stylesheet that is created in advance and specified in the report options.  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.  Before reviewing this document, it may be helpful to review information about XSLT and XPATH. Two links are provided in the Related Links section addressing these topics.

Note: The instructions for this KnowledgeBase start with the XSL file that ships with TestStand 2010 SP1.  This XSL file is similar, but not necessarily identical, to the XSL 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.  The value of this variable will be the new value added to the report, so 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.
  1. 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.


Related Links:
Community Example: Modify XML Report in TestStand
Developer Zone: Best Practices for NI TestStand Report Generation and Customization
KnowledgeBase 4SB7G6CK: TestStand XML Report Customization
TestStand Help: XML Report Style Sheets

W3Schools.com: XSLT Tutorial
W3Schools.com: XPath Tutorial

Attachments:





Report Date: 06/14/2010
Last Updated: 05/29/2012
Document ID: 5ADH53GU

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit