[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: merging the contents of consecutive duplicate ele

Subject: Re: merging the contents of consecutive duplicate elements
From: Mukul Gandhi <gandhi.mukul@xxxxxxxxx>
Date: Tue, 18 Oct 2005 19:30:17 +0530
xml merge duplicate
Please try this stylesheet(XSLT 1.0). It merges same consecutive
elements into one element. I am assuming you will have only element
nodes as children of <info>(or whatever element at this level). I also
enclosed your XML in a <root> tag to make it well formed.

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

<xsl:output method="xml" indent="yes" />

<xsl:template match="/root">
    <xsl:for-each select="*[not(name(preceding-sibling::*[1]) = name())]">
      <xsl:element name="{name()}">
        <xsl:copy-of select="*" />
        <xsl:call-template name="makegroup">
          <xsl:with-param name="name" select="name()" />
          <xsl:with-param name="list" select="following-sibling::*" />

<xsl:template name="makegroup">
  <xsl:param name="name" />
  <xsl:param name="list" />

  <xsl:if test="$name = name($list[1])">
    <xsl:copy-of select="$list[1]/*" />
    <xsl:call-template name="makegroup">
      <xsl:with-param name="name" select="$name" />
      <xsl:with-param name="list" select="$list[position() &gt; 1]" />



On 10/18/05, Annmarie Rubin (anrubin) <anrubin@xxxxxxxxx> wrote:
> Hello list,
> I haven't found this in the archives. I have XML that can contain
> duplicate, consecutive elements with different contents, for example:
> <info>
>      <para>text A </para>
>      <note>note A </note>
>  </info>
>  <info>
>      <para>text B</para>
>      <note>note B</note>
>      <para>text C</para>
>  </info>
> Is there a way to do the following:
> merge the contents of the duplicate elements into a single info element,
> for example:
> <info>
>    <para>text A</para>
>    <note>note A</note>
>    <para>text B</para>
>    <note>note B</note>
>    <para>text C</para>
> </info>
> Thanks,
> Ann Marie

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.