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(_at_)saxonica(_dot_)com]
Gesendet: Freitag, 10. Dezember 2004 18:39
An: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
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 Zöchling [mailto:thomas(_dot_)zoechling(_at_)gmx(_dot_)at]
Sent: 10 December 2004 17:04
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
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?
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--