Connecting Tech Pros Worldwide Help | Site Map

Removing following sibling same element name

Newbie
 
Join Date: Feb 2009
Posts: 15
#1: Feb 4 '09
Hi All,

I want to remove the immediate following sibling element name

For e.g.

Expand|Select|Wrap|Line Numbers
  1. <def-item>
  2.   <term id="G1">CGRP</term>
  3.   <abr-rel-sym style="inline">&#x02009;</abr-rel-sym>
  4.   <abr-rel-sym style="inline">=</abr-rel-sym>
  5.   <abr-rel-sym style="inline">&#x02009;</abr-rel-sym>
  6.   <def>
  7.     <p>Calcitonin gene-related peptide</p>
  8.   </def>
  9. </def-item>
to

Expand|Select|Wrap|Line Numbers
  1. <def-item>
  2.   <term id="G1">CGRP</term>
  3.   <abr-rel-sym style="inline">&#x02009;=&#x02009;</abr-rel-sym>
  4.   <def>
  5.     <p>Calcitonin gene-related peptide</p>
  6.   </def>
  7. </def-item>
Can any one help me how to do this

Thanks
Sam
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#2: Feb 4 '09

re: Removing following sibling same element name


do you want to use XSLT or any programming language?
Newbie
 
Join Date: Feb 2009
Posts: 15
#3: Feb 4 '09

re: Removing following sibling same element name


I want to use XSLT, thanks for your help in advance
Moderator
 
Join Date: Mar 2006
Posts: 1,103
#4: Feb 4 '09

re: Removing following sibling same element name


Something like:
Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="*">
  2.   <xsl:if test="name() != name(preceding-sibling::*[1])">
  3.     <xsl:copy>
  4.       <xsl:copy-of select="@*">
  5.       <xsl:value-of select="."/>
  6.       <xsl:if test="name() = name(following-sibling::*[1])">
  7.         <xsl:apply-templates select="following-sibling::*[1]" mode="merge"/>
  8.       </xsl:if>
  9.     </xsl:copy>
  10.   </xsl:if>
  11. </xsl:template>
  12. <xsl:template match="*" mode="merge"><!-- don't copy element, only it's contents. -->
  13.   <xsl:apply-templates/>
  14. </xsl:template>
  15.  
Newbie
 
Join Date: Feb 2009
Posts: 15
#5: Feb 5 '09

re: Removing following sibling same element name


Wait i will test and let you know
Reply


Similar XML bytes