<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns="http://www.w3.org/Graphics/SVG/SVG-19990812.dtd">
<xsl:output method="xml" indent="yes"/>

<xsl:variable name='width' select='800'/>
<xsl:variable name='height' select='600'/>
<xsl:variable name='lines' select='60'/>

<xsl:variable name='lineheight' select='$height div $lines'/>
<xsl:variable name='sizekb' select='number(/mapfs/filesystem/@fragsize)'/>
<xsl:variable name='linekb' select='number(/mapfs/filesystem/@size) div $lines'/>
<xsl:variable name='pixelkb' select='$linekb div $width'/>

<xsl:template match="/mapfs">
  <svg width="{$width}" height="{$height}">
    <rect width="{$width}" height="{$height}"
	style="fill:rgb(0,0,255);stroke-width:1;stroke:rgb(0,0,0)"/>
    <xsl:apply-templates select="file"/>
    <text x="{10}" y="{30}" style="font-size:16px;fill:rgb(255,255,255)">
      <xsl:value-of select="count(./file)"/>
      <xsl:text> files, </xsl:text>
      <xsl:value-of select="sum(.//blk/@nb)"/>
      <xsl:text> blocks, </xsl:text>
      <xsl:value-of select="count(.//blk)"/>
      <xsl:text> contiguous</xsl:text>
    </text>
  </svg>
</xsl:template>
<xsl:template match="file">
  <xsl:apply-templates select="blk"/>
</xsl:template>
<xsl:template match="blk">
  <xsl:variable name='startx' select='floor((number(@start) mod $linekb) div $pixelkb)'/>
  <xsl:variable name='starty' select='floor(number(@start) div $linekb) * $lineheight'/>
  <xsl:variable name='xlen1' select='ceiling(number(@nb) div $pixelkb)'/>
  <rect x="{$startx}" y="{$starty}" width="{$xlen1}" height="{$lineheight}"
      style="fill:rgb(255,0,0)"/>
</xsl:template>
</xsl:stylesheet>
