[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Handling Directory Trees
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
|
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
|