XSLT Grouping please help

Discussion in 'XML' started by Mark, Aug 16, 2005.

  1. Mark

    Mark Guest

    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>
    <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
     
    Mark, Aug 16, 2005
    #1
    1. Advertising

  2. 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"
    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
     
    Janwillem Borleffs, Aug 18, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christian Ludwig

    XSLT: sorting and grouping

    Christian Ludwig, Nov 24, 2003, in forum: XML
    Replies:
    2
    Views:
    612
    Christian Ludwig
    Nov 26, 2003
  2. Kevin Brown
    Replies:
    3
    Views:
    554
    Kevin Brown
    Aug 28, 2004
  3. Graham

    Help Grouping/Counting XSLT

    Graham, Sep 17, 2004, in forum: XML
    Replies:
    3
    Views:
    571
    =?ISO-8859-1?Q?J=FCrgen_Kahrs?=
    Sep 17, 2004
  4. Per Jørgen Vigdal

    Help on xslt - grouping

    Per Jørgen Vigdal, May 19, 2005, in forum: XML
    Replies:
    6
    Views:
    493
    Dimitre Novatchev
    May 20, 2005
  5. KK
    Replies:
    2
    Views:
    622
    Big Brian
    Oct 14, 2003
Loading...

Share This Page