I’m new to XSLT, and am having problems merging node lists. Would appreciate your help with the following scenario:
Input:
> <A Id="1"> > <B Id="4"> > <Attr> > <someAttr1>2</someAttr1> > <someAttr2>1</someAttr2> > </Attr> > <C Id="7"> > <Attr> > <someAttr3>2</someAttr3> > <someAttr4>1</someAttr4> > <someAttr5>7</someAttr5> > </Attr> > </C> > </B> > <B Id="9"> > <Attr> > <someAttr1>6</someAttr1> > <someAttr2>0</someAttr2> > </Attr> > <C Id="11"> > <Attr> > <someAttr3>1</someAttr3> > <someAttr4>3</someAttr4> > <someAttr5>5</someAttr5> > </Attr> > </C> > </B> > </A>
Output:
<A Id="1"> <B Id="4"> <Attr> <someAttr1>2</someAttr1> <someAttr2>1</someAttr2> <someAttr3>2</someAttr3> <someAttr4>1</someAttr4> <someAttr5>7</someAttr5> </Attr> </B> <B Id="9"> <Attr> <someAttr1>6</someAttr1> <someAttr2>0</someAttr2> <someAttr3>1</someAttr3> <someAttr4>3</someAttr4> <someAttr5>5</someAttr5> </Attr> </B> </A>
It looks like you want to combine all Attr elements that occur at any level under a B element.
First, you would need a template to match B elements with Attr elements
And in the template, you would create an Attr element, and copy all descendant elements under the Attr elements
Here is the full XSLT
When applied to your sample XML, the following is output