Modifying the Report
Log into your instance of SpiraTest, SpiraPlan or SpiraTeam. Then follow these steps:
- Go to Administration > System > Edit Reports
- Make a copy of the report you wish to change (e.g. Test Case Detailed)
- Click on the Edit button for the copy of this report
- On the report dialog box, click on the 'Customize' link for the appropriate section you wish to edit.
- This will display the edit section dialog box:
- Now cut and paste the contents of the 'Template' field into your favorite XML editor and you can modify the report and then save the updated report.
Changing the Template
Now that you have the XSLT template used to generate the report in an XML editor, you will see the following code used to format each of the dates:
<xsl:call-template name="format-date">
<xsl:with-param name="datetime" select="CreationDate" />
</xsl:call-template>
If you only want to change some of the dates in the report, you should change the name of the template that it is calling (e.g. format-date-expanded):
<xsl:call-template name="format-date-expanded">
<xsl:with-param name="datetime" select="CreationDate" />
</xsl:call-template>
If you want to change all of the dates in the report, you can leave this alone.
Next you need to modify the function (called a template in XSLT) that is responsible for actually formatting the date:
<xsl:template name="format-date">
<xsl:param name="datetime"/>
<xsl:variable name="date" select="substring-before($datetime, 'T')" />
<xsl:variable name="year" select="substring-before($date, '-')" />
<xsl:variable name="month" select="substring-before(substring-after($date, '-'), '-')" />
<xsl:variable name="day" select="substring-after(substring-after($date, '-'), '-')" />
<xsl:variable name="time" select="substring-before(substring-after($datetime, 'T'), '.')" />
<xsl:variable name="monthname">
<xsl:choose>
<xsl:when test="$month='01'">
<xsl:value-of select="'Jan'"/>
</xsl:when>
<xsl:when test="$month='02'">
<xsl:value-of select="'Feb'"/>
</xsl:when>
<xsl:when test="$month='03'">
<xsl:value-of select="'Mar'"/>
</xsl:when>
<xsl:when test="$month='04'">
<xsl:value-of select="'Apr'"/>
</xsl:when>
<xsl:when test="$month='05'">
<xsl:value-of select="'May'"/>
</xsl:when>
<xsl:when test="$month='06'">
<xsl:value-of select="'Jun'"/>
</xsl:when>
<xsl:when test="$month='07'">
<xsl:value-of select="'Jul'"/>
</xsl:when>
<xsl:when test="$month='08'">
<xsl:value-of select="'Aug'"/>
</xsl:when>
<xsl:when test="$month='09'">
<xsl:value-of select="'Sep'"/>
</xsl:when>
<xsl:when test="$month='10'">
<xsl:value-of select="'Oct'"/>
</xsl:when>
<xsl:when test="$month='11'">
<xsl:value-of select="'Nov'"/>
</xsl:when>
<xsl:when test="$month='12'">
<xsl:value-of select="'Dec'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="''" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="concat($day, '-' ,$monthname, '-', $year , ' ', $time)" />
</xsl:template>
For example, we want to show that one date in an expanded format (e.g. ISO-8601 YYYY-MM-DD hh:mm).
To do this we use the following function:
<xsl:template name="format-date-expanded">
<xsl:param name="datetime"/>
<xsl:variable name="date" select="substring-after($datetime, 'T')" />
<xsl:variable name="year" select="substring-before($datetime, 'T')" />
<xsl:variable name="month" select="substring-before(substring-after($datetime, $year), '-')" />
<xsl:variable name="day" select="substring-after(substring-before($date, '-'), $month)" />
<xsl:variable name="time" select="$date" />
<xsl:value-of select="concat($year, ' ', $month, $day, $time)" />
</xsl:template>
Sample output if the "format-date-expanded" template applied: