xslt - delete consecutive nodes with same name -


i trying use xslt transform following xml:

 <level>     <nextlevel>         <note> text text text </note>     </nextlevel>     <nextlevel>          <abc>         </abc>         <note>bla bla bla </note>         <note>bla bla bla bla bla</note>         <xyz>         </xyz>     </nextlevel>     <nextlevel>         <note> text text text </note>     </nextlevel> </level> 

i want remove duplicate nodes "note" when appears twice consecutively. output should like:

<level>  <nextlevel>     <note> text text text </note>  </nextlevel>   <nextlevel>        <abc>     </abc>     <xyz>     </xyz>  </nextlevel>  <nextlevel>     <note> text text text </note>  </nextlevel> </level> 

i using following xslt:

<xsl:key name="dup" match="note" use="concat(generate-id(..), '|', name())"/>  <xsl:template match="@*|node()">     <xsl:copy>         <xsl:apply-templates select="@*|node()"/>     </xsl:copy> </xsl:template>  <xsl:template match="note[not(generate-id() = generate-id(key('dup', concat(generate-id(..), '|', .))[1]))]"/> 

however, nodes name "note" being deleted, wrong xslt?

try using avoid repetition of consecutive node of same name same value

 <xsl:template match="@*|node()">         <xsl:copy>             <xsl:apply-templates select="@*|node()"/>         </xsl:copy>     </xsl:template>          <xsl:template match="*[not(*)][name() = preceding-sibling::*[1]/name()][@value = preceding-sibling::*[1]/@value]" /> 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -