format
This commit is contained in:
parent
ae057436d6
commit
2bf81e2b70
1 changed files with 22 additions and 17 deletions
39
tortue.xsl
39
tortue.xsl
|
@ -5,7 +5,15 @@
|
|||
<xsl:param name="nom" />
|
||||
<xsl:param name="n" />
|
||||
|
||||
<!-- Pour le Lsystem -->
|
||||
<!-- 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 -->
|
||||
<xsl:template match="lsystem">
|
||||
<tortue>
|
||||
<xsl:call-template name="substitution">
|
||||
|
@ -19,6 +27,7 @@
|
|||
<xsl:template name="substitution">
|
||||
<xsl:param name="actuel" />
|
||||
<xsl:param name="n" />
|
||||
|
||||
<!-- Si on doit encore substituer -->
|
||||
<xsl:choose>
|
||||
<xsl:when test="$n > 0">
|
||||
|
@ -36,6 +45,7 @@
|
|||
<xsl:with-param name="n" select="$n - 1" />
|
||||
</xsl:call-template>
|
||||
</xsl:when>
|
||||
|
||||
<xsl:otherwise>
|
||||
<!-- Interprétation -->
|
||||
<xsl:call-template name="Interpretation">
|
||||
|
@ -48,7 +58,9 @@
|
|||
<!-- Applique la substitution -->
|
||||
<xsl:template name="Application">
|
||||
<xsl:param name="data" />
|
||||
|
||||
<xsl:variable name="substitution" select="substitutions/substitution" />
|
||||
|
||||
<xsl:analyze-string
|
||||
select="$data" regex=".">
|
||||
<xsl:matching-substring>
|
||||
|
@ -60,35 +72,36 @@
|
|||
<!-- Interprète la séquence -->
|
||||
<xsl:template name="Interpretation">
|
||||
<xsl:param name="data" />
|
||||
|
||||
<xsl:variable name="interpretation"
|
||||
select="interpretations/interpretation" />
|
||||
<xsl:analyze-string
|
||||
select="$data" regex=".">
|
||||
|
||||
<xsl:analyze-string select="$data" regex=".">
|
||||
<xsl:matching-substring>
|
||||
<xsl:variable name="action"
|
||||
select="$interpretation[@member = current()]" />
|
||||
<xsl:choose>
|
||||
<!-- Ecrire -->
|
||||
<!-- TODO: Si plusieurs <line /> se suivent on pourrait les additionner -->
|
||||
<xsl:when test="matches($action, '^LINE \d+$')">
|
||||
<xsl:when test="starts-with($action, 'LINE')">
|
||||
<line>
|
||||
<xsl:value-of select="substring-after($action, 'LINE ')" />
|
||||
<xsl:value-of select="substring-after($action, ' ')" />
|
||||
</line>
|
||||
</xsl:when>
|
||||
|
||||
<!-- Déplacer -->
|
||||
<!-- TODO: Si plusieurs <move /> se suivent on pourrait les additionner -->
|
||||
<xsl:when test="matches($action, '^MOVE \d+$')">
|
||||
<xsl:when test="starts-with($action, 'MOVE')">
|
||||
<move>
|
||||
<xsl:value-of select="substring-after($action, 'MOVE ')" />
|
||||
<xsl:value-of select="substring-after($action, ' ')" />
|
||||
</move>
|
||||
</xsl:when>
|
||||
|
||||
<!-- Tourner -->
|
||||
<!-- TODO: Si plusieurs <turn /> se suivent on pourrait les additionner -->
|
||||
<xsl:when test="matches($action, '^TURN -?\d+$')">
|
||||
<xsl:when test="starts-with($action, 'TURN')">
|
||||
<turn>
|
||||
<xsl:value-of select="substring-after($action, 'TURN ')" />
|
||||
<xsl:value-of select="substring-after($action, ' ')" />
|
||||
</turn>
|
||||
</xsl:when>
|
||||
|
||||
|
@ -112,12 +125,4 @@
|
|||
</xsl:matching-substring>
|
||||
</xsl:analyze-string>
|
||||
</xsl:template>
|
||||
|
||||
|
||||
<!-- 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>
|
||||
</xsl:transform>
|
||||
|
|
Reference in a new issue