Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSLT Grouping please help

Reply
Thread Tools

XSLT Grouping please help

 
 
Mark
Guest
Posts: n/a
 
      08-15-2005
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>(E-Mail Removed)</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"
xmlnssl="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

 
Reply With Quote
 
 
 
 
Janwillem Borleffs
Guest
Posts: n/a
 
      08-18-2005
Mark wrote:
> 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"
xmlnssl="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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help on xslt - grouping Per Jørgen Vigdal XML 6 05-20-2005 09:17 PM
Transforming with XSLT, Grouping elements until difference found. Jody Greening XML 5 01-06-2005 06:52 PM
Help Grouping/Counting XSLT Graham XML 3 09-17-2004 06:20 PM
XSLT XML-HTML Transformation using grouping Kevin Brown XML 3 08-28-2004 03:39 PM
XSLT: sorting and grouping Christian Ludwig XML 2 11-26-2003 10:37 AM



Advertisments