cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marco Pöhler <mpoeh...@eprofessional.de>
Subject XSL variable scope question
Date Mon, 14 Aug 2000 09:48:33 GMT
Hi,

i try to transform a xsp:sql resultset to a simple bar-chart. I need to
scale the values from the query to the maximum height of the bar chart. I
think i need the maximum value existing in the resultset in every output
element to calculate the real height. I have a problem finding this maximum
value, and i think it is a problem of variable scope. 

The test in the loop header seems to use $maxvisits=0, in the loop-body the
$maxvists are OK. If there is any other solution to produce barcharts or
charts in general.

my (xsp-based) resultset:
---snip---
<query countrows="2">
	<row rowpos="0">
		<name>Regaflexinfo</name>
		<visits>2</visits>
	</row>
	<row rowpos="1">
		<name>Shop</name>
		<visits>93</visits>
	</row>
	<row rowpos="2">
		<name>info</name>
		<visits>74</visits>
	</row>
</query>
---snap--- 

my stylesheet:
---snip---
	<xsl:template match="row">
		<xsl:element name="svg:rect"
xmlns:svg="http://www.w3.org/Graphics/SVG/SVG-19990812.dtd">
			<xsl:attribute name="x"><xsl:value-of
select="number(./@rowpos)*round(360 div (../@countrows + 1))+20"
/>pt</xsl:attribute>
			<xsl:attribute name="width"><xsl:value-of
select="round(240 div (../@countrows + 1))" />pt</xsl:attribute>
			<!-- These attributes must be calculated, too -->
			<xsl:attribute name="height"><xsl:value-of
select="./visits" />pt</xsl:attribute>
			<xsl:attribute name="y"><xsl:value-of
select="$maxvisits"/></xsl:attribute>
		</xsl:element>
	</xsl:template>

	<xsl:template match="query">
		<xsl:variable name="maxvisits">0</xsl:variable>		
		<xsl:for-each select="./row">
			 view visits=<xsl:value-of select="visits" />
			 view maxvisits=<xsl:value-of select="$maxvisits" />
			<xsl:if test="number(visits)>number($maxvisits)">
				<!-- set the new maxvisits -->
				<xsl:variable
name="$maxvisits"><xsl:value-of select="visits" /></xsl:variable>
				entering loop-body: maxvisits =
<xsl:value-of select="$maxvisits" />
			</xsl:if>
		</xsl:for-each>
		<xsl:apply-templates>
			<xsl:with-param name="maxvisits"><xsl:value-of
select="$maxvisits" /></xsl:with-param>
		</xsl:apply-templates>
	</xsl:template>
---snap---

tia

Marco Pöhler
eprofessional GmbH
Friedensallee 50, 22765 Hamburg, GERMANY
fon: +49 (0)40 399 278-25, fax: +49 (0)40 399 278-78
http://www.eprofessional.de , http://www.eprofessional.net



Mime
View raw message