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