how to add data HTML table in column wise in xslt



The table is called school. it has two columns called students and teachers. I want to add teachers and students names to respective column. this is my xml



<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="school.xsl"?>
<school>
<students>
<student>
<name>Lakshman</name>
</student>
<student>
<name>Tharindu</name>
</student>
</students>
<teachers>
<teacher>
<name>Sarath</name>
</teacher>
<teacher>
<name>Hemantha</name>
</teacher>
<teacher>
<name>Upali</name>
</teacher>
</teachers>
</school>


this is my xsl file as referenced by xml file



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://ift.tt/tCZ8VR">
<xsl:template match="/">
<html>
<body>
<h2>School</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Students</th>
<th>Teachers</th>
</tr>
<td>
<xsl:for-each select="school/students/student">
<tr><td><xsl:value-of select="name"/></td></tr>
</xsl:for-each>
</td>
<td>
<xsl:for-each select="school/teachers/teacher">
<tr><td><xsl:value-of select="name"/></td></tr>
</xsl:for-each>
</td>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


but it prints the table like this.


enter image description here


is there anyway to add students and teachers names to their respective column?


No comments:

Post a Comment