[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Flattening hierarchic xml, retaining some structur

Subject: Re: Flattening hierarchic xml, retaining some structure
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Wed, 19 Jan 2005 18:30:28 +0100
corporate flattening
Tempore 15:56:08, die 01/19/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Ragulf Pickaxe <jawxml@xxxxxxxxxxx>:

I have a hierarchic structure, that I would like to flatten.
I have tried looking for some examples, but I have not been able to expand the examples I have found, so that they will work on my problem.
Hi,

The followng stylesheet will do the job when applied to the sample XML. It most likely needs some modification to fit the real XML.

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


<xsl:output method="xml" indent="yes"/>

<xsl:template match="mynode">
<xsl:apply-templates select="*[not(child::mynode)][position()=1 or preceding-sibling::*[1]/child::mynode]" mode="encapsule"/>
<xsl:apply-templates select="../following::*[1]/mynode"/>
</xsl:template>


<xsl:template match="mynode/*" mode="encapsule">
	<mynode>
		<xsl:copy-of select="../@*"/>
		<xsl:apply-templates select="." mode="list"/>
	</mynode>
	<xsl:apply-templates select="(following-sibling::*/mynode)[1]"/>
</xsl:template>

<xsl:template match="mynode/*" mode="list">
<xsl:copy-of select="."/>
<xsl:apply-templates select="following-sibling::*[1][not(child::mynode)]" mode="list"/>
</xsl:template>


</xsl:stylesheet>


regards, -- Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041) "Et ipsa scientia potestas est" - Francis Bacon , Meditationes sacrae

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.