I have an XML file that stores data about classes at a school. I\'m just starting to mess around with SVG, so made an SVG file to represent the enrollment numbers in each cl
Make sure you put the declaration of the SVG namespace on the root element of the stylesheet as only then it applies to all result elements in all templates. With your current code only the svg
element gets the right namespace while your rectangles in the other templates end up being in no namespace.
Let me suggest the following as your starting point:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/2000/svg">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<svg version="1.0">
<g transform="translate(0 500) scale(1 -1)">
<xsl:apply-templates select="courses/course/section"/>
</g>
</svg>
</xsl:template>
<xsl:template match="section">
<rect x="{40 * position()}" width="30" height="{enrollment}"/>
</xsl:template>
</xsl:stylesheet>
See also: Using XSLT and SVG to create bar chart from XML - Scaling Bar Chart