I need to move the element "two" inside "six" without its descendant element "four". Also I'm not using identity transformation, only using mode to move the element.
Please tell me you suggestions.
input xml:
Code:
<one>aaa
<two>bbb<three>ccc</three><four>ddd</four></two>
<five>eee</five>
<six>fff</six>
</one>
current output:
Code:
<first>aaa
<fourth>ddd</fourth>
<fifth>eee</fifth>
<sixth>
<second>bbb<third>ccc</third>
<fourth>ddd</fourth>
</second>fff</sixth>
</first>
expected output xml:
Code:
<first>aaa
<fourth>ddd</fourth>
<fifth>eee</fifth>
<sixth><second>bbb<third>ccc</third></second>fff</sixth>
</first>
xslt:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:template match="one">
<first>
<xsl:apply-templates/>
</first>
</xsl:template>
<xsl:template match="two">
<xsl:apply-templates select="descendant::four"/>
</xsl:template>
<xsl:template match="two" mode="move">
<second>
<xsl:apply-templates/>
</second>
</xsl:template>
<xsl:template match="three">
<third>
<xsl:apply-templates/>
</third>
</xsl:template>
<xsl:template match="four">
<fourth>
<xsl:apply-templates/>
</fourth>
</xsl:template>
<xsl:template match="four" mode="move"/>
<xsl:template match="five">
<fifth>
<xsl:apply-templates/>
</fifth>
</xsl:template>
<xsl:template match="six">
<sixth>
<xsl:apply-templates select="preceding::two" mode="move"/>
<xsl:apply-templates/>
</sixth>
</xsl:template>
</xsl:stylesheet>
Regards
Priyan