Connecting Tech Pros Worldwide Help | Site Map

How to combine the following-sibling is same element

Newbie
 
Join Date: Feb 2009
Posts: 15
#1: Sep 15 '09
Hello Guru's,

I need a help from u guys, I am working on XSLT and my XML is like this

Expand|Select|Wrap|Line Numbers
  1. <text><i>Hello</i><i> world</i>... <i>Here</i> we <i>go</i>... <i>This</i> <i>is</i> for sample</text>
transform to

Expand|Select|Wrap|Line Numbers
  1. <text><i>Hello world</i>... <i>Here</i> we <i>go</i>... <i>This</i> <i>is</i> for sample</text>
If my immediate following sibling is same element, i want to combine it in single element.

Please help me out how to write XSLT transformation for this.

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

re: How to combine the following-sibling is same element


combine the following-sibling axis with a tag name test (name()), although it would be easier to use a script on the xml string and remove consecutive end and start tags.
Newbie
 
Join Date: Sep 2009
Posts: 6
#3: Oct 16 '09

re: How to combine the following-sibling is same element


Hey Sam u can use as following..

Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="i">
  2. <xsl:if test="not(preceding-sibling::*[1][self::i])">
  3.     <xsl:value-of select="'&lt;i&gt;'" disable-output-escaping="yes"/>    
  4. </xsl:if>
  5. <xsl:apply-templates/>
  6. <xsl:if test="not(following-sibling::*[1][self::i])">
  7.     <xsl:value-of select="'&lt;/i&gt;'" disable-output-escaping="yes"/>    
  8. </xsl:if>
  9. </xsl:template>
This works fine for me.. Hope this helps..
Reply