XSLT :How to remove duplicate Tag in XML
<p>We are getting duplicate tag in this Input XML. we wanted to remove this duplication using XSLT2.0 template Instruction.</p>

<p>Input XML :</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;SalesOrders xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:noNamespaceSchemaLocation="SDOC.XSD"&gt;
   &lt;Orders&gt;
      &lt;OrderHeader&gt;
         &lt;CustomerPoNumber&gt;AB-54354&lt;/CustomerPoNumber&gt;
      &lt;/OrderHeader&gt;
      &lt;OrderDetails&gt;
         &lt;CommentLine&gt;
            &lt;Comment&gt;Ensure saddle is color coded&lt;/Comment&gt;
            &lt;OrderLineID&gt;OR-1810127&lt;/OrderLineID&gt;
         &lt;/CommentLine&gt;
         &lt;CommentLine&gt;
            &lt;Comment&gt;EDI-001&lt;/Comment&gt;
            &lt;OrderLineID&gt;OR-1810128&lt;/OrderLineID&gt;
         &lt;/CommentLine&gt;
         &lt;StockLine&gt;
            &lt;CustomerPoLine&gt;9999&lt;/CustomerPoLine&gt;
            &lt;StockCode&gt;ABSH-SMH-12OZ-01&lt;/StockCode&gt;
            &lt;StockDescription&gt;SMH ABS BALANCE SHAMPOO 12OZ&lt;/StockDescription&gt;
            &lt;OrderQty&gt;1.0&lt;/OrderQty&gt;
         &lt;/StockLine&gt;
         &lt;CommentLine&gt;
            &lt;Comment&gt;This is for test purpose&lt;/Comment&gt;
            &lt;OrderLineID&gt;OR-1810124&lt;/OrderLineID&gt;
         &lt;/CommentLine&gt;
         &lt;CommentLine&gt;
            &lt;Comment&gt;EDI-SAVE&lt;/Comment&gt;
            &lt;OrderLineID&gt;OR-1810125&lt;/OrderLineID&gt;
         &lt;/CommentLine&gt;
         &lt;CommentLine&gt;
            &lt;Comment&gt;Ensure saddle is color coded&lt;/Comment&gt;
            &lt;OrderLineID&gt;OR-1810127&lt;/OrderLineID&gt;
         &lt;/CommentLine&gt;
      &lt;/OrderDetails&gt;
   &lt;/Orders&gt;
&lt;/SalesOrders&gt;
</code></pre>

<p>We Tried following XSLT on it:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"&gt;
   &lt;xsl:output method="xml" encoding="Windows-1252" indent="yes" /&gt;
   &lt;xsl:template match="@*|node()"&gt;
      &lt;xsl:copy copy-namespaces="no"&gt;
         &lt;xsl:apply-templates select="@*|node()" /&gt;
      &lt;/xsl:copy&gt;
   &lt;/xsl:template&gt;
   &lt;xsl:template match="StockLine[not(StockCodeDescription) and not (OrderQty) and not(Price)]"&gt;
      &lt;CommentLine&gt;
         &lt;Comment&gt;
            &lt;xsl:value-of select="StockCode" /&gt;
         &lt;/Comment&gt;
         &lt;xsl:copy-of select="OrderLineID" /&gt;
      &lt;/CommentLine&gt;
   &lt;/xsl:template&gt;
   &lt;xsl:template match="CommentLine[OrderLineID = preceding-sibling::StockLine/OrderLineID and not(Comment)]" /&gt;
&lt;/xsl:stylesheet&gt;
</code></pre>

<p>Expected Output XML:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;SalesOrders xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:noNamespaceSchemaLocation="SDOC.XSD"&gt;
   &lt;Orders&gt;
      &lt;OrderHeader&gt;
         &lt;CustomerPoNumber&gt;AB-54354&lt;/CustomerPoNumber&gt;
      &lt;/OrderHeader&gt;
      &lt;OrderDetails&gt;
         &lt;CommentLine&gt;
            &lt;Comment&gt;Ensure saddle is color coded&lt;/Comment&gt;
            &lt;OrderLineID&gt;OR-1810127&lt;/OrderLineID&gt;
         &lt;/CommentLine&gt;
         &lt;CommentLine&gt;
            &lt;Comment&gt;EDI-001&lt;/Comment&gt;
            &lt;OrderLineID&gt;OR-1810128&lt;/OrderLineID&gt;
         &lt;/CommentLine&gt;
         &lt;StockLine&gt;
            &lt;CustomerPoLine&gt;9999&lt;/CustomerPoLine&gt;
            &lt;StockCode&gt;ABSH-SMH-12OZ-01&lt;/StockCode&gt;
            &lt;StockDescription&gt;SMH ABS BALANCE SHAMPOO 12OZ&lt;/StockDescription&gt;
            &lt;OrderQty&gt;1.0&lt;/OrderQty&gt;
         &lt;/StockLine&gt;
         &lt;CommentLine&gt;
            &lt;Comment&gt;This is for test purpose&lt;/Comment&gt;
            &lt;OrderLineID&gt;OR-1810124&lt;/OrderLineID&gt;
         &lt;/CommentLine&gt;
         &lt;CommentLine&gt;
            &lt;Comment&gt;EDI-SAVE&lt;/Comment&gt;
            &lt;OrderLineID&gt;OR-1810125&lt;/OrderLineID&gt;
         &lt;/CommentLine&gt;
      &lt;/OrderDetails&gt;
   &lt;/Orders&gt;
&lt;/SalesOrders&gt;
</code></pre>

<p>This element is duplicating inside XML.</p>

<pre><code>&lt;CommentLine&gt;
            &lt;Comment&gt;Ensure saddle is color coded&lt;/Comment&gt;  
            &lt;OrderLineID&gt;OR-1810127&lt;/OrderLineID&gt;  
          &lt;/CommentLine&gt;  
</code></pre>

<p>Any help on it would be much appreciated !</p>