[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Line SVG charts via XSLT

Subject: Re: Line SVG charts via XSLT
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 06 Jul 2001 11:42:07 +0100
svg chart xslt
Thorsten:

My guess is you're looking for

<xsl:with-param name="y-natrium-after">
  <xsl:value-of select="following-sibling::labor[1]/natrium"/>
</xsl:with-param>

which sets $y-natrium-after to being the natrium child of the first following labor element (given a labor element as context node).

But what are you planning to do with the last one?

BTW (and FWIW): you've got alot of redundancy/verbosity in your code. For example,

<xsl:for-each select="labor">
<xsl:apply-templates select=".">
<xsl:with-param name="x-offset"><xsl:value-of select="(position() *
50)"/></xsl:with-param>
<xsl:with-param name="y-natrium-after"><xsl:value-of
select="natrium[(position() + 1)]"/></xsl:with-param>
</xsl:apply-templates>
</xsl:for-each>

would be no different from


<xsl:apply-templates select="labor">
  <xsl:with-param name="x-offset" select="(position() * 50)"/>
  <xsl:with-param name="y-natrium-after"
    select="natrium[(position() + 1)]"/>
</xsl:apply-templates>

and

<path>
<xsl:attribute name="id">
<xsl:text>line_row1</xsl:text></xsl:attribute>
<xsl:attribute
name="style"><xsl:text>visibility:visible</xsl:text></xsl:attribute>
<xsl:attribute name="d">
<xsl:text>M </xsl:text><xsl:value-of select="$x-offset"/><xsl:text>
</xsl:text><xsl:value-of select="$y-natrium"/>
<xsl:text> L </xsl:text><xsl:value-of select="$x-offset + 28"/><xsl:text>
</xsl:text><xsl:value-of select="$y-natrium-after"/>
</xsl:attribute>
</path>

could be


<path id="line-row1" style="visibility:visible"
      d="M {$x-offset} {$y-natrium}
         L {$x-offset + 28} {$y-natrium-after}"/>

which is more legible once you know what the {} (attribute value templates) are.

Do you care about this stuff? The main thing is to get it working, I guess. To solve your basic problem it sounds like you want to learn some more about how XPath works.

Good luck,
Wendell

At 03:09 PM 7/6/01, you wrote:
Hello, I'm working for a little project to transform XML with XSL(T) in a
SVG line chart.
For drawing lines in SVG I have to specify two points. For example, I would
like to draw a line with the y-coordinates of the three <natrium>-Tags in my
XML-file - the x-coordinates are maybe 50, 100, 150.
I tried to do it with a <xsl:for-each> and a position() like shown in my
(simplified) XSL-file, but it doesn't work. My idea is something like ...
natrium[position + 1] ... for the following value. Can anybody help me??
Thanks a lot...
Thorsten Richter

<?xml version="1.0"?>
<laborviewer>
        <labor>
                <natrium>144</natrium>
                <kalium>4.3</kalium>
                <hb>9.1</hb>
        </labor>
        <labor>
                <natrium>150</natrium>
                <kalium>4.9</kalium>
                <hb>8.8</hb>
        </labor>
        <labor>
                <natrium>140</natrium>
                <kalium>5.0</kalium>
                <hb>8.0</hb>
        </labor>
</laborviewer>

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xlink="http://w3.org/1999/xlink">
<xsl:template match="/">
<xsl:apply-templates select="laborviewer"/>
</xsl:template>
<xsl:template match="laborviewer">
<svg height="100%" width="100%">
<xsl:for-each select="labor">
<xsl:apply-templates select=".">
<xsl:with-param name="x-offset"><xsl:value-of select="(position() *
50)"/></xsl:with-param>
<xsl:with-param name="y-natrium-after"><xsl:value-of
select="natrium[(position() + 1)]"/></xsl:with-param>
</xsl:apply-templates>
</xsl:for-each>
</svg>
</xsl:template>
<xsl:template match="labor">
<xsl:param name="x-offset" select="' '"/>
<xsl:param name="y-natrium-after" select="' '"/>
<xsl:variable name="y-natrium"><xsl:value-of
select="natrium"/></xsl:variable>
<g style="fill:red; stroke:red; stroke-width:1">
<path>
<xsl:attribute name="id">
<xsl:text>line_row1</xsl:text></xsl:attribute>
<xsl:attribute
name="style"><xsl:text>visibility:visible</xsl:text></xsl:attribute>
<xsl:attribute name="d">
<xsl:text>M </xsl:text><xsl:value-of select="$x-offset"/><xsl:text>
</xsl:text><xsl:value-of select="$y-natrium"/>
<xsl:text> L </xsl:text><xsl:value-of select="$x-offset + 28"/><xsl:text>
</xsl:text><xsl:value-of select="$y-natrium-after"/>
</xsl:attribute>
</path>
</g>
</xsl:template>
</xsl:stylesheet>


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


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



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.