473,408 Members | 2,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

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>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>Te*******@TEst.com</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

Aug 15 '05 #1
1 1414
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

Aug 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Peter Gerstbach | last post by:
Hello, I need help on the new xsl:document element! I'm using XSLT version 1.1 to be able to use the <xsl:document> element, because I need more than 1 output files. I'm using Saxon 6.5.3 My...
3
by: Kevin Brown | last post by:
Is there anyway to generate this type of resulting HTML table from this XML using XSLT? Basically I need to be able to consult 2 trees of data to generate the HTML, but I have not been able to...
3
by: Graham | last post by:
Hi, I am having trouble getting XSL to count the members of a group. What I am trying to do is group by <objectid.Contactid> and count the number of <activityid>'s for each <objectid.contactid>....
5
by: inquirydog | last post by:
Hi- Does anyone know a way to compare whether two nodes contain the same information in xslt (the name, attributes, and all content recursivly should be the same. I am interested in the case...
5
by: Jody Greening | last post by:
Transforming with XSLT, Grouping elements until difference found. I am seeking some help with the following problem, I am fairly new at XSLT transformations, and my problem may lie in looking at...
4
by: Chris Kettenbach | last post by:
Hi Peter, I get error when processing the stylesheet. It errors here. <xsl:for-each select="registration)=1]"> specifically: Expression does not return a DOM node. registration)=1]<--
0
by: DAnne | last post by:
Hi, I'm very new to xslt and this is my first time posting to a Forum so please forgive me if I transgress any protocols. I have to do a tally report. This report is divided up into sections....
3
by: silver_sabrina | last post by:
Hey everyone, I'm having some trouble with this. I need to convert one xml doc into another and I think that XSLT may be the answer, so I'd like some help from the gurus out here :) If XSLT cannot...
2
jkmyoung
by: jkmyoung | last post by:
Here's a short list of useful xslt general tricks that aren't taught at w3schools. Attribute Value Template Official W3C explanation and example This is when you want to put dynamic values...
1
by: Sandeep Singh | last post by:
Hi, How to do group by in XSLT ? I tried on the following codes: <files> <file name="swablr.eps" size="4313" project="mars"/> <file name="batboy.wks" size="424" ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.