This repository has been archived on 2024-05-19. You can view files and clone it, but cannot push or open issues or pull requests.
l-systems/svg.xsl

56 lines
1.7 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/2000/svg">
<xsl:output indent="yes" />
<xsl:template match="/">
<svg version="1.0"
xmlns:xlink="http://www.w3.org/1999/xlink">
<xsl:apply-templates select="traceur" />
</svg>
</xsl:template>
<!-- Template pour le traceur -->
<xsl:template match="traceur">
<xsl:variable name="path">
<xsl:call-template name="generatePath">
<xsl:with-param name="idx" select="1" />
<xsl:with-param name="path" select="'M 0 0 '" />
</xsl:call-template>
</xsl:variable>
<!-- TODO: usage temporaire d'un offset pour que l'image soit pas hors de
l'écran, il faut trouver à l'avenir un moyen que ça soit automatique ?? -->
<xsl:variable
name="offset" select="250" />
<g
transform="translate({$offset}, {$offset})">
<path
d="{$path}" stroke="green" fill="none" />
</g>
</xsl:template>
<!-- Fonction récursive terminale -->
<xsl:template name="generatePath">
<xsl:param name="idx" />
<xsl:param name="path" />
<xsl:choose>
<xsl:when test="$idx > count(LINETO)">
<xsl:value-of select="$path" />
</xsl:when>
<xsl:otherwise>
<xsl:variable name="x"
select="LINETO[$idx]/@x" />
<xsl:variable name="y"
select="LINETO[$idx]/@y" />
<xsl:call-template name="generatePath">
<xsl:with-param name="idx" select="$idx + 1" />
<xsl:with-param name="path" select="concat($path, ' L ', $x, ' ', $y)" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:transform>