RE: [xsl] Nested Disk tree layout

Subject: RE: [xsl] Nested Disk tree layout
From: Américo Albuquerque <aalbuquerque@xxxxxxxxxxxxxxxx>
Date: Tue, 3 Dec 2002 16:27:11 -0000
Hi.
This is a template that I usualy use when facing similar situations.
 <xsl:template match="/"><!-- this was taken from your code -->
  <html>
   <body>
    <H3>Table of Contents</H3>
    <xsl:apply-templates select="ALL/BYDIRECTORY" mode="toc"/>
   </body>
  </html>
 </xsl:template>
 
 <xsl:template match="L0|L1|L2|L3|L4|L5|L6|L7" mode="toc">
  <xsl:param name="left" select="0"/><!-- starts with zero -->
  <DIV style="padding-left: {$left}em;"><!-- this sets the left -->
   <xsl:value-of select="DIR"/>
   <xsl:if test="not(string-length(@DIR)=0)">
     <xsl:text>&#160; = </xsl:text>
     <xsl:value-of select="SIZE"/>
     <br/>
   </xsl:if>
   <xsl:apply-templates select="L1|L2|L3|L4|L5|L6|L7" mode="toc">
    <xsl:with-param name="left" select="$left + 1"/><!-- and increment
to all children -->
   </xsl:apply-templates>
  </DIV>
 </xsl:template>

Hope that this helps you.


-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of
ed.rolison@xxxxxxxxxxxxxx
Sent: terça-feira, 3 de Dezembro de 2002 12:31
To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] Nested Disk tree layout


Helo, I've currently got a filesystem analysis program which produces
XML output eg. <ALL>
  <TITLE> .... </TITLE>
  <BYDIRECTORY>
   <L0>
     <PATH="some path">
     <SIZE="disk used">
     <L1>
        <PATH="subdirectory">
         <SIZE="disk used">
          <L2>
              .... more stuff down to L7 ...
          </L2>
     </L1>
  </L0>
  </BYDIRECTORY>
  <BYCUSTOMER>
   ...stuff I don't care about at the moment..
  </BYCUSTOMER
</ALL>

The L0 L1 etc. nests down up to 8 levels. I've gotten as far as
modifying a 'TOC' template off microsoft's website to process this into
a useful output:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version
="1.0"> <xsl:output method="html"/> <xsl:template match="text()"/>

<xsl:template match="/">
  <html>
    <body>
      <H3>Table of Contents</H3>
      <xsl:apply-templates select="ALL/BYDIRECTORY" mode="toc"/>
    </body>
  </html>
</xsl:template>

<xsl:template match="L0|L1|L2|L3|L4|L5|L6|L7" mode="toc">
  <DIV STYLE="margin-left:2em">
    <xsl:call-template name="format_table">
      <xsl:with-param name="count">
       <xsl:number count="L1|L2|L3|L4|L5|L6|L7" />
      </xsl:with-param>
    </xsl:call-template>

    <xsl:value-of select="DIR"/>
    <xsl:if test="not ( string-length(@DIR) = 0 )">
        &#160; = <xsl:value-of select="SIZE"/> <br/>
    </xsl:if>
    <xsl:apply-templates select="L1|L2|L3|L4|L5|L6|L7" mode="toc"/>
  </DIV>
</xsl:template>
</xsl:stylesheet>

This produces a rather neatly indented layout, which was _almost_ what I
was trying to re-create. The problem is, that ideally I'd also like to
be able to format it into an HTML table, looking something like this:

/fs001      <total usage>
      /subdir1    <usage of subdir1>
            /another sub      <usage of that other sub>
      /subdir2    <usage in subdir2>

apologies if that formatting doesn't come out right, but basically,
because the data are recursive, the 'L0' nodes are total usage for the
subnodes, and I'd like to lay it out in such a way that makes it easy to
read - which basically means getting the child elements to column
format. My actual aim here, is to get the 'sizes' aligned, based on
recursion depth.

It've tried putting '<TABLE>' directives around the xsl:apply-templates
but this doesn't seem to work. (I haven't figured out why yet, but there
must be a reason). Can anyone offer suggestions? I'd rather avoid having
to make an XSL loop that inserts a load of &nbsp;s to be able to format
it, but my limited experimentation with styles doesn't seem to give me
the desired results.

Is there a nicer template to use, that doesn't require brute force
layouts of the L0 ... L8? (The script which generates this output has a
recursion depth, so in theory this might increase).

Or am I simply going about this the wrong way? Some pointers to
alternatives would be good.


Cheers.
Ed Rolison




CONFIDENTIALITY:
This e-mail and any attachments are confidential and may be privileged.
If you are not a named recipient, please notify the sender immediately
and do not disclose the contents to another person, use it for any
purpose, or store or copy the information in any medium.


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread