O'Reilly logo

XSLT Cookbook by Sal Mangano

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating Reusable SVG Generation Utilities for Graphs and Charts

Problem

You want to create a library of SVG generators that can be mixed and matched in applications involving graphical presentation of data.

Solution

If you plan to do a significant amount of SVG generation using XSLT, it is useful to develop a library of templates that generate graphical components that can be mixed and matched. This section shows several components that can graph data.

Axis generation

This example creates a general set of templates for generating graduated x- and y-axes:

<!-- Draw a graduated X-Axis --> <xsl:template name="svgu:xAxis"> <xsl:param name="min" select="0"/> <!-- Min x coordinate --> <xsl:param name="max" select="100"/> <!-- Max x coordinate --> <xsl:param name="offsetX" select="0"/> <!-- X offset of axis placement --> <xsl:param name="offsetY" select="0"/> <!-- Y offset of axis placement --> <xsl:param name="width" select="500"/> <!-- Width of the physical plotting area --> <xsl:param name="height" select="500"/> <!-- Height of the physical plotting area --> <xsl:param name="majorTicks" select="10"/> <!-- Number of major axis divisions --> <xsl:param name="majorBottomExtent" select="4"/> <!-- Length of the major tick mark from axis downward --> <xsl:param name="majorTopExtent" select="$majorBottomExtent"/> <!-- Length of the major tick mark from axis upward --> <xsl:param name="labelMajor" select="true( )"/> <!-- Label the major tick marks if true --> <xsl:param name="minorTicks" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required