2024-04-26 22:19:39 +02:00
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
2024-04-27 01:44:42 +02:00
|
|
|
<xsl:transform version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
2024-05-03 01:59:58 +02:00
|
|
|
<xsl:output indent="yes" />
|
2024-04-26 22:19:39 +02:00
|
|
|
|
2024-05-03 01:59:58 +02:00
|
|
|
<xsl:param name="nom" />
|
|
|
|
<xsl:param name="n" />
|
2024-04-27 01:44:42 +02:00
|
|
|
|
2024-05-06 21:01:18 +02:00
|
|
|
<!-- On récupère le Lsystem qui nous intéresse -->
|
|
|
|
<xsl:template match="/">
|
|
|
|
<xsl:processing-instruction name="xml-model">href="tortue.xsd"</xsl:processing-instruction>
|
|
|
|
|
|
|
|
<xsl:apply-templates
|
|
|
|
select="lsystems/lsystem[name=$nom]" />
|
|
|
|
</xsl:template>
|
|
|
|
|
|
|
|
<!-- Appel de la substitution -->
|
2024-05-03 01:59:58 +02:00
|
|
|
<xsl:template match="lsystem">
|
|
|
|
<tortue>
|
|
|
|
<xsl:call-template name="substitution">
|
|
|
|
<xsl:with-param name="actuel" select="axiom" />
|
|
|
|
<xsl:with-param name="n" select="$n" />
|
|
|
|
</xsl:call-template>
|
|
|
|
</tortue>
|
|
|
|
</xsl:template>
|
2024-04-27 01:44:42 +02:00
|
|
|
|
2024-05-03 01:59:58 +02:00
|
|
|
<!-- Substitution -->
|
|
|
|
<xsl:template name="substitution">
|
|
|
|
<xsl:param name="actuel" />
|
2024-05-06 14:46:31 +02:00
|
|
|
<xsl:param name="n" />
|
2024-05-06 21:01:18 +02:00
|
|
|
|
2024-05-03 01:59:58 +02:00
|
|
|
<!-- Si on doit encore substituer -->
|
2024-05-06 14:46:31 +02:00
|
|
|
<xsl:choose>
|
2024-05-03 01:59:58 +02:00
|
|
|
<xsl:when test="$n > 0">
|
|
|
|
<!-- Applique la substitution -->
|
2024-05-06 14:46:31 +02:00
|
|
|
<xsl:variable name="data">
|
2024-05-03 01:59:58 +02:00
|
|
|
<xsl:call-template name="Application">
|
|
|
|
<xsl:with-param name="data" select="$actuel" />
|
|
|
|
</xsl:call-template>
|
|
|
|
</xsl:variable>
|
2024-04-27 01:44:42 +02:00
|
|
|
|
2024-05-03 01:59:58 +02:00
|
|
|
<!-- Appel récursif -->
|
2024-05-06 14:46:31 +02:00
|
|
|
<xsl:call-template
|
2024-05-03 01:59:58 +02:00
|
|
|
name="substitution">
|
|
|
|
<xsl:with-param name="actuel" select="$data" />
|
|
|
|
<xsl:with-param name="n" select="$n - 1" />
|
|
|
|
</xsl:call-template>
|
|
|
|
</xsl:when>
|
2024-05-06 21:01:18 +02:00
|
|
|
|
2024-05-03 01:59:58 +02:00
|
|
|
<xsl:otherwise>
|
|
|
|
<!-- Interprétation -->
|
2024-05-06 14:46:31 +02:00
|
|
|
<xsl:call-template name="Interpretation">
|
2024-05-03 01:59:58 +02:00
|
|
|
<xsl:with-param name="data" select="$actuel" />
|
|
|
|
</xsl:call-template>
|
2024-05-06 21:32:11 +02:00
|
|
|
|
|
|
|
<!-- DEBUG : Chaîne pas interprétée -->
|
|
|
|
<!-- <xsl:value-of select="$actuel" /> -->
|
2024-05-03 01:59:58 +02:00
|
|
|
</xsl:otherwise>
|
|
|
|
</xsl:choose>
|
|
|
|
</xsl:template>
|
2024-04-27 01:44:42 +02:00
|
|
|
|
2024-05-03 01:59:58 +02:00
|
|
|
<!-- Applique la substitution -->
|
|
|
|
<xsl:template name="Application">
|
|
|
|
<xsl:param name="data" />
|
2024-05-06 21:01:18 +02:00
|
|
|
|
2024-05-06 14:46:31 +02:00
|
|
|
<xsl:variable name="substitution" select="substitutions/substitution" />
|
2024-05-06 21:01:18 +02:00
|
|
|
|
2024-05-06 14:46:31 +02:00
|
|
|
<xsl:analyze-string
|
2024-05-03 01:59:58 +02:00
|
|
|
select="$data" regex=".">
|
|
|
|
<xsl:matching-substring>
|
2024-05-06 21:32:11 +02:00
|
|
|
<xsl:variable name="sub" select="$substitution[@member = current()]" />
|
|
|
|
|
|
|
|
<xsl:choose>
|
|
|
|
<!-- Si pas de substitution trouvé, alors on renvoie le caractère
|
|
|
|
tel qu'il est -->
|
|
|
|
<xsl:when test="not($sub)">
|
|
|
|
<xsl:value-of select="current()" />
|
|
|
|
</xsl:when>
|
|
|
|
|
|
|
|
<!-- Sinon renvois sa substitution -->
|
|
|
|
<xsl:otherwise>
|
|
|
|
<xsl:value-of select="$sub" />
|
|
|
|
</xsl:otherwise>
|
|
|
|
</xsl:choose>
|
2024-05-03 01:59:58 +02:00
|
|
|
</xsl:matching-substring>
|
|
|
|
</xsl:analyze-string>
|
|
|
|
</xsl:template>
|
2024-04-27 01:44:42 +02:00
|
|
|
|
2024-05-03 01:59:58 +02:00
|
|
|
<!-- Interprète la séquence -->
|
|
|
|
<xsl:template name="Interpretation">
|
|
|
|
<xsl:param name="data" />
|
2024-05-06 21:01:18 +02:00
|
|
|
|
2024-05-06 14:46:31 +02:00
|
|
|
<xsl:variable name="interpretation"
|
2024-05-03 01:59:58 +02:00
|
|
|
select="interpretations/interpretation" />
|
2024-05-06 21:01:18 +02:00
|
|
|
|
|
|
|
<xsl:analyze-string select="$data" regex=".">
|
2024-05-03 01:59:58 +02:00
|
|
|
<xsl:matching-substring>
|
|
|
|
<xsl:variable name="action"
|
|
|
|
select="$interpretation[@member = current()]" />
|
2024-05-06 14:46:31 +02:00
|
|
|
<xsl:choose>
|
2024-05-03 01:59:58 +02:00
|
|
|
<!-- Ecrire -->
|
|
|
|
<!-- TODO: Si plusieurs <line /> se suivent on pourrait les additionner -->
|
2024-05-06 21:01:18 +02:00
|
|
|
<xsl:when test="starts-with($action, 'LINE')">
|
2024-05-03 01:59:58 +02:00
|
|
|
<line>
|
2024-05-06 21:01:18 +02:00
|
|
|
<xsl:value-of select="substring-after($action, ' ')" />
|
2024-05-03 01:59:58 +02:00
|
|
|
</line>
|
|
|
|
</xsl:when>
|
2024-04-27 01:49:51 +02:00
|
|
|
|
2024-05-03 01:59:58 +02:00
|
|
|
<!-- Déplacer -->
|
|
|
|
<!-- TODO: Si plusieurs <move /> se suivent on pourrait les additionner -->
|
2024-05-06 21:01:18 +02:00
|
|
|
<xsl:when test="starts-with($action, 'MOVE')">
|
2024-05-03 01:59:58 +02:00
|
|
|
<move>
|
2024-05-06 21:01:18 +02:00
|
|
|
<xsl:value-of select="substring-after($action, ' ')" />
|
2024-05-03 01:59:58 +02:00
|
|
|
</move>
|
|
|
|
</xsl:when>
|
2024-04-27 01:44:42 +02:00
|
|
|
|
2024-05-03 01:59:58 +02:00
|
|
|
<!-- Tourner -->
|
|
|
|
<!-- TODO: Si plusieurs <turn /> se suivent on pourrait les additionner -->
|
2024-05-06 21:01:18 +02:00
|
|
|
<xsl:when test="starts-with($action, 'TURN')">
|
2024-05-03 01:59:58 +02:00
|
|
|
<turn>
|
2024-05-06 21:01:18 +02:00
|
|
|
<xsl:value-of select="substring-after($action, ' ')" />
|
2024-05-03 01:59:58 +02:00
|
|
|
</turn>
|
|
|
|
</xsl:when>
|
2024-04-27 01:44:42 +02:00
|
|
|
|
2024-05-03 01:59:58 +02:00
|
|
|
<!-- Store -->
|
2024-05-07 12:24:09 +02:00
|
|
|
<xsl:when test="current() = '['">
|
2024-05-03 01:59:58 +02:00
|
|
|
<store />
|
|
|
|
</xsl:when>
|
2024-04-27 01:44:42 +02:00
|
|
|
|
2024-05-03 01:59:58 +02:00
|
|
|
<!-- Restore -->
|
2024-05-07 12:24:09 +02:00
|
|
|
<xsl:when test="current() = ']'">
|
2024-05-03 01:59:58 +02:00
|
|
|
<restore />
|
|
|
|
</xsl:when>
|
2024-04-27 01:44:42 +02:00
|
|
|
|
2024-05-06 21:32:11 +02:00
|
|
|
<!-- DEBUG : Affichage des actions non-gérés -->
|
2024-05-03 01:59:58 +02:00
|
|
|
<!-- <xsl:otherwise>
|
2024-05-06 14:46:31 +02:00
|
|
|
<action>
|
|
|
|
<xsl:value-of select="$interpretation[@member = current()]" />
|
|
|
|
</action>
|
|
|
|
</xsl:otherwise> -->
|
2024-05-03 01:59:58 +02:00
|
|
|
</xsl:choose>
|
|
|
|
</xsl:matching-substring>
|
|
|
|
</xsl:analyze-string>
|
|
|
|
</xsl:template>
|
2024-04-26 22:19:39 +02:00
|
|
|
</xsl:transform>
|