我有一个带有多个内部循环的XML,我需要循环遍历1个节点并在HTML视图中显示它。 XML在下面给出
<?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>
答案 0 :(得分:1)
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>