Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] XSLT/SVG variables question

From: Jeni Tennison <jeni@---------------->
To:
Date: 7/1/2002 1:11:00 AM
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


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent