Forum Moderators: open

Message Too Old, No Replies

XSL Sheet

Need help

         

P_Gupta

2:03 pm on Nov 28, 2007 (gmt 0)

10+ Year Member



My lecturers.xml is

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="lecturers_1.xsl"?>
<!-- Edited with XML Spy v2007 (http://www.altova.com) -->
<tutors>
<tutor>
<name title="Professor" first="Peter" last="Quirk"/>
<teaching>
<course code="CO3070">XML and the Web</course>
<course code="CO3300"/>Web Server Architectures
</teaching>
<research>
The application of Web protocols to Biology
</research>
</tutor>

<tutor>
<name title="Dr" first="Flowers" last="Alan"/>
<teaching>
<course code="CO3001">Design</course>
<course code="CO3100"/>Design and technology
</teaching>
<research>
The application of xml
</research>
</tutor>
</tutors>

My lecturers_1.xsl is

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited with XML Spy v2007 (http://www.altova.com) -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>tutors</h2>
<table border="1">

<tr>
<th>Title</th>
<th>Name</th>
<th>Teaching</th>
<th>Research</th>
</tr>

<xsl:for-each select="tutors/tutor">

<tr>
<td><xsl:value-of select="name/@title"/></td>
<td><xsl:value-of select="name/@first"/><xsl:value-of select="name/@last"/></td>

<xsl:for-each select="teaching">
<td><xsl:value-of select="course"/>(<xsl:value-of select="course/@code"/>)</td>
</xsl:for-each>

<td><xsl:value-of select="research"/></td>
</tr>

</xsl:for-each>

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

Can some pls help me in displaying the teaching tags pls

Thanks

httpwebwitch

6:05 pm on Nov 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



the XML looks weird. like maybe this

<course code="CO3070">XML and the Web</course>
<course code="CO3300"/>Web Server Architectures

should actually be this


<course code="CO3070">XML and the Web</course>
<course code="CO3300">Web Server Architectures</course>

also you're looping through "teaching" when perhaps you mean to loop through courses

instead of:


<xsl:for-each select="teaching">
<td><xsl:value-of select="course"/>(<xsl:value-of select="course/@code"/>)</td>
</xsl:for-each>

try:


<xsl:for-each select="teaching/course">
<td><xsl:value-of select="."/>(<xsl:value-of select="@code"/>)</td>
</xsl:for-each>

Or perhaps you intend to have more than one "teaching" node with many "course" nodes below each, in which case a nested loop or "apply-template" would do the trick.

I didn't test that last chunk of XSLT. Since you're using Altova XML Spy you should be able to nudge and debug your XSL with relative ease... good luck

httpwebwitch

2:25 pm on Nov 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I also just noticed
with your XSL as-is, if you have more than one <teaching> node, you'll create multiple <td> cells, and they won't line up with the <th> headings of the table. If it was my project, I'd create one <td> cell for teaching, and apply a new template to render the courses, separated by line breaks within that cell.

(within the root template)...
<td>
<xsl:apply-templates select="teaching" />
</td>

(outside the main template, within the stylesheet)
...

<xsl:template match="teaching">
<xsl:for-each select="course">
<xsl:value-of select=".">(<xsl:value-of select="course/@code"/>)<br/>
</xsl:for-each>
</xsl:template>

once again I've typed this XSL blindly sans testing, so it may be buggy. But you can paste this into Altova and massage it until it purrs