Using XSLT to create SVG

后端 未结 2 1580
误落风尘
误落风尘 2020-12-10 22:00

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

相关标签:
2条回答
  • 2020-12-10 22:27

    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.

    0 讨论(0)
  • 2020-12-10 22:36

    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

    0 讨论(0)
提交回复
热议问题