[XSLT] recursivité, evaluation d'une expression
Bonjour,
Voici mon code xml :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
<?xml version="1.0" encoding="iso-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="evalue1.xsl"?>
<arbre>
<noeud val="-">
<noeud val="+">
<noeud val="*">
<noeud val="2"/>
<noeud val="x"/>
</noeud>
<noeud val="4"/>
</noeud>
<noeud val="y"/>
</noeud>
</arbre> |
et mon code xsl :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" version = "1.0" >
<xsl:template match="/">
<xsl:apply-templates select="//arbre"/>
</xsl:template>
<xsl:template match="arbre">
<xsl:apply-templates select="child::noeud"/>
</xsl:template>
<xsl:template match="noeud">
<xsl:choose>
<xsl:when test="./@val ='-' ">
<xsl:variable name="fg">
<xsl:apply-templates select="child::noeud[position()='1']"></xsl:apply-templates>
</xsl:variable>
<xsl:variable name="fd">
<xsl:apply-templates select="child::noeud[position()='2']"></xsl:apply-templates>
<xsl:choose>
<xsl:when test="./@val ='y' ">
<xsl:value-of select="$fd ='3'"/>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="$fg-$fd"/>
</xsl:when>
<xsl:when test="./@val ='+' ">
<xsl:variable name="fg">
<xsl:apply-templates select="child::noeud[position()='1']"></xsl:apply-templates>
</xsl:variable>
<xsl:variable name="fd">
<xsl:apply-templates select="child::noeud[position()='2']"></xsl:apply-templates>
</xsl:variable>
<xsl:value-of select="$fg+$fd"/>
</xsl:when>
<xsl:when test="./@val ='*' ">
<xsl:variable name="fg">
<xsl:apply-templates select="child::noeud[position()='1']"></xsl:apply-templates>
</xsl:variable>
<xsl:variable name="fd">
<xsl:apply-templates select="child::noeud[position()='2']"></xsl:apply-templates>
<xsl:choose>
<xsl:when test="./@val ='x' ">
<xsl:value-of select="$fd ='3'"/>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="$fg*$fd"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="./@val"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet> |
J'aimerais evaluer une expresion comportant des variables mais je n'arrive pas à modifier mes variables x et y du code xml pour pouvoir l'évaluer.
Pouvez vous m'aider.
merci