XSLT Grouping please help

M

Mark

I must say that I'm quite the newb with XML/XSLT. I kind of stubmled
upon using it for a report I'm trying to make. If someone would be so
kind as to help out with the following I would be grateful. I have the
following XML output from SQL server 2000 and would like to transform
it such that teh questions are grouped by QID.
----------------------------------------------------------------
<Personal>
<MCRegID>946</MCRegID>
<MCFirstName>Testter</MCFirstName>
<MCLastNmae>TestLast</MCLastNmae>
<RegID>946</RegID>
<Prefix>1</Prefix>
<FirstName>testFirst</FirstName>
<LastName>TestLast</LastName>
<BadgeName></BadgeName>
<Phone>5555555555</Phone>
<Fax>5555555555</Fax>
<email>[email protected]</email>
<DateTimeStamp>2005-08-02T16:48:44.700</DateTimeStamp>
<RegDate>2005-08-02T16:52:41.967</RegDate>
<Gen1>5555555555</Gen1>
<Gen9>1</Gen9>
<Gen10>0</Gen10>
<RegTypeName>Attending</RegTypeName>
<Questions>
<QRegID>946</QRegID>
<QID>11</QID>
<QuestionName>Contact Name (For Emergencies)</QuestionName>
<AnswerName>SOme Guy</AnswerName>
</Questions>
<Questions>
<QRegID>946</QRegID>
<QID>12</QID>
<QuestionName>Ground Travel</QuestionName>
<AnswerName>I will be driving to this event.</AnswerName>
</Questions>
<Questions>
<QRegID>946</QRegID>
<QID>12</QID>
<QuestionName>Ground Travel</QuestionName>
<AnswerName>I would like parking at the hotel.</AnswerName>
</Questions>
<Questions>
<QRegID>946</QRegID>
<QID>13</QID>
<QuestionName>Clothing Size</QuestionName>
<AnswerName>Men&apos;s Extra Large</AnswerName>
</Questions>
<Questions>
<QRegID>946</QRegID>
<QID>14</QID>
<QuestionName>I would Prefer</QuestionName>
<AnswerName>Non-Smoking</AnswerName>
</Questions>
<Questions>
<QRegID>946</QRegID>
<QID>15</QID>
<QuestionName>Special Requests</QuestionName>
<AnswerName>Request room upgrade - sharing with XXX YYYY</AnswerName>
</Questions>
</Personal>
----------------------------------------------------

Currently I have the following for my XSLT:

----------------------------------------------------
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<body>
<table border="1">
<xsl:for-each select="Document/Personal">
<tr>
<td valign="top" width="200">
<xsl:value-of select="FirstName" />
</td>

<td valign="top" width="200">
<xsl:value-of select="LastName" />
</td>

<xsl:for-each select="Questions">
<xsl:sort select="QID"/>
<td align="CENTER">

<xsl:value-of select="QID"/><BR/>
<xsl:value-of select="QuestionName"/><BR/>
:<xsl:value-of select="AnswerName"/>

</td>
</xsl:for-each>
</tr>
</xsl:for-each>

</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
----------------------------------------------------


Unfortunately, I need to group by QID and have each result from , for
instance QID #12 appear in one HTML table cell. I've been reading up
on the muenchian method, but I can't seem to grasp what's happening.

If anyone could chime in I would truely appreciate it.

Mark
 
J

Janwillem Borleffs

Mark said:
Unfortunately, I need to group by QID and have each result from , for
instance QID #12 appear in one HTML table cell. I've been reading up
on the muenchian method, but I can't seem to grasp what's happening.

If anyone could chime in I would truely appreciate it.

Here's a start:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:key name="myKey" match="QID" use="text()" />
<xsl:template match="/">
<html>
<body>
<table border="1">
<xsl:for-each select="Document/Personal">
<tr>
<td valign="top" width="200">
<xsl:value-of select="FirstName" />
</td>

<td valign="top" width="200">
<xsl:value-of select="LastName" />
</td>

<xsl:for-each select="Questions[generate-id(QID) =
generate-id(key('myKey',QID))]">
<xsl:sort select="QID"/>
<xsl:variable name="QID" select="QID"/>
<td align="CENTER">

<xsl:value-of select="QID"/><BR/>

<xsl:for-each select="../Questions[QID=$QID]">
<xsl:value-of select="QuestionName"/><BR/>
:<xsl:value-of select="AnswerName"/>
</xsl:for-each>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>

</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


HTH;
JW
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top