Shifting nodes in an XML using XSLT

Here should go questions about transforming XML with XSLT and FOP.
Hosch
Posts: 1
Joined: Sun Nov 11, 2012 5:40 pm

Shifting nodes in an XML using XSLT

Post by Hosch »

Hi guys,

I have an XML with following structure

<root>
<header>
<line>
<line>
<line>
<subline>
<subline>
<subline>
<root>


how can I transform the above xml to the following structure using XSLT?
<root>
<line>
<subline>
<line>
<subline>
<line>
<subline>

each line is connected with the appropriate subline using a tag id

Thanks in advance for your support.
lorela
Posts: 1
Joined: Tue Nov 20, 2012 11:41 am

Re: Shifting nodes in an XML using XSLT

Post by lorela »

Hi,
You can use :

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>

<xsl:template match="/root">
<xsl:copy>
<xsl:apply-templates select="line | subline">
<xsl:sort select="id"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>
Regards,
Lorela
Lorela Stanescu
oXygen XML Editor and Author Support
Post Reply