You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by João César <jo...@duploclique.com> on 2003/05/11 12:36:43 UTC

Preparing data to SVG...

Hi again :)

I'm doing some reports, and I want to put a nice histogram on it. It's working fine but the SVG is using static values.. So I want to transform the SVG data to draw the bars based on another XML information... for instance:


<xsl:variable name="XLocation">100</xsl:variable>   
<xsl:for-each select="/report/data">   

        <!-- the X value is the variable value -->
        <rect x="number($XLocation)" y="360" width="100" height="100" fill="yellow" stroke="navy" stroke-width="1" />

        <!-- this would work as an incrementation -->
        <xsl:variable name="XLocation">
               <xsl:value-of select="number($XLocation) + number(100)"/>
        </xsl:variable>                                           

</xsl:for-each>


Problems:

#1 - I can't get the variable name inside de <rect> tag :| Instead I get the string uninterpreted as output

#2 - The variable $XLocation loses scope and it's value is not preserved in the <for-each> iterations. (The increment code is working altought)

How can I fix this ? 

Many thanks in advance

Joao Cesar
joaocesar@duploclique.com

Computer Science Student @ Universidade de Lisboa, PORTUGAL

Re: Preparing data to SVG...

Posted by Antonio Gallardo <ag...@agsoftware.dnsalias.com>.
João César dijo:


> Hi again :)
>
> I'm doing some reports, and I want to put a nice histogram on it. It's
> working fine but the SVG is using static values.. So I want to transform
> the SVG data to draw the bars based on another XML information...

Try to use Fins. It is a very nice chart generation tool for Cocoon. More
info at: http://cocoondev.org/projects/fins.html

Best Regards,

Antonio Gallardo



---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org


Re: Preparing data to SVG...

Posted by Andrew Savory <an...@luminas.co.uk>.
Hi,

On Sun, 11 May 2003, João César wrote:

> Perhaps could you guys recommend a XSL book that covers both newbie aspects
> and advanced programming ?

No book recommendations, but the following links have been invaluable to
me:

	http://www.dpawson.co.uk/
	(in particular http://www.dpawson.co.uk/xsl/sect2/sect21.html)
	http://www.jenitennison.com/xslt/index.html
	http://www.topxml.com/library/default.asp

Hope that helps!

Andrew.

-- 
Andrew Savory                                Email: andrew@luminas.co.uk
Managing Director                              Tel:  +44 (0)870 741 6658
Luminas Internet Applications                  Fax:  +44 (0)700 598 1135
This is not an official statement or order.    Web:    www.luminas.co.uk

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org


Re: Preparing data to SVG...

Posted by "J.Pietschmann" <j3...@yahoo.de>.
João César wrote:
> Everything is working now but we have another dummy "problem"
> 
> We don't have much flexibility with XSL and we don't how to transform this:
> 
> <report >
>       <date>2002</date>
>       <date>2002</date>
>       <date>2001</date>
>       <date>2001</date>
> </report>
> 
> to this :
> 
> <report>
>         <date count="2">2002</date>
>         <date count="2">2001</date>
> </report>

That's a standard grouping problem. See the XSL FAQ reachable
from
    http://www.mulberrytech.com/xsl/xsl-list
or Jeni's XSLT pages
    http://www.jenitennison.com/xslt/grouping/index.html
and ask on the XSL list for further advice.

J.Pietschmann


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org


Re: Preparing data to SVG...

Posted by João César <jo...@duploclique.com>.
Everything is working now but we have another dummy "problem"

We don't have much flexibility with XSL and we don't how to transform this:

<report >
      <date>2002</date>
      <date>2002</date>
      <date>2001</date>
      <date>2001</date>
</report>

to this :

<report>
        <date count="2">2002</date>
        <date count="2">2001</date>
</report>

Because we want to send the count value to the graph...

Perhaps could you guys recommend a XSL book that covers both newbie aspects
and advanced programming ?

Thanks

Joao Cesar
joaocesar@duploclique.com

Computer Science Student @ Universidade de Lisboa, PORTUGAL

----- Original Message ----- 
From: "Conal Tuohy" <co...@paradise.net.nz>
To: <co...@xml.apache.org>
Sent: Sunday, May 11, 2003 1:06 PM
Subject: RE: Preparing data to SVG...


> João maybe I've misunderstood what you're trying to do, but you can't EVER
> modify the value of an xsl:variable. It is like a "final" variable in
Java.
>
> By the way, you ought to ask XSLT questions on the Mulberrytech XSL mail
> list - you'll usually get a much better response there.
> http://www.mulberrytech.com/xsl/xsl-list
>
> Although you can't change a value, you can "shadow" it by defining another
> variable with the same name, in a smaller scope. In your example the first
> xsl:variable binds the name "XLocation" to the value "100", within the
scope
> of the element which encloses that xsl:variable. The second xsl:variable
> hides the first variable by binding the the name "XLocation" to the value
> "200" within the scope of the second xsl:variable, which is (as you know)
> everything INSIDE the xsl:for-each element. Outside of that xsl:for-each
> loop only the FIRST variable is in scope, which still has the value 100.
See
> http://www.w3.org/TR/xslt#dt-shadows for more on shadowing and variable
> scope in XSLT.
>
> So if you want to increment a variable in this way, you have to have to
use
> a new scope each time you increment, and another, and another ... in other
> words, you would have to use recursion.
>
> Alternatively, more simply, you can use multiplication :-)
>
> E.g. inside your for-each, use <xsl:variable name="XLocation"
> select="100*position()"/>. See the example in the XSLT spec:
> http://www.w3.org/TR/xslt#number where they use the position() function
> inside xsl:for-each.
>
> By the way, you are missing the curly brackets { } inside the rect/@x
> attribute - you need to evaluate this expression as an expression - you
> don't want the x attribute to be literally "number($XLocation)" do you?
:-)
> Presumably you will have y="{y}" or something too, instead of y="360".
>
> Con
>
>
>  -----Original Message-----
> From: João César [mailto:joaocesar@duploclique.com]
> Sent: Sunday, 11 May 2003 22:37
> To: cocoon-users@xml.apache.org
> Subject: Preparing data to SVG...
>
>
> Hi again :)
>
> I'm doing some reports, and I want to put a nice histogram on it. It's
> working fine but the SVG is using static values.. So I want to transform
the
> SVG data to draw the bars based on another XML information... for
instance:
>
>
> <xsl:variable name="XLocation">100</xsl:variable>
> <xsl:for-each select="/report/data">
>
>         <!-- the X value is the variable value -->
>         <rect x="number($XLocation)" y="360" width="100" height="100"
> fill="yellow" stroke="navy" stroke-width="1" />
>
>         <!-- this would work as an incrementation -->
>         <xsl:variable name="XLocation">
>                <xsl:value-of select="number($XLocation) + number(100)"/>
>         </xsl:variable>
>
> </xsl:for-each>
>
>
> Problems:
>
> #1 - I can't get the variable name inside de <rect> tag :| Instead I get
the
> string uninterpreted as output
>
> #2 - The variable $XLocation loses scope and it's value is not preserved
in
> the <for-each> iterations. (The increment code is working altought)
>
> How can I fix this ?
>
> Many thanks in advance
>
> Joao Cesar
> joaocesar@duploclique.com
>
> Computer Science Student @ Universidade de Lisboa, PORTUGAL
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: cocoon-users-help@xml.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org


RE: Preparing data to SVG...

Posted by Conal Tuohy <co...@paradise.net.nz>.
João maybe I've misunderstood what you're trying to do, but you can't EVER
modify the value of an xsl:variable. It is like a "final" variable in Java.

By the way, you ought to ask XSLT questions on the Mulberrytech XSL mail
list - you'll usually get a much better response there.
http://www.mulberrytech.com/xsl/xsl-list

Although you can't change a value, you can "shadow" it by defining another
variable with the same name, in a smaller scope. In your example the first
xsl:variable binds the name "XLocation" to the value "100", within the scope
of the element which encloses that xsl:variable. The second xsl:variable
hides the first variable by binding the the name "XLocation" to the value
"200" within the scope of the second xsl:variable, which is (as you know)
everything INSIDE the xsl:for-each element. Outside of that xsl:for-each
loop only the FIRST variable is in scope, which still has the value 100. See
http://www.w3.org/TR/xslt#dt-shadows for more on shadowing and variable
scope in XSLT.

So if you want to increment a variable in this way, you have to have to use
a new scope each time you increment, and another, and another ... in other
words, you would have to use recursion.

Alternatively, more simply, you can use multiplication :-)

E.g. inside your for-each, use <xsl:variable name="XLocation"
select="100*position()"/>. See the example in the XSLT spec:
http://www.w3.org/TR/xslt#number where they use the position() function
inside xsl:for-each.

By the way, you are missing the curly brackets { } inside the rect/@x
attribute - you need to evaluate this expression as an expression - you
don't want the x attribute to be literally "number($XLocation)" do you? :-)
Presumably you will have y="{y}" or something too, instead of y="360".

Con


 -----Original Message-----
From: João César [mailto:joaocesar@duploclique.com]
Sent: Sunday, 11 May 2003 22:37
To: cocoon-users@xml.apache.org
Subject: Preparing data to SVG...


Hi again :)

I'm doing some reports, and I want to put a nice histogram on it. It's
working fine but the SVG is using static values.. So I want to transform the
SVG data to draw the bars based on another XML information... for instance:


<xsl:variable name="XLocation">100</xsl:variable>
<xsl:for-each select="/report/data">

        <!-- the X value is the variable value -->
        <rect x="number($XLocation)" y="360" width="100" height="100"
fill="yellow" stroke="navy" stroke-width="1" />

        <!-- this would work as an incrementation -->
        <xsl:variable name="XLocation">
               <xsl:value-of select="number($XLocation) + number(100)"/>
        </xsl:variable>

</xsl:for-each>


Problems:

#1 - I can't get the variable name inside de <rect> tag :| Instead I get the
string uninterpreted as output

#2 - The variable $XLocation loses scope and it's value is not preserved in
the <for-each> iterations. (The increment code is working altought)

How can I fix this ?

Many thanks in advance

Joao Cesar
joaocesar@duploclique.com

Computer Science Student @ Universidade de Lisboa, PORTUGAL


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org