I’ve been working on something for my boss, a website that displays the web-services of a ticketing system. The web-service spits out an XML file based on a query. My problem is, when I try to set conditions for output, I either get an error or it skips all the way to the “otherwise” entry when the array containing the XML entries for each ticket clearly match what I have in my test. I’m new to XSLT and have only what I’ve looked into to go off of. Can someone look at what I have and explain why this isn’t working? I know it’s just something to do with the test expression.
XML (output in array, don’t have original XML file)
Array
(
[RowCount] => 3
[HasError] => false
[ErrorMessage] => Array
(
)
[StackTrace] => Array
(
)
[IncidentList] => Array
(
[Incident] => Array
(
[0] => Array
(
[GroupName] => EXTERNAL_SUPPORT
[IncidentNumber] => 229178
[OpenDateAndTime] => 2011-05-09T10:42:33
[State] => O
[StatusID] => EMAIL WIP
[SubjectID] => MAGIC
[UrgencyID] => NORMAL
)
[1] => Array
(
[GroupName] => CISS SYSTEMS
[IncidentNumber] => 203863
[OpenDateAndTime] => 2010-05-25T09:16:55
[State] => C
[StatusID] => CLOSED
[SubjectID] => ULID EXPIRATION
[UrgencyID] => NORMAL
)
[2] => Array
(
[GroupName] => HELP DESK 1ST LEVEL
[IncidentNumber] => 186909
[OpenDateAndTime] => 2009-09-11T09:58:44
[State] => C
[StatusID] => CLOSED
[SubjectID] => QUESTION
[UrgencyID] => NORMAL
)
)
)
)
What I’m using is this snippet of XSLT to display a table based on the State being O, C, or otherwise, display a message that there are no tickets to display.
<xsl:template match="/">
<table id="myTable" class="list">
<tr>
<td class="title">Incident</td>
<td class="title">Category</td>
<td class="title">State</td>
<td class="title">Status</td>
<td class="title">Date</td>
</tr>
<xsl:choose>
<xsl:when test="State = 'O'">
<xsl:for-each select="Results/IncidentList/Incident">
<tr>
<td>#<xsl:value-of select="IncidentNumber"/></td>
<td><xsl:value-of select="SubjectID"/></td>
<td>OPEN</td>
<td><xsl:value-of select="StatusID"/></td>
<td>
<xsl:call-template name="formatDate">
<xsl:with-param name="dateTime" select="OpenDateAndTime" />
</xsl:call-template>
</td>
</tr>
</xsl:for-each>
</xsl:when>
<xsl:when test="State = 'C'">
<xsl:for-each select="Results/IncidentList/Incident">
<tr>
<td class="closed">#<xsl:value-of select="IncidentNumber"/></td>
<td class="closed"><xsl:value-of select="SubjectID"/></td>
<td class="closed">CLOSED</td>
<td class="closed"></td>
<td class="closed">
<xsl:call-template name="formatDate">
<xsl:with-param name="dateTime" select="OpenDateAndTime" />
</xsl:call-template>
</td>
</tr>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<tr>
<td colspan="5">There are no incidents to display</td>
</tr>
</xsl:otherwise>
</xsl:choose>
</table>
</xsl:template>
</xsl:stylesheet>
I have tried every iteration of the test expression and I either get errors or it skips directly to the otherwise. Any help would be greatly appreciated!
You probably meant this instead of your ‘xsl:when’s:
and
etc. The context on your ‘when’ condition in your example is not an Incident, but the root of the XML document. So you could also prefer:
Another alternative is using templates: