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