Page 1 of 1

XSL: inserting a new element below a sibling

Posted: Mon Apr 04, 2005 3:59 pm
by cbridle
Hi,

I need to be able to insert a new element which will be a sibling an an existing element.

The xml is too large to post but i will provide an exampole for this purpose. The XML structuire would be simular to this:

<task>
<temp>
</temp>
<trial>
</trial>
<floppy>
</floppy>
<spain>
</spain>
</task>

what i need to be able to do is add a new element below the floppy element and above the spain element.

The xsl i have only inserts it immediately below the <task> element.

Thanks for any help.

Posted: Mon Apr 04, 2005 4:01 pm
by cbridle
for some reason the formatting has been affected, the <task> element would be the top level, and the other elements would be children of the <task> element, i'll try again, like this:

<task>
<temp>
</temp>
<trial>
</trial>
<floppy>
</floppy>
<spain>
</spain>
</task>

Posted: Thu Apr 07, 2005 2:05 pm
by george
Hi,

Try something like below:

Code: Select all


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>

<xsl:template match="spain">
<newElement/>
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Regards,
George