I have an XML file like:
<Documents>
<Document>
<firstname>Vaneet</firstname>
<lastname>chendra</lastname>
<ID_DOC>101121</ID_DOC>
<Doc_Type>html</Doc_Type>
</Document>
<Document>
<firstname>joshna</firstname>
<lastname>shekar</lastname>
<ID_DOC>101121</ID_DOC>
<Doc_Type>Text</Doc_Type>
</Document>
</Documents>
and my output XML should be like
<Documents>
<Document>
<firstname>Vaneet</firstname>
<lastname>chendra</lastname>
<ID_DOC>101121</ID_DOC>
<Doc_Type>html</Doc_Type>
<firstname>joshna</firstname>
<lastname>shekar</lastname>
<Doc_Type>Text</Doc_Type>
</Document>
</Documents>
I tried the Below XSLT but cant get the output
the child nodes of same value of different parent node should be removed and the remaining child nodes of parent of the duplicate child node needs to be appended to the previous parent nodeenter code here
<?xml version = "1.0" encoding = "UTF-8"?>
<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:template match = "/">
<html>
<body>
<h3>Details of each Documents. Xpath expression = "/Documents/Document"</h3>
<table border = "1">
<tr bgcolor = "#9acd32">
<th>ID_DOC</th>
<th>First Name</th>
<th>Last Name</th>
<th>Doc_Type</th>
</tr>
<xsl:for-each select = "/Documents/Document">
<xsl:variable name="myVar" select="@ID_DOC"
<xsl:for-each select = "/Documents/Document">
<xsl:variable name="i" select="position()+1" />
<xsl:variable name="myVar1" select="ID_DOC[i]"
<xsl:if test="$myVar != $myVar1">
<!comment : i am trying to compare the previous node value with current node value>
<!comment : and also to append it to the previous parent node if present and i am not able to do so>
<tr>
<td><xsl:value-of select = "ID_DOC"/></td>
<td><xsl:value-of select = "firstname"/></td>
<td><xsl:value-of select = "lastname"/></td>
<td><xsl:value-of select = "Doc_Type"/></td>
</tr>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
I have tried as you explained through the link but i am getting errors like net.sf.saxon.s9api.SaxonApiException and I dont know where is the error so can you tell me where did i go wrong. Here is my code that i have Tried -->@michael.hor257k
<?xml version = "1.0" encoding = "UTF-8"?>
<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:template match = "/">
<html>
<body>
<h3>Details of each Documents. Xpath expression = "/Documents/Document"</h3>
<table border = "1">
<tr bgcolor = "#9acd32">
<th>ID_DOC</th>
<th>First Name</th>
<th>Last Name</th>
<th>Doc_Type</th>
</tr>
<xsl:key name = "Documents-by-ID_DOC" match="Document" use="ID_DOC" />
<xsl:template match="Documents">
<xsl:for-each select="Document[count(. | key('Documents-by-ID_DOC', ID_DOC)[1]) = 1]">
<xsl:sort select="ID_DOC" />
<xsl:value-of select="ID_DOC" />,<br />
<xsl:for-each select="key('Documents-by-ID_DOC', ID_DOC)">
<xsl:sort select="Doc_Type" />
<xsl:value-of select="Doc_Type" /> (<xsl:value-of select="firstname" />)<br />
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Can u help with getting the output using XSLT? THANKS IN ADVANCE