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" ...
Get XSLT Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.