There is xslt code for version 2.0 which gives output shown below but I want to convert it to version 1.0. I referred following links.. How to compare two XML nodes and get compared result using XSLT? and xslt compare two different nodes and then combine
Input XML file:
<?xml version="1.0" encoding="utf-8"?>
<OperatorStationCollection xmlns="http://www.w3.org" >
<OperatorStation xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Name>OS001</Name>
<Nodes>
<DataNodeBase xsi:type="Adaptor">
<Family>NetworkSettings</Family>
<Name>Network A</Name>
<IPAddress>111.11.11.1</IPAddress>
</DataNodeBase>
<DataNodeBase xsi:type="Adaptor">
<Family>Network1111</Family>
<Name>Network B</Name>
<IPAddress>111.22.11.1</IPAddress>
</DataNodeBase>
<DataNodeBase xsi:type="Adaptor">
<Family>Network2222</Family>
<Name>Network C</Name>
<IPAddress>111.33.11.1</IPAddress>
</DataNodeBase>
</Nodes>
</OperatorStation>
<OperatorStation xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Name>OS002</Name>
<Nodes>
<DataNodeBase xsi:type="Adaptor">
<Family>NetworkSettings</Family>
<Name>Network A</Name>
<IPAddress>111.11.11.1</IPAddress>
</DataNodeBase>
<DataNodeBase xsi:type="Adaptor">
<Family>Network1111</Family>
<Name>Network B</Name>
<IPAddress>111.22.11.2</IPAddress>
</DataNodeBase>
<DataNodeBase xsi:type="Adaptor">
<Family>NetworkSettings</Family>
<Name>Network D</Name>
<IPAddress>111.33.11.2</IPAddress>
</DataNodeBase>
</Nodes>
</OperatorStation>
<OperatorStation xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Name>OS003</Name>
<Nodes>
<DataNodeBase xsi:type="Adaptor">
<Family>NetworkSettings</Family>
<Name>Network A</Name>
<IPAddress>111.11.11.1</IPAddress>
</DataNodeBase>
<DataNodeBase xsi:type="Adaptor">
<Family>NetworkSettings</Family>
<Name>Network B</Name>
<IPAddress>111.22.11.3</IPAddress>
</DataNodeBase>
<DataNodeBase xsi:type="Adaptor">
<Family>NetworkSettings</Family>
<Name>Network E</Name>
<IPAddress>111.33.11.3</IPAddress>
</DataNodeBase>
</Nodes>
</OperatorStation>
</OperatorStationCollection>
XSLT code for version 2.0:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="/">
<xsl:variable name="allStations"
select="/*:OperatorStationCollection/*:OperatorStation" />
<table>
<!-- Header row - two fixed columns plus one per station name -->
<tr>
<td>Name</td><td>Status</td>
<xsl:for-each select="$allStations">
<td><xsl:value-of select="*:Name" /></td>
</xsl:for-each>
</tr>
<!-- main rows - one per "group" of DataNodeBase elements which share the
same Name -->
<xsl:for-each-group
select="$allStations/*:Nodes/*:DataNodeBase"
group-by="*:Name">
<!-- calculate the column values - the IPAddress if this network (i.e. the
current-group) has an entry for this station, and "None" if not -->
<xsl:variable name="addresses"
select="for $s in ($allStations)
return (current-group()[../.. is $s]/*:IPAddress, 'None')[1]" />
<tr>
<td><xsl:value-of select="current-grouping-key()" /></td>
<td>
<!-- equal if all the $addresses are the same, unequal otherwise -->
<xsl:value-of select="if (count(distinct-values($addresses)) = 1)
then 'Equal' else 'Unequal'" />
</td>
<xsl:for-each select="$addresses">
<td><xsl:value-of select="."/></td>
</xsl:for-each>
</tr>
</xsl:for-each-group>
</table>
</xsl:template>
</xsl:stylesheet>
Expected OUTPUT: As there is no provision to add table , I have made hatml code for result, please save this code to html file and see expected output.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<table>
<tr>
<td>Name</td><td>Status</td><td>OS01</td><td>OS02</td><td>OS03</td>
</tr>
<tr>
<td>Network A</td><td>Equal</td><td>111.11.11.1</td><td>111.11.11.1</td><td>111.11.11.1</td>
</tr>
<tr>
<td>Network B</td><td>Unequal</td><td>111.22.11.1</td><td>111.22.11.2</td><td>111.22.11.2</td>
</tr>
<tr>
<td>Network C</td><td>Unequal</td><td>111.33.11.1</td><td>Not Exist</td><td>Not Exist</td>
</tr>
<tr>
<td>Network D</td><td>Unequal</td><td>Not Exist</td><td>111.33.11.2</td><td>Not Exist</td>
</tr>
<tr>
<td>Network E</td><td>Unequal</td><td>Not Exist</td><td>Not Exist</td><td>111.33.11.3</td>
</tr>
</table>
</body>
</html>