use 3 space indentation instead of 2
This commit is contained in:
parent
5d3a184468
commit
ead6b851ed
5 changed files with 310 additions and 304 deletions
146
data.xsd
146
data.xsd
|
@ -1,90 +1,90 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||
|
||||
<!-- Valeur contenu par une substitution -->
|
||||
<xs:simpleType name="Element">
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:pattern value="[A-Z]+" />
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
<!-- Valeur contenu par une substitution -->
|
||||
<xs:simpleType name="Element">
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:pattern value="[A-Z]+" />
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
|
||||
<!-- Valeur contenu par une substitution -->
|
||||
<xs:simpleType name="SubElement">
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:pattern value="[A-Z|\[|\]]+" />
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
<!-- Valeur contenu par une substitution -->
|
||||
<xs:simpleType name="SubElement">
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:pattern value="[A-Z|\[|\]]+" />
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
|
||||
<xs:complexType name="Substitution">
|
||||
<xs:simpleContent>
|
||||
<xs:extension base="SubElement">
|
||||
<xs:attribute name="member" use="required">
|
||||
<!-- Membre d'une substitution -->
|
||||
<xs:simpleType>
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:pattern value="[A-Z]{1}" />
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
</xs:attribute>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="Substitution">
|
||||
<xs:simpleContent>
|
||||
<xs:extension base="SubElement">
|
||||
<xs:attribute name="member" use="required">
|
||||
<!-- Membre d'une substitution -->
|
||||
<xs:simpleType>
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:pattern value="[A-Z]{1}" />
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
</xs:attribute>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
|
||||
<!-- Valeur contenu par une interprétation -->
|
||||
<xs:simpleType name="InterpElement">
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:pattern value="(LINE) \d+|(MOVE) \d+|(TURN) -?\d+|(RE)?(STORE)" />
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
<!-- Valeur contenu par une interprétation -->
|
||||
<xs:simpleType name="InterpElement">
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:pattern value="(LINE) \d+|(MOVE) \d+|(TURN) -?\d+|(RE)?(STORE)" />
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
|
||||
|
||||
<xs:complexType name="Interpretation">
|
||||
<xs:simpleContent>
|
||||
<xs:extension base="InterpElement">
|
||||
<xs:attribute name="member" use="required">
|
||||
<!-- Membre d'une interprétation -->
|
||||
<xs:simpleType>
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:pattern value="[A-Z|\[|\]]{1}" />
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
</xs:attribute>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="Interpretation">
|
||||
<xs:simpleContent>
|
||||
<xs:extension base="InterpElement">
|
||||
<xs:attribute name="member" use="required">
|
||||
<!-- Membre d'une interprétation -->
|
||||
<xs:simpleType>
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:pattern value="[A-Z|\[|\]]{1}" />
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
</xs:attribute>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
|
||||
|
||||
<xs:complexType name="Substitutions">
|
||||
<xs:sequence>
|
||||
<xs:element name="substitution" type="Substitution" maxOccurs="unbounded" />
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="Substitutions">
|
||||
<xs:sequence>
|
||||
<xs:element name="substitution" type="Substitution" maxOccurs="unbounded" />
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="Interpretations">
|
||||
<xs:sequence>
|
||||
<xs:element name="interpretation" type="Interpretation" maxOccurs="unbounded" />
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="Interpretations">
|
||||
<xs:sequence>
|
||||
<xs:element name="interpretation" type="Interpretation" maxOccurs="unbounded" />
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="Lsystem">
|
||||
<xs:sequence>
|
||||
<xs:element name="name" type="xs:string" />
|
||||
<!-- TODO: On peut utiliser [a-z|\d] mais c'est peut-être
|
||||
<xs:complexType name="Lsystem">
|
||||
<xs:sequence>
|
||||
<xs:element name="name" type="xs:string" />
|
||||
<!-- TODO: On peut utiliser [a-z|\d] mais c'est peut-être
|
||||
trop restrictif ? -->
|
||||
|
||||
<xs:element name="base" type="Element" />
|
||||
<xs:element name="axiom" type="Element" />
|
||||
<xs:element name="substitutions" type="Substitutions" />
|
||||
<xs:element name="interpretations" type="Interpretations" />
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
|
||||
<xs:element name="lsystems">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="lsystem" type="Lsystem" maxOccurs="unbounded" />
|
||||
<xs:element name="base" type="Element" />
|
||||
<xs:element name="axiom" type="Element" />
|
||||
<xs:element name="substitutions" type="Substitutions" />
|
||||
<xs:element name="interpretations" type="Interpretations" />
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:complexType>
|
||||
|
||||
<xs:element name="lsystems">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="lsystem" type="Lsystem" maxOccurs="unbounded" />
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
</xs:schema>
|
||||
|
|
30
tortue.xsd
30
tortue.xsd
|
@ -1,23 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||
|
||||
<xs:complexType name="Empty">
|
||||
</xs:complexType>
|
||||
<xs:complexType name="Empty">
|
||||
</xs:complexType>
|
||||
|
||||
<xs:element name="tortue">
|
||||
<xs:complexType>
|
||||
<xs:choice maxOccurs="unbounded">
|
||||
<xs:element name="line" type="xs:positiveInteger" />
|
||||
<xs:element name="move" type="xs:positiveInteger" />
|
||||
<xs:element name="turn" type="xs:integer" />
|
||||
<xs:element name="tortue">
|
||||
<xs:complexType>
|
||||
<xs:choice maxOccurs="unbounded">
|
||||
<xs:element name="line" type="xs:positiveInteger" />
|
||||
<xs:element name="move" type="xs:positiveInteger" />
|
||||
<xs:element name="turn" type="xs:integer" />
|
||||
|
||||
<!-- TODO: Store que si on a déja eu un line/move -->
|
||||
<xs:element name="store" type="Empty" />
|
||||
<!-- TODO: Store que si on a déja eu un line/move -->
|
||||
<xs:element name="store" type="Empty" />
|
||||
|
||||
<!-- TODO: Restore que si on a déjà eu un store -->
|
||||
<xs:element name="restore" type="Empty" />
|
||||
</xs:choice>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<!-- TODO: Restore que si on a déjà eu un store -->
|
||||
<xs:element name="restore" type="Empty" />
|
||||
</xs:choice>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
</xs:schema>
|
||||
|
|
184
tortue.xsl
184
tortue.xsl
|
@ -1,124 +1,124 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsl:transform version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||||
<xsl:output indent="yes" />
|
||||
<xsl:output indent="yes" />
|
||||
|
||||
<xsl:param name="nom" />
|
||||
<xsl:param name="n" />
|
||||
<xsl:param name="nom" />
|
||||
<xsl:param name="n" />
|
||||
|
||||
<!-- Pour le Lsystem -->
|
||||
<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>
|
||||
<!-- Pour le Lsystem -->
|
||||
<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>
|
||||
|
||||
<!-- Substitution -->
|
||||
<xsl:template name="substitution">
|
||||
<xsl:param name="actuel" />
|
||||
<!-- Substitution -->
|
||||
<xsl:template name="substitution">
|
||||
<xsl:param name="actuel" />
|
||||
<xsl:param name="n" />
|
||||
<!-- Si on doit encore substituer -->
|
||||
<!-- Si on doit encore substituer -->
|
||||
<xsl:choose>
|
||||
<xsl:when test="$n > 0">
|
||||
<!-- Applique la substitution -->
|
||||
<xsl:when test="$n > 0">
|
||||
<!-- Applique la substitution -->
|
||||
<xsl:variable name="data">
|
||||
<xsl:call-template name="Application">
|
||||
<xsl:with-param name="data" select="$actuel" />
|
||||
</xsl:call-template>
|
||||
</xsl:variable>
|
||||
<xsl:call-template name="Application">
|
||||
<xsl:with-param name="data" select="$actuel" />
|
||||
</xsl:call-template>
|
||||
</xsl:variable>
|
||||
|
||||
<!-- Appel récursif -->
|
||||
<!-- Appel récursif -->
|
||||
<xsl:call-template
|
||||
name="substitution">
|
||||
<xsl:with-param name="actuel" select="$data" />
|
||||
<xsl:with-param name="n" select="$n - 1" />
|
||||
</xsl:call-template>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<!-- Interprétation -->
|
||||
name="substitution">
|
||||
<xsl:with-param name="actuel" select="$data" />
|
||||
<xsl:with-param name="n" select="$n - 1" />
|
||||
</xsl:call-template>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<!-- Interprétation -->
|
||||
<xsl:call-template name="Interpretation">
|
||||
<xsl:with-param name="data" select="$actuel" />
|
||||
</xsl:call-template>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
<xsl:with-param name="data" select="$actuel" />
|
||||
</xsl:call-template>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
<!-- Applique la substitution -->
|
||||
<xsl:template name="Application">
|
||||
<xsl:param name="data" />
|
||||
<!-- 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>
|
||||
<xsl:value-of select="$substitution[@member = current()]" />
|
||||
</xsl:matching-substring>
|
||||
</xsl:analyze-string>
|
||||
</xsl:template>
|
||||
select="$data" regex=".">
|
||||
<xsl:matching-substring>
|
||||
<xsl:value-of select="$substitution[@member = current()]" />
|
||||
</xsl:matching-substring>
|
||||
</xsl:analyze-string>
|
||||
</xsl:template>
|
||||
|
||||
<!-- Interprète la séquence -->
|
||||
<xsl:template name="Interpretation">
|
||||
<xsl:param name="data" />
|
||||
<!-- Interprète la séquence -->
|
||||
<xsl:template name="Interpretation">
|
||||
<xsl:param name="data" />
|
||||
<xsl:variable name="interpretation"
|
||||
select="interpretations/interpretation" />
|
||||
select="interpretations/interpretation" />
|
||||
<xsl:analyze-string
|
||||
select="$data" regex=".">
|
||||
<xsl:matching-substring>
|
||||
<xsl:variable name="action"
|
||||
select="$interpretation[@member = current()]" />
|
||||
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+$')">
|
||||
<line>
|
||||
<xsl:value-of select="substring-after($action, 'LINE ')" />
|
||||
</line>
|
||||
</xsl:when>
|
||||
<!-- Ecrire -->
|
||||
<!-- TODO: Si plusieurs <line /> se suivent on pourrait les additionner -->
|
||||
<xsl:when test="matches($action, '^LINE \d+$')">
|
||||
<line>
|
||||
<xsl:value-of select="substring-after($action, 'LINE ')" />
|
||||
</line>
|
||||
</xsl:when>
|
||||
|
||||
<!-- Déplacer -->
|
||||
<!-- TODO: Si plusieurs <move /> se suivent on pourrait les additionner -->
|
||||
<xsl:when test="matches($action, '^MOVE \d+$')">
|
||||
<move>
|
||||
<xsl:value-of select="substring-after($action, 'MOVE ')" />
|
||||
</move>
|
||||
</xsl:when>
|
||||
<!-- Déplacer -->
|
||||
<!-- TODO: Si plusieurs <move /> se suivent on pourrait les additionner -->
|
||||
<xsl:when test="matches($action, '^MOVE \d+$')">
|
||||
<move>
|
||||
<xsl:value-of select="substring-after($action, 'MOVE ')" />
|
||||
</move>
|
||||
</xsl:when>
|
||||
|
||||
<!-- Tourner -->
|
||||
<!-- TODO: Si plusieurs <turn /> se suivent on pourrait les additionner -->
|
||||
<xsl:when test="matches($action, '^TURN -?\d+$')">
|
||||
<turn>
|
||||
<xsl:value-of select="substring-after($action, 'TURN ')" />
|
||||
</turn>
|
||||
</xsl:when>
|
||||
<!-- Tourner -->
|
||||
<!-- TODO: Si plusieurs <turn /> se suivent on pourrait les additionner -->
|
||||
<xsl:when test="matches($action, '^TURN -?\d+$')">
|
||||
<turn>
|
||||
<xsl:value-of select="substring-after($action, 'TURN ')" />
|
||||
</turn>
|
||||
</xsl:when>
|
||||
|
||||
<!-- Store -->
|
||||
<xsl:when test="$action = 'STORE'">
|
||||
<store />
|
||||
</xsl:when>
|
||||
<!-- Store -->
|
||||
<xsl:when test="$action = 'STORE'">
|
||||
<store />
|
||||
</xsl:when>
|
||||
|
||||
<!-- Restore -->
|
||||
<xsl:when test="$action = 'RESTORE'">
|
||||
<restore />
|
||||
</xsl:when>
|
||||
<!-- Restore -->
|
||||
<xsl:when test="$action = 'RESTORE'">
|
||||
<restore />
|
||||
</xsl:when>
|
||||
|
||||
<!-- Debug -->
|
||||
<!-- <xsl:otherwise>
|
||||
<!-- Debug -->
|
||||
<!-- <xsl:otherwise>
|
||||
<action>
|
||||
<xsl:value-of select="$interpretation[@member = current()]" />
|
||||
</action>
|
||||
</xsl:otherwise> -->
|
||||
</xsl:choose>
|
||||
</xsl:matching-substring>
|
||||
</xsl:analyze-string>
|
||||
</xsl:template>
|
||||
</xsl:choose>
|
||||
</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>
|
||||
<!-- 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>
|
||||
select="lsystems/lsystem[name=$nom]" />
|
||||
</xsl:template>
|
||||
|
||||
</xsl:transform>
|
||||
|
|
42
traceur.xsd
42
traceur.xsd
|
@ -1,24 +1,24 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||
<xs:element name="traceur">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<!-- Peut contenir plusieurs "LINETO" ou "MOVETO" -->
|
||||
<xs:choice maxOccurs="unbounded">
|
||||
<xs:element name="LINETO">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="x" type="xs:decimal" use="required" />
|
||||
<xs:attribute name="y" type="xs:decimal" use="required" />
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="MOVETO">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="x" type="xs:decimal" use="required" />
|
||||
<xs:attribute name="y" type="xs:decimal" use="required" />
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:choice>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="traceur">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<!-- Peut contenir plusieurs "LINETO" ou "MOVETO" -->
|
||||
<xs:choice maxOccurs="unbounded">
|
||||
<xs:element name="LINETO">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="x" type="xs:decimal" use="required" />
|
||||
<xs:attribute name="y" type="xs:decimal" use="required" />
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="MOVETO">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="x" type="xs:decimal" use="required" />
|
||||
<xs:attribute name="y" type="xs:decimal" use="required" />
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:choice>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
||||
|
|
212
traceur.xsl
212
traceur.xsl
|
@ -1,165 +1,171 @@
|
|||
<xsl:transform version="3.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:math="http://www.w3.org/2005/xpath-functions/math"
|
||||
xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
||||
exclude-result-prefixes="xs math">
|
||||
<xsl:output method="xml" indent="yes" />
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:math="http://www.w3.org/2005/xpath-functions/math"
|
||||
xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
||||
exclude-result-prefixes="xs math">
|
||||
<xsl:output method="xml" indent="yes" />
|
||||
|
||||
<!-- Déclaration des variables initiales -->
|
||||
<!-- Déclaration des variables initiales -->
|
||||
<xsl:variable name="initial-x" select="0" as="xs:double" />
|
||||
<xsl:variable
|
||||
name="initial-y" select="0" as="xs:double" />
|
||||
name="initial-y" select="0" as="xs:double" />
|
||||
<xsl:variable name="initial-angle" select="0"
|
||||
as="xs:double" />
|
||||
as="xs:double" />
|
||||
|
||||
<xsl:template match="/tortue">
|
||||
<xsl:processing-instruction name="xml-model">href="traceur.xsd"</xsl:processing-instruction>
|
||||
<xsl:processing-instruction name="xml-model">href="traceur.xsd"</xsl:processing-instruction>
|
||||
<traceur>
|
||||
<!-- Appel du template pour traiter les commandes avec les valeurs initiales des
|
||||
<!-- Appel du template pour traiter les commandes avec les valeurs initiales des
|
||||
paramètres -->
|
||||
<xsl:call-template name="process-commands">
|
||||
<xsl:with-param name="commands" select="*" />
|
||||
<xsl:with-param name="x" select="$initial-x" />
|
||||
<xsl:call-template name="process-commands">
|
||||
<xsl:with-param name="commands" select="*" />
|
||||
<xsl:with-param name="x"
|
||||
select="$initial-x" />
|
||||
<xsl:with-param
|
||||
name="y" select="$initial-y" />
|
||||
name="y" select="$initial-y" />
|
||||
<xsl:with-param
|
||||
name="angle" select="$initial-angle" />
|
||||
name="angle" select="$initial-angle" />
|
||||
<xsl:with-param name="states" select="()" />
|
||||
</xsl:call-template>
|
||||
</traceur>
|
||||
</xsl:template>
|
||||
</xsl:call-template>
|
||||
</traceur>
|
||||
</xsl:template>
|
||||
|
||||
<!-- Template récursif pour traiter les commandes individuelles -->
|
||||
<!-- Template récursif pour traiter les commandes individuelles -->
|
||||
<xsl:template
|
||||
name="process-commands">
|
||||
<xsl:param name="commands" />
|
||||
name="process-commands">
|
||||
<xsl:param name="commands" />
|
||||
<xsl:param name="x" />
|
||||
<xsl:param name="y" />
|
||||
<xsl:param name="angle" />
|
||||
<xsl:param
|
||||
name="states" />
|
||||
name="angle" />
|
||||
<xsl:param
|
||||
name="states" />
|
||||
|
||||
<!-- Si il reste des commandes à traiter -->
|
||||
<!-- Si il reste des commandes à traiter -->
|
||||
<xsl:if test="$commands">
|
||||
<!-- Sélection de la première commande à traiter -->
|
||||
<!-- Sélection de la première commande à traiter -->
|
||||
<xsl:variable
|
||||
name="current-command" select="$commands[1]" />
|
||||
name="current-command" select="$commands[1]" />
|
||||
<xsl:choose>
|
||||
<!-- Si la commande est une ligne -->
|
||||
<xsl:when test="local-name($current-command) = 'line'">
|
||||
<!-- Calcul de la distance à parcourir et conversion de l'angle en radians -->
|
||||
<!-- Si la commande est une ligne -->
|
||||
<xsl:when test="local-name($current-command) = 'line'">
|
||||
<!-- Calcul de la distance à parcourir et conversion de l'angle en radians -->
|
||||
<xsl:variable name="distance"
|
||||
select="number($current-command)" />
|
||||
select="number($current-command)" />
|
||||
<xsl:variable name="radians"
|
||||
select="$angle * math:pi() div 180" />
|
||||
select="$angle * math:pi() div 180" />
|
||||
<xsl:variable name="new-x"
|
||||
select="$x + $distance * math:cos($radians)" />
|
||||
select="$x + $distance * math:cos($radians)" />
|
||||
<xsl:variable name="new-y"
|
||||
select="$y + $distance * math:sin($radians)" />
|
||||
<!-- Création de l'élément LINETO avec les nouvelles coordonnées calculées -->
|
||||
select="$y + $distance * math:sin($radians)" />
|
||||
<!-- Création de l'élément LINETO avec les nouvelles coordonnées calculées -->
|
||||
<LINETO
|
||||
x="{format-number($new-x, '#.######')}"
|
||||
y="{format-number($new-y, '#.######')}" />
|
||||
<!-- Rappel récursif du template avec la mise à jour des coordonnées et des
|
||||
x="{format-number($new-x, '#.######')}"
|
||||
y="{format-number($new-y, '#.######')}" />
|
||||
<!-- Rappel récursif du template avec la mise à jour des coordonnées et des
|
||||
commandes restantes -->
|
||||
<xsl:call-template name="process-commands">
|
||||
<xsl:with-param name="commands" select="$commands[position() > 1]" />
|
||||
<xsl:call-template
|
||||
name="process-commands">
|
||||
<xsl:with-param name="commands" select="$commands[position() > 1]" />
|
||||
<xsl:with-param
|
||||
name="x" select="$new-x" />
|
||||
name="x" select="$new-x" />
|
||||
<xsl:with-param name="y" select="$new-y" />
|
||||
<xsl:with-param
|
||||
name="angle" select="$angle" />
|
||||
name="angle" select="$angle" />
|
||||
<xsl:with-param name="states" select="$states" />
|
||||
</xsl:call-template>
|
||||
</xsl:when>
|
||||
<!-- Si la commande est un turn -->
|
||||
<xsl:when test="local-name($current-command) = 'turn'">
|
||||
<!-- Calcul du nouvel angle avec modulo 360 pour rester dans un cercle complet -->
|
||||
</xsl:call-template>
|
||||
</xsl:when>
|
||||
<!-- Si la commande est un turn -->
|
||||
<xsl:when test="local-name($current-command) = 'turn'">
|
||||
<!-- Calcul du nouvel angle avec modulo 360 pour rester dans un cercle complet -->
|
||||
<xsl:variable
|
||||
name="new-angle" select="($angle + number($current-command)) mod 360" />
|
||||
<!-- Rappel récursif du template sans changer de position mais en mettant à jour
|
||||
name="new-angle" select="($angle + number($current-command)) mod 360" />
|
||||
<!-- Rappel récursif du template sans changer de position mais en mettant à jour
|
||||
l'angle -->
|
||||
<xsl:call-template
|
||||
name="process-commands">
|
||||
<xsl:with-param name="commands" select="$commands[position() > 1]" />
|
||||
name="process-commands">
|
||||
<xsl:with-param name="commands" select="$commands[position() > 1]" />
|
||||
<xsl:with-param
|
||||
name="x" select="$x" />
|
||||
name="x" select="$x" />
|
||||
<xsl:with-param name="y" select="$y" />
|
||||
<xsl:with-param
|
||||
name="angle" select="$new-angle" />
|
||||
<xsl:with-param name="states" select="$states" />
|
||||
</xsl:call-template>
|
||||
</xsl:when>
|
||||
<!-- Si la commande est un MOVE -->
|
||||
<xsl:when test="local-name($current-command) = 'move'">
|
||||
<!-- Calcul de la distance à parcourir et conversion de l'angle en radians -->
|
||||
name="angle" select="$new-angle" />
|
||||
<xsl:with-param name="states"
|
||||
select="$states" />
|
||||
</xsl:call-template>
|
||||
</xsl:when>
|
||||
<!-- Si la commande est un MOVE -->
|
||||
<xsl:when test="local-name($current-command) = 'move'">
|
||||
<!-- Calcul de la distance à parcourir et conversion de l'angle en radians -->
|
||||
<xsl:variable name="distance"
|
||||
select="number($current-command)" />
|
||||
select="number($current-command)" />
|
||||
<xsl:variable name="radians"
|
||||
select="$angle * math:pi() div 180" />
|
||||
select="$angle * math:pi() div 180" />
|
||||
<xsl:variable name="new-x"
|
||||
select="$x + $distance * math:cos($radians)" />
|
||||
select="$x + $distance * math:cos($radians)" />
|
||||
<xsl:variable name="new-y"
|
||||
select="$y + $distance * math:sin($radians)" />
|
||||
<!-- Création de l'élément MOVETO avec les nouvelles coordonnées calculées -->
|
||||
select="$y + $distance * math:sin($radians)" />
|
||||
<!-- Création de l'élément MOVETO avec les nouvelles coordonnées calculées -->
|
||||
<MOVETO
|
||||
x="{format-number($new-x, '#.######')}"
|
||||
y="{format-number($new-y, '#.######')}" />
|
||||
<!-- Rappel récursif du template avec la mise à jour des coordonnées et des
|
||||
x="{format-number($new-x, '#.######')}"
|
||||
y="{format-number($new-y, '#.######')}" />
|
||||
<!-- Rappel récursif du template avec la mise à jour des coordonnées et des
|
||||
commandes restantes -->
|
||||
<xsl:call-template name="process-commands">
|
||||
<xsl:with-param name="commands" select="$commands[position() > 1]" />
|
||||
<xsl:call-template
|
||||
name="process-commands">
|
||||
<xsl:with-param name="commands" select="$commands[position() > 1]" />
|
||||
<xsl:with-param
|
||||
name="x" select="$new-x" />
|
||||
name="x" select="$new-x" />
|
||||
<xsl:with-param name="y" select="$new-y" />
|
||||
<xsl:with-param
|
||||
name="angle" select="$angle" />
|
||||
name="angle" select="$angle" />
|
||||
<xsl:with-param name="states" select="$states" />
|
||||
</xsl:call-template>
|
||||
</xsl:when>
|
||||
<!-- Si la commande est un store -->
|
||||
<xsl:when test="local-name($current-command) = 'store'">
|
||||
<!-- On enregistre le nouvelle état-->
|
||||
</xsl:call-template>
|
||||
</xsl:when>
|
||||
<!-- Si la commande est un store -->
|
||||
<xsl:when test="local-name($current-command) = 'store'">
|
||||
<!-- On enregistre le nouvelle état-->
|
||||
<xsl:variable name="new-state">
|
||||
<state x="{$x}" y="{$y}" angle="{$angle}" />
|
||||
</xsl:variable>
|
||||
<!-- On l'ajoute au précédent -->
|
||||
<state x="{$x}" y="{$y}" angle="{$angle}" />
|
||||
</xsl:variable>
|
||||
<!-- On l'ajoute au précédent -->
|
||||
<xsl:variable
|
||||
name="new-states" select="($states, $new-state)" />
|
||||
name="new-states" select="($states, $new-state)" />
|
||||
<xsl:call-template
|
||||
name="process-commands">
|
||||
<xsl:with-param name="commands" select="$commands[position() > 1]" />
|
||||
name="process-commands">
|
||||
<xsl:with-param name="commands" select="$commands[position() > 1]" />
|
||||
<xsl:with-param
|
||||
name="x" select="$x" />
|
||||
name="x" select="$x" />
|
||||
<xsl:with-param name="y" select="$y" />
|
||||
<xsl:with-param
|
||||
name="angle" select="$angle" />
|
||||
<xsl:with-param name="states" select="$new-states" />
|
||||
</xsl:call-template>
|
||||
</xsl:when>
|
||||
<!-- Si la commande est un restore et que au moins 1 état est enregistré : -->
|
||||
<xsl:when test="local-name($current-command) = 'restore' and count($states)>=1">
|
||||
<!-- On séléctionne notre state-->
|
||||
name="angle" select="$angle" />
|
||||
<xsl:with-param name="states"
|
||||
select="$new-states" />
|
||||
</xsl:call-template>
|
||||
</xsl:when>
|
||||
<!-- Si la commande est un restore et que au moins 1 état est enregistré : -->
|
||||
<xsl:when test="local-name($current-command) = 'restore' and count($states)>=1">
|
||||
<!-- On séléctionne notre state-->
|
||||
<xsl:variable
|
||||
name="state" select="$states/state[1]" />
|
||||
name="state" select="$states/state[1]" />
|
||||
<xsl:variable
|
||||
name="remaining-states"
|
||||
select="subsequence($states/state, 1, count($states/state) - 1)" />
|
||||
name="remaining-states"
|
||||
select="subsequence($states/state, 1, count($states/state) - 1)" />
|
||||
|
||||
<xsl:call-template
|
||||
name="process-commands">
|
||||
<xsl:with-param name="commands" select="$commands[position() > 1]" />
|
||||
name="process-commands">
|
||||
<xsl:with-param name="commands" select="$commands[position() > 1]" />
|
||||
<xsl:with-param
|
||||
name="x" select="($state/@x)[last()]" />
|
||||
name="x" select="($state/@x)[last()]" />
|
||||
<xsl:with-param name="y"
|
||||
select="($state/@y)[last()]" />
|
||||
select="($state/@y)[last()]" />
|
||||
<xsl:with-param name="angle"
|
||||
select="($state/@angle)[last()]" />
|
||||
select="($state/@angle)[last()]" />
|
||||
<xsl:with-param name="states"
|
||||
select="$remaining-states" />
|
||||
</xsl:call-template>
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
</xsl:if>
|
||||
</xsl:template>
|
||||
select="$remaining-states" />
|
||||
</xsl:call-template>
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
</xsl:if>
|
||||
</xsl:template>
|
||||
</xsl:transform>
|
||||
|
|
Reference in a new issue