Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML, XSL and Grouping. 15 hours or I get axed! Help!

Status
Not open for further replies.

jinglebells

Programmer
Jan 13, 2002
4
0
0
GB
I'll make it short and sweet, don't have much time!!

I have an XML file. I need to create an XSL file to create a table for each separate entity, listing each table separately. For example, I have several Students, each one has taken several classes. Each table should display the student and classes they have taken. Each student in a separate table.

I have the XML file, I just need help constructing the XSL file.

I've been at it for 4 entire days now. Haven't seen the light of day. If anyone can help me out, I'll buy you a beer at your favourite pub in London.

Cheers!

P.S. I'm not kidding about the 15 hours. :(
 
Here it is. I really hope someone can help.

Cheers.


<?xml version = &quot;1.0&quot; ?>
<?xml-stylesheet type=&quot;text/&quot;text/xsl&quot; href=&quot;students.xsl&quot;?>


<!DOCTYPE students [
<!ELEMENT students (student+)>
<!ELEMENT student (coursename,studentid,surname,name+)>
<!ELEMENT surname (#PCDATA)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT studentid (#PCDATA)>
<!ELEMENT coursename (#PCDATA)>

]>

<students>
<student>
<surname>Duncan</surname>
<name>Sabrina</name>
<studentid>111</studentid>
<coursename>Intro to Visual Basic</coursename>
<coursename>Intermediate Visual Basic</coursename>
<coursename>Advanced Visual Basic</coursename>
</student>
<student>
<surname>Teeves</surname>
<name>Andrew</name>
<studentid>112</studentid>
<coursename>Advanced Java</coursename>
</student>
<student>
<surname>Dunn</surname>
<name>Martin</name>
<studentid>113</studentid>
<coursename>Intro to InterDev</coursename>
<coursename>Intermediate Interdev</coursename>
<coursename>Advanced Visual Basic</coursename>
</student>
</students>
 
<?xml version=&quot;1.0&quot; ?>
<xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;
<xsl:template match=&quot;/students&quot;>
<html>
<head>....
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

<xsl:template match=&quot;student&quot;>
<table>
<tr>
<td>
<xsl:value-of select=&quot;concat(name, ' ', surname)&quot;/>
</td>
<td>
<xsl:value-of select=&quot;studentid&quot;/>
</td>
<td>
<xsl:value-of select=&quot;coursename[1]&quot;/>
</td>
</tr>
<xsl:for-each select=&quot;coursename[position() > 1]&quot;>
<tr>
<td/><td/>
<td>
<xsl:value-of select=&quot;.&quot;/>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>


</xsl:stylesheet>

hope this was along the lines of wot u needed.
 
You got the idea! I'm kinda embarrassed to ask but is this what I put in the .xml?

<?xml version=&quot;1.0&quot; ?>
<xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;<?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;students.xsl&quot;?>

I did this and got an error saying there's a white space missing after Transform&quot;;>

I must be missing a few brain cells if I can't figure that part out.

Regards and very so grateful.
 
wot you wrote goes in the .xml and wot i wrote goes in the .xsl

also remove any &quot;;&quot; you see - this is just added by mistake by this website.
 
Yep, I got that. I've done quite a few XML and XSL but this one is a pain. With your xsl what I get in the browser is text &quot;Student&quot;. Got rid of those ; too.

This is what my xml file looks like (just 1 student for demonstration purposes):

<?xml version=&quot;1.0&quot;?>
<?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;students.xsl&quot;?>
<xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;
<students>
<student>
<surname>Duncan</surname>
<name>Sabrina</name>
<studentid>111</studentid>
<coursename>Intro to Visual Basic</coursename>
<coursename>Intermediate Visual Basic</coursename>
<coursename>Advanced Visual Basic</coursename>
</student>

I don't want to waste too much of your valuable time or web space on here, but I've tried everything I can think of and I can't identify what is missing.

I understand if you're done dealing with this dingbat. I'll still buy you a beer for your time if you're ever in London.


Miss Jinglebells
 
Jinglebells --

Did MrTom's help get you through the problem? If not, you should find everything you need to answer your questions, including some working code, here... thread426-189284
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top