But from your example I can see that probably you do want to do different thing : just use single <info> as a root and collect all children of all <info> elements from original XML under this info. If this is tha case you can use following XSLT:
Subject:merge contents of consecutive duplicate elements Author:Ann Marie Rubin Date:18 Oct 2005 01:54 PM
thanks for the suggestion, Yuriv.
Yes, I want to generate a single element to replace two consecutive info elements that are children of an overview element and have the same name (and concatinate content.) There will be no more than one pair of these info elements in each overview element. I don't want to generate a single element containing all duplicate elements.
For example, this code finds the info element that is a child of an overview element and whose next following sibling is also an info element.
Subject:merge contents of consecutive duplicate elements Author:Ann Marie Rubin Date:18 Oct 2005 09:07 PM
The info elements are still not merged. Can you see what the problem is? Note that I needed to add the <xsl:apply-templates select="@*|node()"/> statement in the match / template or I got no output at all.
Subject:merge contents of consecutive duplicate elements Author:Ann Marie Rubin Date:18 Oct 2005 09:08 PM
The info elements are still not merged. Can you see what the problem is? Note that I needed to add the <xsl:apply-templates select="@*|node()"/> statement in the match / template or I got no output at all.
Subject:merge contents of consecutive duplicate elements Author:(Deleted User) Date:19 Oct 2005 08:22 AM
If your task is to replace all <info> elements located under <overview> element with a single <info> element and concatinate children under this new <info> and you want to do this in cases a) and b) :
a) <overview>
<info/>
<other/>
<info/>
</overview>
and
b)
<overview>
<info/>
<info/>
<other/>
</overview>
There are overview elements in other parts of the tree that don't want to change. I want to combine info element children of concept/overview with the info element that is the immediately following sibling of overview in a single info element.
Subject:merge contents of consecutive duplicate elements Author:Ann Marie Rubin Date:20 Oct 2005 10:08 PM
thanks Ivan.
I need to merge the duplicate info elements under overview children of concept but not other info elements. See my reply to Yuriv. I'm going to try out this stylesheet and see if I can modify it to merge the info child of concept/overview with overview's following sibling info node.
that's the problem I need to solve now.
If you have any suggestions, I would greatly appreciate it.
We can modify Ivan template to handle this case too, so you'll get original tree with info elements merged, not just sample case. But let's make sure first that we understand requirements correctly.
If you will post complete input XML with all possible cases and desired output XML we will try to come up with stylesheet.
Subject:merge contents of consecutive duplicate elements Author:Ann Marie Rubin Date:27 Oct 2005 01:02 PM
Hello Yuriy,
Sorry for the delay. I am attaching the input xml and desired output xml. I only want to merge the contents of subconcept/overview/info and the following-sibling info element of subconcept/overview. There are overview/info elements that are children of other elements, such as, minitask, that should be left alone.
Let me know if you have any questions about the requirements.
Subject:merge contents of consecutive duplicate elements Author:Ann Marie Rubin Date:27 Oct 2005 01:12 PM
Hello Yuriy,
Sorry for the delay. I am attaching the input xml and desired output xml. I want to remove overview children of subconcept and merge the contents of subconcept/overview/info and the following-sibling info element of subconcept/overview. There are overview/info elements that are children of other elements, such as, minitask, that should be left alone.
For example, the following input:
<subconcept id="_8">
<title>concept</title>
<overview>
<info>
<para>para A</para>
</info>
</overview>
<info>
<para>para B</para>
</info>
</subconcept>
should be changed to:
<subconcept id="_8">
<title>subconcept</title>
<info>
<para>para 1</para>
<para>para 2</para>
</info>
</subconcept>
Let me know if you have any questions about the requirements.
2 <info> tags replaced with single <info>
all <info> children are merged (<para>)
and all this happens only if <overview> is direct child of <subconcept>