[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Positional Grouping Problem - Add hierarchy to a flat
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|