Reputation: 149
I have an XML with multiple inner loops, I need to loop through 1 node after another and to display it in HTML view. The XML is given below
<?xml version ="1.0" encoding ="utf-8" ?>
<TestUser>
<Users>
<UserData name="test123" address="USA"/>
<UserCommunication>
<Communication mode="Te" value="123456879"/>
<Qualification>
<PG value="No"></PG>
</Qualification>
<Qualification>
<UG value="YES"></UG>
</Qualification>
</UserCommunication>
</Users>
<Users>
<UserData name="test124" address="UK"/>
<UserCommunication>
<Communication mode="Te" value="1567894525"/>
<Qualification>
<PG value="No"></PG>
</Qualification>
<Qualification>
<UG value="YES"></UG>
</Qualification>
</UserCommunication>
</Users>
<Users>
<UserData name="test125" address="INDIA"/>
<UserCommunication>
<Communication mode="Te" value="5465897845"/>
<Qualification>
<PG value="YES"></PG>
</Qualification>
<Qualification>
<UG value="YES"></UG>
</Qualification>
</UserCommunication>
</Users>
</TestUser>
I need to display the Users details one by one in an HTML view using XSLT as in the image below.
Can anyone help me to achieve this?
Upvotes: 0
Views: 44
Reputation: 1076
Check following Code:-
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="TestUser">
<html>
<head>
</head>
<body>
<table border="5" style="border-collapse: collapse;">
<thead>
<th bgcolor="greeen">User Name</th>
<th bgcolor="greeen">User_Addrss</th>
<th bgcolor="greeen">User_Telephone</th>
<th bgcolor="greeen">PG</th>
<th bgcolor="greeen">UG</th>
</thead>
<xsl:for-each select="//Users/UserData">
<tr>
<td><xsl:value-of select="@name"/></td>
<td><xsl:value-of select="@address"/></td>
<td><xsl:value-of select="../UserCommunication/Communication/@value"/></td>
<td><xsl:value-of select="../UserCommunication/Qualification/PG/@value"/> </td>
<td><xsl:value-of select="../UserCommunication/Qualification/UG/@value"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Upvotes: 1