This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Handling Directory Trees
- To: XSL-List at lists dot mulberrytech dot com
- Subject: [xsl] Handling Directory Trees
- From: David_Benua at percussion dot com
- Date: Wed, 24 Jan 2001 09:06:28 -0500
- Reply-To: xsl-list at lists dot mulberrytech dot com
We've been searching for an appropriate method to output directory information
as an XML tree. We have a list of file names (with directory paths) for
example:
<file path="/directory1/directory2/file1" />
<file path="/directory1/directory2/file2" />
<file path="/directory1/directory3/file3" />
<file path="/directory4/directory5/file4" />
and we want an XML tree like this:
<rootnode>
<directory name="directory1">
<directory name="directory2">
<file name="file1"/>
<file name="file2"/>
</directory>
<directory name="directory3">
<file name="file3" />
</directory>
</directory>
<directory name="directory4">
<directory name="directory5">
<file name="file4"/>
</directory>
</directory>
</rootnode>
It's pretty easy to parse the file names by recursive descent using
substring-before and substring-after. This produces a tree that looks like
this:
<rootnode>
<directory name="directory1">
<directory name="directory2">
<file name="file1" />
</directory>
</directory>
<directory name="directory1">
<directory name="directory2">
<file name="file2" />
</directory>
</directory>
etc
</rootnode>
I suppose we could produce the desired output by making a second pass through
this output using following-sibling to find unique directory names. but I'd much
rather do this in one pass. I'm looking for any suggestions from anybody who
may have encountered this problem before.
We're doing this in a Servlet based system (and using XT). The data comes from
a relational database, so we can guarantee that the input is in the correct
order. Any thoughts or suggestions, please let me know
Dave
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list