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

Building up a hierarchy from a flat structure

Subject: Building up a hierarchy from a flat structure
From: "Wolfgang Schindler" <w.schindler@xxxxxxxxxxxxx>
Date: Wed, 26 Nov 2003 10:02:51 +0100
wolfgang schindler
Dear colleagues,

I have an XML file with a set of entries, each containing a sequence of elements. I have to introduce container elements that group some of these elements together. The A element is intended as a hook where I want to start grouping all the following-siblings so that all following-siblings after a specific A are grouped together as children of A until the next A or the end of the ENTRY is reached. One problem is that I want to keep the sequence of elements as in the original and do not know what elements in which frequency and in what sequence occur in my data, the second problem is that I don't have the A hook at the end of the ENTRY. How would such a procedural logics (start at a certain element to move each following element in turn into a container element until a certain element is reached) be implemented in XSLT?

The sample files have been simplified. In the original the elements are not empty, but contain substructure.

See in.xml (the input) and out.xml(the intended output).

IN.XML: Input file

<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
	<ENTRY>
		<X/>
		<A/>
		<SG/>
		<TG/>
		<TG/>
		<U/>
		<U/>
		<U/>
		<TG/>
		<A/>
		<SG/>
		<TG/>
	</ENTRY>
	<ENTRY>
		<B/>
		<A/>
		<SG/>
		<TG/>
		<SG/>
		<TG/>
		<TG/>
		<TG/>
		<SG/>
		<TG/>
		<A/>
		<SG/>
		<TG/>
	</ENTRY>
	<ENTRY>
		<C/>
		<A/>
		<SG/>
		<U/>
		<SG/>
		<TG/>
		<A/>
		<SG/>
		<U/>
		<U/>
		<U/>
		<U/>
		<U/>
	</ENTRY>
	<ENTRY>
		<Y/>
		<A/>
		<SG/>
		<U/>
		<TG/>
		<U/>
		<TG/>
		<A/>
		<SG/>
		<TG/>
		<TG/>
		<TG/>
	</ENTRY>
	<ENTRY>
		<C/>
		<Z/>
	</ENTRY>
</ROOT>

OUT.XML: Desired Output

<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
	<ENTRY>
		<X/>
		<A>
			<SG/>
			<TG/>
			<TG/>
			<U/>
			<U/>
			<U/>
			<TG/>
		</A>
		<A>
			<SG/>
			<TG/>
		</A>
	</ENTRY>
	<ENTRY>
		<B/>
		<A>
			<SG/>
			<TG/>
			<SG/>
			<TG/>
			<TG/>
			<TG/>
			<SG/>
			<TG/>
		</A>
		<A>
			<SG/>
			<TG/>
		</A>
	</ENTRY>
	<ENTRY>
		<C/>
		<A>
			<SG/>
			<U/>
			<SG/>
			<TG/>
		</A>
		<A>
			<SG/>
			<U/>
			<U/>
			<U/>
			<U/>
			<U/>
		</A>
	</ENTRY>
	<ENTRY>
		<Y/>
		<A>
			<SG/>
			<U/>
			<TG/>
			<U/>
			<TG/>
		</A>
		<A>
			<SG/>
			<TG/>
			<TG/>
			<TG/>
		</A>
	</ENTRY>
	<ENTRY>
		<C/>
		<Z/>
	</ENTRY>
</ROOT>

Many thanks in advance for your patience and your kind assistance!

Best regards
Wolfgang


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.