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

Positional Grouping Problem - Add hierarchy to a flat

Subject: Positional Grouping Problem - Add hierarchy to a flat structure
From: Tom Chmielenski <Tom.Chmielenski@xxxxxxxxxxx>
Date: Tue, 1 Jul 2003 16:57:53 -0400
chmielenski
I currently have an xml file (a series of sequential statements printf'ed)
that looks like this (simplified example):

<LogFile>
    <BeginFile lineNum="1" fileName="file1.txt"/>
    <ElementA lineNum="2"/>
    <ElementB lineNum="3"/>
    <ElementC lineNum="4"/>
    <BeginFile lineNum="6" fileName="file2.txt"/>
    <ElementA lineNum="7"/>
    <ElementB lineNum="8"/>
    <BeginFile lineNum="9" fileName="file2b.txt"/>
    <ElementA lineNum="10"/>
    <ElementB lineNum="11"/>
    <EndFile lineNum="12" fileName="file2b.txt"/>
    <ElementA lineNum="13"/>
    <ElementB lineNum="14"/>
    <ElementC lineNum="15"/>
    <EndFile lineNum="16" fileName="file1.txt"/>
</LogFile>

And would like to transform it to look like this:
<LogFile>
    <File lineNum="1" fileName="file1.txt"/>
	<ElementA lineNum="2"/>
	<ElementB lineNum="3"/>
	<ElementC lineNum="4"/>
	<File lineNum="6" fileName="file2.txt"/>
	    <ElementA lineNum="7"/>
	    <ElementB lineNum="8"/>
	    <File lineNum="9" fileName="file2b.txt"/>
		<ElementA lineNum="10"/>
		<ElementB lineNum="11"/>
	    </File>
	<ElementA lineNum="13"/>
	<ElementB lineNum="14"/>
	<ElementC lineNum="15"/>
    </File>
</LogFile>

Basically, I want to replace the <BeginFile> node, with a <File> node.
And then copy all elements between <BeginFile file="x"> and its
corresponding <EndFile file="x"> as subelements to this new <File> node.
Nesting <File> nodes if a second <BeginFile> node is found before the
corresponding <EndFile> node is found. For each <BeginFile file="x"/>, there
will always be a corresponding <EndFile file="x"/> element. And the LineNum
attribute is not that important, but are in the original document, are
valid, and can be used in the solution.

I think the solution should be simple, but I am having a brain freeze.
It is similar to this:
	http://www.dpawson.co.uk/xsl/sect2/N4486.html#d4110e229
But the hierarchy <File> nodes and the intermediate <ElementXX> nodes are
confusing me.

Any help is appreciated.
Tx in Advance.
Tom

 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.