After a day's research into XSLT, I am admitting defeat!
This is my input:
<div class="a" >
<div class="b">b1</div>
<div class="c">b1c1</div>
<div class="d">b1d1</div>
<div class="d">b1d2</div>
<div class="b">b2</div>
<div class="c">b2c1</div>
<div class="d">b2d1</div>
<div class="d">b2d2</div>
<div class="d">b2d3</div>
<div class="b">b3</div>
<div class="c">b3c1</div>
<div class="d">b3d1</div>
</div>
And this is the output I would like to get:
<div class="a" >
<div class="b">b1
<div class="c">b1c1</div>
<div class="d">b1d1</div>
<div class="d">b1d2</div>
</div>
<div class="b">b2
<div class="c">b2c1</div>
<div class="d">b2d1</div>
<div class="d">b2d2</div>
<div class="d">b2d3</div>
</div>
<div class="b">b3
<div class="c">b3c1</div>
<div class="d">b3d1</div>
</div>
</div>
This is the xslt that I am using:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- Identity template, copies everything as is -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- Override for target element -->
<xsl:template match="div[@class='a']">
<!-- Copy the element -->
<xsl:copy>
<!-- And everything inside it -->
<xsl:copy-of select="@*|node()"/>
<!-- Move nodes -->
<xsl:apply-templates select="div[@class='c']"/>
<xsl:apply-templates select="div[@class='d']"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
But it's giving me the wrong output:
<div class="a">
<div class="b">b1</div>
<div class="c">b1c1</div>
<div class="d">b1d1</div>
<div class="d">b1d2</div>
<div class="b">b2</div>
<div class="c">b2c1</div>
<div class="d">b2d1</div>
<div class="d">b2d2</div>
<div class="d">b2d3</div>
<div class="b">b3</div>
<div class="c">b3c1</div>
<div class="d">b3d1</div>
<div class="c">b1c1</div>
<div class="c">b2c1</div>
<div class="c">b3c1</div>
<div class="d">b1d1</div>
<div class="d">b1d2</div>
<div class="d">b2d1</div>
<div class="d">b2d2</div>
<div class="d">b2d3</div>
<div class="d">b3d1</div>
</div>
I understand why it's giving me this output, but I cannot find a way to modify it and get the correct output.
Thank you in advance.
PullingHair