Subject: AW: [xsl] Tree from directory listing From: Thomas Zöchling <thomas.zoechling@xxxxxx> Date: Fri, 10 Dec 2004 19:04:28 +0100 |
Thank you! > A 1.0 solution is beyond my concentration powers at this time on a Friday > evening. It was beyond my concentration powers for the past 3 days :) I will experiment with this 2.0 solution. (But it would be cool if someone has already done similar things before in 1.0 and posts his result) Thomas -----Urspr|ngliche Nachricht----- Von: Michael Kay [mailto:mike@xxxxxxxxxxxx] Gesendet: Freitag, 10. Dezember 2004 18:39 An: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Betreff: RE: [xsl] Tree from 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: [xsl] 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Tree from directory listi, Michael Kay | Thread | [xsl] Calculating Sum in XSLT 1.0, Abhijit Junnare |
Re: [xsl] Convert 2 xml with 1 xsl , Marcelo | Date | Re: [xsl] Convert 2 xml with 1 xsl , António Mota |
Month |