Umesh Chandra Kahali
Umesh Chandra Kahali

Reputation: 71

merging two xml elements uning XSLT

I have a large xml file like below

:
:
<CN>222</CN>
<CT>Raam</CT>
:
:

I would like to merge these two elements as

<CN>222 Raam</CN>

then like to convert it as

<div>222 Raam</div>

which is the final output.

Upvotes: 0

Views: 181

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167471

Well if all you need is merging the two consecutive elements in a div (I don't understand what the intermediary CN is for) then use

<xsl:template match="@* | node()">
  <xsl:copy>
    <xsl:apply-templates select="@* | node()"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="CN[following-sibling::*[1][self::CT]]">
  <div>
    <xsl:value-of select="concat(., ' ', following-sibling::*[1][self::CT])"/>
  </div>
</xsl:template>

<xsl:template match="CT[preceding-sibling::*[1][self::CN]]"/>

Upvotes: 1

Related Questions