Re: [xsl] XSLT/SVG variables question

Subject: Re: [xsl] XSLT/SVG variables question
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 1 Jul 2002 10:11:55 +0100
Hi Harry,

> As the block chart is built, I need to account for arbitrary number
> of strings per block and number of blocks. "Normal" variables would
> let me compute and increment SVG coordinates for the rectangles and
> text. But XSLT variables aren't normal!
>
> If you have any suggestions about how I should track the
> coordinates, or better yet an example, that would be helpful.

There are two ways of working that might help here.

The first is to express the algorithm by which you decide where the
blocks should be and how large they should be in terms of the
information that you have about the other blocks. For example, if you
know that each block is 100 units across and 100 units from the
preceding block, then you can work out the location of this block by
counting the number of preceding blocks and multiplying by 200 units.

The trouble is that this method often leads to you revisiting nodes
and recalculating things like widths and heights for all the preceding
blocks for any particular block, and that's not very efficient when
you have lots of blocks to arrange.

The alternative, then, is to control the order of processing of the
blocks and use parameters to keep track of the things that you would
otherwise hold within variables. For example, you could have a
template like:

<xsl:template name="layout">
  <xsl:param name="blocks" select="BlockA | BlockB" />
  <xsl:param name="x" select="0" />
  <xsl:param name="y" select="0" />

  <xsl:variable name="block" select="$blocks[1]" />

  ... various layout stuff to create SVG from $block ...

  <xsl:if test="$blocks[2]">
    <xsl:call-template name="layout">
      <xsl:with-param name="blocks" select="$blocks[position() > 1]" />
      <xsl:with-param name="x" select="$newX" />
      <xsl:with-param name="y" select="$newY" />
    </xsl:call-template>
  </xsl:if>
</xsl:template>

Here, the parameters $x and $y are updated as you work through the
blocks one by one, until there are no blocks left, so you get a more
procedural style of programming.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


Current Thread