[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: most efficient flat file listing to hierarchical
Hi James,
I assume the files are those items that do not have further content. My take will be something like below. I believe there is still some room for optimizing the identification of a file. <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output indent="yes"/> <xsl:template match="listing"> <dir> <xsl:call-template name="group"> <xsl:with-param name="items" select="./item"/> </xsl:call-template> </dir> </xsl:template> <xsl:template name="group"> <xsl:param name="items" select="/.."/> <xsl:param name="base" select="''"/> <xsl:for-each select="$items[not(contains(substring-after(., $base), '/'))]"> <xsl:if test="not($items[current()!=. and contains(., current())])"> <file name="{substring-after(., $base)}"/> </xsl:if> </xsl:for-each> <xsl:for-each-group select="$items[contains(substring-after(., $base), '/')]" group-adjacent="substring-before(substring-after(., $base), '/')" > <xsl:sort select="."/> <xsl:variable name="folder" select="substring-before(substring-after(current-group()[1], $base), '/')"/> <dir name="{$folder}"> <xsl:call-template name="group"> <xsl:with-param name="items" select="current-group()"/> <xsl:with-param name="base" select="concat($base, $folder, '/')"/> </xsl:call-template> </dir> </xsl:for-each-group> </xsl:template> </xsl:stylesheet> Best Regards, George --------------------------------------------------------------------- George Cristian Bina <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger http://www.oxygenxml.com James Fuller wrote: Hello All,
|
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
|