New to xsl / xml - reorder issue
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 2
- Joined: Wed Jan 31, 2007 8:50 am
- Contact:
New to xsl / xml - reorder issue
Hello all,
I am new to xml and xsl and am trying to reorder elements in an xml file to be output as an xml file that is being placed into Adobe InDesign.
My xml file to be reordered is written as such:
My xsl that I wrote looks like this:
What I get is this:
What I would like is this:
I would appreciate any advise.
I am new to xml and xsl and am trying to reorder elements in an xml file to be output as an xml file that is being placed into Adobe InDesign.
My xml file to be reordered is written as such:
Code: Select all
<advertisement>
<tester>
<three>Coloumn three</three>
<one>Column one</one>
<two>Column two</two>
</tester>
<tester>
<three>Second Coloumn three</three>
<one>Second Column one</one>
<two>Second Column two</two>
</tester>
<tester>
<three>Third Coloumn three</three>
<one>Third Column one</one>
<two>Third Column two</two>
</tester>
<tester>
<three>Fourth Coloumn three</three>
<one>Fourth Column one</one>
<two>Fourth Column two</two>
</tester>
<tester>
<three>Fifth Coloumn three</three>
<one>Fifth Column one</one>
<two>Fifth Column two</two>
</tester>
<tester>
<three>Sixth Coloumn three</three>
<one>Sixth Column one</one>
<two>Sixth Column two</two>
</tester>
</advertisement>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:element name="advertisement">
<xsl:element name="tester">
<!--Rearrange the order of the elements-->
<xsl:copy-of select="advertisement/tester/one"/>
<xsl:copy-of select="advertisement/tester/two"/>
<xsl:copy-of select="advertisement/tester/three"/>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Code: Select all
<?xml version="1.0" encoding="UTF-16"?>
<advertisement>
<tester>
<one>Column one</one>
<one>Second Column one</one>
<one>Third Column one</one>
<one>Fourth Column one</one>
<one>Fifth Column one</one>
<one>Sixth Column one</one>
<two>Column two</two>
<two>Second Column two</two>
<two>Third Column two</two>
<two>Fourth Column two</two>
<two>Fifth two</two>
<two>Sixth Column two</two>
<three>Coloumn three</three>
<three>Second Coloumn three</three>
<three>Third Coloumn three</three>
<three>Fourth Coloumn three</three>
<three>Fifth three</three>
<three>Sixth Coloumn three</three>
</tester>
</advertisement>
Code: Select all
<advertisement>
<tester>
<one>Column one</one>
<two>Column two</two>
<three>Coloumn three</three>
</tester>
<tester>
<one>Second Column one</one>
<two>Second Column two</two>
<three>Second Coloumn three</three>
</tester>
<tester>
<one>Third Column one</one>
<two>Third Column two</two>
<three>Third Coloumn three</three>
</tester>
<tester>
<one>Fourth Column one</one>
<two>Fourth Column two</two>
<three>Fourth Coloumn three</three>
</tester>
<tester>
<one>Fifth Column one</one>
<two>Fifth Column two</two>
<three>Fifth Coloumn three</three>
</tester>
<tester>
<one>Sixth Column one</one>
<two>Sixth Column two</two>
<three>Sixth Coloumn three</three>
</tester>
</advertisement>
I would appreciate any advise.
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi,
I would do this with a modified recursive copy stylesheet as below
Regards,
George
I would do this with a modified recursive copy stylesheet as below
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="tester">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="one"/>
<xsl:apply-templates select="two"/>
<xsl:apply-templates select="three"/>
<xsl:apply-templates select="node()[not(self::one or self::two or self::three)]"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
George
George Cristian Bina
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service