XSLT Grouping please help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark

    #1

    XSLT Grouping please help

    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>Te stter</MCFirstName>
    <MCLastNmae>Tes tLast</MCLastNmae>
    <RegID>946</RegID>
    <Prefix>1</Prefix>
    <FirstName>test First</FirstName>
    <LastName>TestL ast</LastName>
    <BadgeName></BadgeName>
    <Phone>55555555 55</Phone>
    <Fax>5555555555 </Fax>
    <email>Test.Tes t@TEst.com</email>
    <DateTimeStamp> 2005-08-02T16:48:44.700 </DateTimeStamp>
    <RegDate>2005-08-02T16:52:41.967 </RegDate>
    <Gen1>555555555 5</Gen1>
    <Gen9>1</Gen9>
    <Gen10>0</Gen10>
    <RegTypeName>At tending</RegTypeName>
    <Questions>
    <QRegID>946</QRegID>
    <QID>11</QID>
    <QuestionName>C ontact Name (For Emergencies)</QuestionName>
    <AnswerName>SOm e Guy</AnswerName>
    </Questions>
    <Questions>
    <QRegID>946</QRegID>
    <QID>12</QID>
    <QuestionName>G round Travel</QuestionName>
    <AnswerName>I will be driving to this event.</AnswerName>
    </Questions>
    <Questions>
    <QRegID>946</QRegID>
    <QID>12</QID>
    <QuestionName>G round Travel</QuestionName>
    <AnswerName>I would like parking at the hotel.</AnswerName>
    </Questions>
    <Questions>
    <QRegID>946</QRegID>
    <QID>13</QID>
    <QuestionName>C lothing Size</QuestionName>
    <AnswerName>Men &apos;s Extra Large</AnswerName>
    </Questions>
    <Questions>
    <QRegID>946</QRegID>
    <QID>14</QID>
    <QuestionName >I would Prefer</QuestionName>
    <AnswerName>N on-Smoking</AnswerName>
    </Questions>
    <Questions>
    <QRegID>946</QRegID>
    <QID>15</QID>
    <QuestionName>S pecial Requests</QuestionName>
    <AnswerName>Req uest room upgrade - sharing with XXX YYYY</AnswerName>
    </Questions>
    </Personal>
    ----------------------------------------------------

    Currently I have the following for my XSLT:

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

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

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

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

    <xsl:value-of select="QID"/><BR/>
    <xsl:value-of select="Questio nName"/><BR/>
    :<xsl:value-of select="AnswerN ame"/>

    </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

  • Janwillem Borleffs

    #2
    Re: XSLT Grouping please help

    Mark wrote:[color=blue]
    > 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.
    >[/color]

    Here's a start:

    <xsl:styleshe et 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="Documen t/Personal">
    <tr>
    <td valign="top" width="200">
    <xsl:value-of select="FirstNa me" />
    </td>

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

    <xsl:for-each select="Questio ns[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="Questio nName"/><BR/>
    :<xsl:value-of select="AnswerN ame"/>
    </xsl:for-each>
    </td>
    </xsl:for-each>
    </tr>
    </xsl:for-each>

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


    HTH;
    JW



    Comment

    Working...