Hi all,
Can someone give me a hand with this? I have an XML document which contains results of a questionnaire. The questions are listed at the top of the document and each user's response(s) are listed below. Users may not have answered all the questions, and if they have not answered a question then a node for the response does not appear in the XML. The questions have odd numbering and are in a completely random order, but are asked in order of display in the XML. For example:
I need to display an HTML table of all the results like this:
I got as far as:
Which doesn't work at all. Can anyone help?
C:\DOS:>
C:\DOS:>RUN
RUN DOS RUN!!
Can someone give me a hand with this? I have an XML document which contains results of a questionnaire. The questions are listed at the top of the document and each user's response(s) are listed below. Users may not have answered all the questions, and if they have not answered a question then a node for the response does not appear in the XML. The questions have odd numbering and are in a completely random order, but are asked in order of display in the XML. For example:
Code:
<?xml version="1.0" encoding="utf-8"?>
<QuestionGrid>
<Questions>
<Question QuestionId="51" QuestionText="Favorite Music" />
<Question QuestionId="52" QuestionText="Favorite Place" />
<Question QuestionId="2" QuestionText="Favorite Food" />
</Questions>
<Response ResponseId="8621" EmployeeName="Fred Bloggs" DepartmentName="training">
<Answer QuestionId="51" Answer="The Killers" />
</Response>
<Response ResponseId="8622" EmployeeName="A Nonymouse" DepartmentName="IT">
<Answer QuestionId="51" Answer="Kings of Leon" />
<Answer QuestionId="52" Answer="Florida" />
<Answer QuestionId="2" Answer="Hamburgers" />
</Response>
<Response ResponseId="8623" EmployeeName="Dan Tman" DepartmentName="training">
<Answer QuestionId="2" Answer="Sushi" />
</Response>
</QuestionGrid>
I need to display an HTML table of all the results like this:
Code:
Name Department Favorite Music Favorite Place Favorite Food
Fred Bloggs training The Killers
A Nonymouse IT Kings of Leon Florida Hamburgers
Dan Tman training Sushi
I got as far as:
Code:
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<table border="1" class="defaultstyle">
<tr>
<th style="writing-mode: tb-rl; text-align:right;">Employee</th>
<th style="writing-mode: tb-rl; text-align:right;">Department</th>
<xsl:for-each select="QuestionGrid/Questions/Question">
<th style="writing-mode: tb-rl; text-align:right;">
<xsl:value-of select="@QuestionText"/>
</th>
</xsl:for-each>
</tr>
<xsl:for-each select="QuestionGrid/Response">
<tr>
<td>
<xsl:value-of select="@EmployeeName"/>
</td>
<td>
<xsl:value-of select="@DepartmentName"/>
</td>
<xsl:for-each select="QuestionGrid/Questions/Question">
<xsl:apply-templates select="Answer">
<xsl:with-param name="ResponseId" select="@ResponseId" />
</xsl:apply-templates>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<xsl:template match="Answer">
<xsl:param name="ResponseId"/>
<td>
<xsl:value-of select="/QuestionGrid/Response[@ResponseId=$ResponseId]/Answer[@QuestionId=@QuestionId]/@Answer"/>
</td>
</xsl:template>
Which doesn't work at all. Can anyone help?
C:\DOS:>
C:\DOS:>RUN
RUN DOS RUN!!