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

RE: Tree from directory listing

Subject: RE: Tree from directory listing
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 10 Dec 2004 17:39:24 -0000
xsl directory listing
It's essentially a recursive grouping problem. (Yes, I have seen these
before!) In XSLT 2.0 you can solve it like this:

<xsl:template name="g">
  <xsl:param name="files" as="element(file)*"/>
  <xsl:param name="level" as="xs:integer"/>
  <xsl:for-each-group select="$files"
     group-adjacent="tokenize(@path, '/')[$level]">
   <folder name="current-grouping-key()">
     <xsl:call-template name="g">
       <xsl:with-param name="files" select="current-group() except ."/>
       <xsl:with-param name="level" select="$level + 1"/>
     </xsl:call-template>
   </folder>
  </xsl:for-each-group>
</xsl:template>

I haven't tried to distinguish folders from files here, I leave that as an
exercise for the reader (perhaps best done in a second pass).

A 1.0 solution is beyond my concentration powers at this time on a Friday
evening.

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: Thomas Zvchling [mailto:thomas.zoechling@xxxxxx]
> Sent: 10 December 2004 17:04
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Tree from directory listing
>
> Hi list!
>
> Does someone know a method to create a nested xml Tree
> structure from file
> listing with paths?
>
> eg.
> ...
> <file name ="f1.xyz" path="/test/"/>
> <file name ="f2.xyz" path="/test/folderInFolder/"/>
> <file name ="f3.xyz" path="/test/folderInFolder/"/>
> <file name ="f4.xyz" path="/test/folderInFolder2/"/>
> <file name ="f5.xyz" path="/test2/folderInFolder3/"/>
> ...
>
> to
>
> <folder name="test">
>     <folder name="folderInFolder">
>         <file name="f2.xyz"/>
>         <file name="f3.xyz"/>
>     </folder
>     <folder name="folderInFolder2">
>         <file name="f4.xyz"/>
>     </folder
> <folder name ="test">
>     <folder name="folderInFolder3">
>         <file name="f5.xyz">
>     </folder>
> </folder>
>
> Maybe anyone solved a similar problem?

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.