my xml input is-
<?xml version="1.0" encoding="UTF-8"?>
<foo> <bar>bar</bar>
<bar>bar</bar>
<foobar><baz>baz</baz></foobar>
<foobar>foobar</foobar>
<bar>bar</bar>
<bar>bar</bar>
</foo>
Output using xslt should be
<?xml version="1.0" encoding="UTF-8"?>
<foo>
<s>
<s>
<bar>bar</bar>
<bar>bar</bar>
</s>
<s>
<foobar><baz>baz</baz></foobar>
<foobar>foobar></foobar>
</s>
<s>
<bar>bar</bar>
<bar>bar</bar>
</s>
</s>
</foo>
the output should have sequence-of elements inside a parent. Mixed sequence-of elements will be moved inside parents node “s”. the xslt file that is used is-
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:key name="adjacentByName" match="*/*" use="generate-id(preceding-sibling::*[not(name()=name(current()))][1])" />
<xsl:template match="/*">
<foo><s>
<xsl:for-each select="*[generate-id()=generate-id(key('adjacentByName', generate-id(preceding-sibling::*[not(name()=name(current()))][1]))[1])]">
<s>
<xsl:for-each select="key('adjacentByName', generate-id(preceding-sibling::*[not(name()=name(current()))][1]))">
<xsl:copy-of select="."/>
</xsl:for-each>
</s>
</xsl:for-each>
</s></foo>
</xsl:template>
</xsl:stylesheet>
the problem is in output baz element (child element of first foobar element) is with both bar and foobar sequences.
<foo>
<s>
<s>
<bar>bar</bar>
<bar>bar</bar>
**<baz>baz</baz>**
</s>
<s>
<foobar>
<baz>baz</baz>
</foobar>
<foobar>foobar</foobar>
</s>
<s>
<bar>bar</bar>
<bar>bar</bar>
</s>
</s>
</foo>
How can i remove baz element from bar sequences. Many thanks.
How about
With your input of
this produces