IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

XSL/XSLT/XPATH XML Discussion :

Calcul/Somme XML / XSL , comment faire ?


Sujet :

XSL/XSLT/XPATH XML

  1. #1
    Candidat au Club
    Inscrit en
    Septembre 2005
    Messages
    6
    Détails du profil
    Informations forums :
    Inscription : Septembre 2005
    Messages : 6
    Points : 4
    Points
    4
    Par défaut Calcul/Somme XML / XSL , comment faire ?
    Hello
    j'aimerai faire une somme de différence positive. Exemple XML d'une RAndo avec des étapes et des altitudes.
    puis j'essaye de faire une transformation pour avoir le total ascencion positive . (c.a.d qu'on ne compte que lorsque le point est supérieur au précédent)

    mais j'ai besoin de conseil car j'y arrive pas...d'un seul coup.
    DE plus si qq pouvais me conseiller sur mon 1er XSL (si on peut l'optimiser) car comme je débute, il me semble qu'il est pas top.
    Merci à tous.


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    <?xml version="1.0" encoding="UTF-8"?>
    <RANDONNEE>
    	<ETAPE>
    		<ALTITUDE>1360</ALTITUDE>
    	</ETAPE>
    	<ETAPE>
    		<ALTITUDE>1374</ALTITUDE>
    	</ETAPE>
    	<ETAPE>
    		<ALTITUDE>1401</ALTITUDE>
    	</ETAPE>
    	<ETAPE>
    		<ALTITUDE>1621</ALTITUDE>
    	</ETAPE>
    	<ETAPE>
    		<ALTITUDE>1559</ALTITUDE>
    	</ETAPE>
    	<ETAPE>
    		<ALTITUDE>1584</ALTITUDE>
    	</ETAPE>
    	<ETAPE>
    		<ALTITUDE>1493</ALTITUDE>
    	</ETAPE>
    	<ETAPE>
    		<ALTITUDE>1658</ALTITUDE>
    	</ETAPE>
    	<ETAPE>
    		<ALTITUDE>1417</ALTITUDE>
    	</ETAPE>
    	<ETAPE>
    		<ALTITUDE>1367</ALTITUDE>
    	</ETAPE>
    	<ETAPE>
    		<ALTITUDE>1358</ALTITUDE>
    	</ETAPE>
    </RANDONNEE>
    => le XSL suivant me permet d'avoir les DELTAs.
    Il est simple d'appliquer une 2 ème transformation pour n'avoir que la SUM des Deltas positif, mais comment y arriver sans faire 2 XSL ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    64
    65
    66
    67
    68
    69
    70
    71
    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    version="1.0">
     
    <xsl:output method="xml"/>
     
    <xsl:template match="RANDONNEE">
    <xsl:element name="CALCUL">
    <xsl:for-each select="ETAPE">
    <xsl:choose>
    <xsl:when test="position()=1">
       <xsl:text>
       </xsl:text>
        <xsl:element name="ALTITUDE0"> 
                  <xsl:value-of select="substring(./ALTITUDE,1,4)">
         </xsl:value-of>
          </xsl:element>
       <xsl:text>
       </xsl:text>
        <xsl:element name="DELTA0">0      </xsl:element>
    </xsl:when>
     
    <xsl:otherwise>
       <xsl:text>
       </xsl:text>
        <xsl:element name="ALTITUDE"> 
                  <xsl:value-of select="substring(./ALTITUDE,1,4)">
         </xsl:value-of>
          </xsl:element>
       <xsl:text>
       </xsl:text>
     
    <xsl:element name="DELTA">
    <xsl:variable name="POS" select="position()"/>
        <xsl:element name="POS">
            <xsl:value-of select="$POS">
         </xsl:value-of>
       </xsl:element>
     
    <xsl:variable name="POSP" select="position()-1"/>
        <xsl:element name="POSP">
            <xsl:value-of select="$POSP">
         </xsl:value-of>
       </xsl:element>
     
    <xsl:variable name="ALT"   select="substring(./ALTITUDE, 1,4)"/>
        <xsl:element name="ALT">
        <xsl:value-of select="$ALT">
         </xsl:value-of>
    </xsl:element>
     
    <xsl:variable name="PREC"
            select="substring(../ETAPE[$POSP]/ALTITUDE, 1,4)"/>    <xsl:element name="PREC">
             <xsl:value-of select="$PREC">
         </xsl:value-of>
    </xsl:element>
     
    <xsl:variable name="DELTA" select="number($ALT)-number($PREC)"/>
        <xsl:element name="DELT">
            <xsl:value-of select="$DELTA">
         </xsl:value-of>
    </xsl:element>
     
    </xsl:element>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:for-each>
    </xsl:element>
    </xsl:template>
     
    </xsl:stylesheet>

  2. #2
    Expert éminent Avatar de Mr N.
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    5 418
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 5 418
    Points : 6 449
    Points
    6 449
    Par défaut
    Je ne suis pas un pro, mais la solution ci-dessous me donne (pour ton jeu d'essai) :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    Etape n°  Altitude  Denivele  Denivele total positif
    1         1360      0         0
    2         1374      14        14
    3         1401      27        41
    4         1621      220       261
    5         1559      -62       261
    6         1584      25        286
    7         1493      -91       286
    8         1658      165       451
    9         1417      -241      451
    10        1367      -50       451
    11        1358      -9        451
    La stylesheet :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
     
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method='html' version='1.0' encoding='ISO-8859-1' indent='yes'/>
     
    <xsl:template match="/RANDONNEE">
    	<html>
    		<head>
    			<style type="text/css">
    				body, th, td {
    					font-family:sans-serif;
    					font-size:10pt;
    				}
    				.number {
    					font-family:monotype;
    					text-align:right;
    				}
    			</style>
    		</head>
    		<body>
    			<table border="1">
    				<tbody>
    					<xsl:for-each select="//ETAPE">
    						<tr>
    							<td><xsl:value-of select="position()" /></td>
    							<td class="number"><xsl:value-of select="ALTITUDE" /></td>
    							<td class="number">
    								<xsl:call-template name="calculDenivele">
    									<xsl:with-param name="avant">
    										<xsl:choose>
    											<xsl:when test="position() = 1">
    												<xsl:value-of select="ALTITUDE" />
    											</xsl:when>
    											<xsl:otherwise>
    												<xsl:value-of select="preceding::ETAPE[1]/ALTITUDE" />
    											</xsl:otherwise>
    										</xsl:choose>
    									</xsl:with-param>
    									<xsl:with-param name="apres">
    										<xsl:value-of select="ALTITUDE" />
    									</xsl:with-param>
    								</xsl:call-template>
    							</td>
    							<td class="number">
    								<xsl:call-template name="positif">
    									<xsl:with-param name="element"><xsl:value-of select="." /></xsl:with-param>
    									<xsl:with-param name="num"><xsl:value-of select="position()" /></xsl:with-param>
    								</xsl:call-template>
    							</td>
    						</tr>
    					</xsl:for-each>
    				</tbody>
    				<thead>
    					<tr>
    						<th>Etape n°</th>
    						<th>Altitude</th>
    						<th>Denivele</th>
    						<th>Denivele total positif</th>
    					</tr>
    				</thead>
    			</table>
    		</body>
    	</html>
    </xsl:template>
     
    <xsl:template name="calculDenivele">
    	<xsl:param name="avant" />
    	<xsl:param name="apres" />
    	<xsl:value-of select="$apres - $avant" />
    </xsl:template>
     
    <xsl:template name="positif">
    	<xsl:param name="somme">0</xsl:param>
    	<xsl:param name="index">1</xsl:param>
    	<xsl:param name="num" />
    	<xsl:choose>
    		<xsl:when test="$index = $num">
    			<xsl:value-of select="$somme" />
    		</xsl:when>
    		<xsl:otherwise>
     
    			<xsl:variable name="avant">
    				<xsl:choose>
    					<xsl:when test="$index = 1">
    							<xsl:value-of select="preceding::ETAPE[1]/ALTITUDE" />
    					</xsl:when>
    					<xsl:otherwise>
    							<xsl:value-of select="preceding::ETAPE[position()=$index]/ALTITUDE" />
    					</xsl:otherwise>
    				</xsl:choose>
    			</xsl:variable>
     
     
    			<xsl:variable name="apres">
    				<xsl:choose>
    					<xsl:when test="$index = 1">
    							<xsl:value-of select="ALTITUDE" />
    					</xsl:when>
    					<xsl:otherwise>
    							<xsl:variable name="new_index"><xsl:value-of select="$index - 1"/></xsl:variable>
    							<xsl:value-of select="preceding::ETAPE[position() = $new_index]/ALTITUDE" />
    					</xsl:otherwise>
    				</xsl:choose>
    			</xsl:variable>
     
     
    			<xsl:variable name="denivele">
    				<xsl:choose>
    					<xsl:when test="$avant &gt; $apres">0</xsl:when>
    					<xsl:otherwise>
    						<xsl:value-of select="$apres - $avant" />
    					</xsl:otherwise>
    				</xsl:choose>
    			</xsl:variable>
     
    			<xsl:call-template name="positif">
    				<xsl:with-param name="somme"><xsl:value-of select="$somme + $denivele" /></xsl:with-param>
    				<xsl:with-param name="index"><xsl:value-of select="$index + 1" /></xsl:with-param>
    				<xsl:with-param name="num"><xsl:value-of select="$num" /></xsl:with-param>
    			</xsl:call-template>
     
    		</xsl:otherwise>
    	</xsl:choose>
    </xsl:template>
     
    </xsl:stylesheet>

  3. #3
    Candidat au Club
    Inscrit en
    Septembre 2005
    Messages
    6
    Détails du profil
    Informations forums :
    Inscription : Septembre 2005
    Messages : 6
    Points : 4
    Points
    4
    Par défaut Pb de Performances pour ce XSL
    Bonjour, et merci pour votre essai. Entre temps j'avais trouvé sur unnsite comment faire une Boucle. J'ai essayé de mon coté et trouvé une solution.
    Puis en testant le votre, je me suis heurté à des pb de perf.
    En effet, le votre met un temp fou. (le mien un peu moins) j'ai recherché pour comprendre (car j'apprend) et je pense qu'il s'agit du fait que votre algorithme recalcul tout le cumul pour chaque elt. (for-each //etape)
    Merci pour votre essai, j'ai appris un peu plus.

    ma solution :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
    <xsl:output method="xml" indent='yes'/>
     
    <xsl:template match="RANDONNEE">
        <xsl:element name="RANDO">
             <xsl:text>
            </xsl:text>
            <xsl:call-template name="boucleplus">
            </xsl:call-template>
        </xsl:element>
    </xsl:template>
     
    <xsl:template name="boucleplus">
      <xsl:param name="debut" select="1" />
      <xsl:param name="fin" select="count(//ETAPE)" />
      <xsl:param name="cumul" select="0" />
     
      <xsl:if test="$cumul &gt;0">
        <xsl:text>Nv Cumul  : </xsl:text>
      <xsl:value-of select="$cumul"></xsl:value-of>
      </xsl:if>
     
      <xsl:text>
      i = </xsl:text>
            <xsl:value-of select="$debut" />    <xsl:text> / </xsl:text>  <xsl:value-of select="$fin" />
     
            <xsl:variable name="prec" select="number($debut)-1"></xsl:variable>
            <xsl:text> Prec :    </xsl:text><xsl:value-of select="$prec"></xsl:value-of>
     
            <xsl:text> Alt courant :    </xsl:text>
            <xsl:value-of select="substring(//ETAPE[$debut]/ALTITUDE, 1,4)">  </xsl:value-of>
            <xsl:text> Alt prec :    </xsl:text>
            <xsl:value-of select="substring(//ETAPE[$prec]/ALTITUDE, 1,4)">  </xsl:value-of>
     
            <xsl:text> Cumul prec :    </xsl:text> <xsl:value-of select="$cumul">    </xsl:value-of>
     
     
            <xsl:if test="($debut)=($fin)">
                    <xsl:call-template name="lastetape">
     	                 <xsl:with-param name="cumuldef" select="$cumul" /> </xsl:call-template>
            </xsl:if> 
     
     
            <xsl:if test="$debut &lt; $fin">
                     <xsl:variable name="debutprec" select="($debut) - 1"></xsl:variable>
                     <xsl:choose>
                  	<xsl:when test="$debut &gt; 1">
    	      		<xsl:if test="substring(//ETAPE[$debut]/ALTITUDE, 1,4) &gt; substring(//ETAPE[$debutprec]/ALTITUDE, 1,4)">
    			      <xsl:variable name="delta" select="number(substring(//ETAPE[$debut]/ALTITUDE, 1,4)) -number( substring(//ETAPE[$debutprec]/ALTITUDE, 1,4))"></xsl:variable>
    		             <xsl:call-template name="cumuler">
     			       <xsl:with-param name="cumul" select="($cumul) + ($delta)" />
    				</xsl:call-template>
     
     
    		             <xsl:call-template name="boucleplus">
    			 	      <xsl:with-param name="debut" select="($debut)+1" />
    				      <xsl:with-param name="fin" select="$fin" />
    			      		<xsl:with-param name="cumul" select="($cumul) + ($delta)" />
    				</xsl:call-template>
     
    		       </xsl:if>
    		       <xsl:if test="substring(//ETAPE[$debut]/ALTITUDE, 1,4) &lt;= substring(//ETAPE[$debutprec]/ALTITUDE, 1,4)">
    			      <xsl:variable name="delta" select="0"></xsl:variable>
    		             <xsl:call-template name="cumuler">
     			       <xsl:with-param name="cumul" select="($cumul) + ($delta)" />
    				</xsl:call-template>
     
            		      <xsl:call-template name="boucleplus">
     	      				<xsl:with-param name="debut" select="($debut)+1" />
    		      			<xsl:with-param name="fin" select="$fin" />
    				      <xsl:with-param name="cumul" select="($cumul) + ($delta)" />
    				</xsl:call-template>
    	      		</xsl:if>
    			</xsl:when>
     
    		       <xsl:otherwise>
           		      <xsl:call-template name="boucleplus">
     	      				<xsl:with-param name="debut" select="($debut)+1" />
    			      		<xsl:with-param name="fin" select="$fin" />
    			      		<xsl:with-param name="cumul" select="($cumul)" />
    			    </xsl:call-template>
          			</xsl:otherwise>	
    			</xsl:choose>
    	   </xsl:if>
     
    </xsl:template>
     
    <xsl:template name="cumuler">
      <xsl:param name="cumul" select="0" />
            <xsl:text> Cumul inter :      </xsl:text>
          <xsl:value-of select="$cumul">      </xsl:value-of>
          <xsl:text> 
           </xsl:text>
    </xsl:template>
     
    <xsl:template name="lastetape">
      <xsl:param name="cumuldef" select="0" />
     
          <xsl:text> Cumul Final :      </xsl:text>
          <xsl:value-of select="$cumuldef">
          </xsl:value-of>
          <xsl:text> 
           </xsl:text>
    </xsl:template>
     
    </xsl:stylesheet>

  4. #4
    Expert éminent
    Avatar de GrandFather
    Inscrit en
    Mai 2004
    Messages
    4 587
    Détails du profil
    Informations personnelles :
    Âge : 54

    Informations forums :
    Inscription : Mai 2004
    Messages : 4 587
    Points : 7 103
    Points
    7 103
    Par défaut
    Bonjour,

    en utilisant à bon escient les axes XPath et les tests de variables, il est possible de faire beaucoup plus simple (et efficace) :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:output method="html" encoding="UTF-8"/>
     
    	<xsl:template match="/RANDONNEE">
    		<html>
    			<head>
    				<title>ALTITUDES</title>
    			</head>
    			<body>
    				<p>Différence positive :
    					<xsl:call-template name="diff-pos">
    						<xsl:with-param name="etape" select="ETAPE[1]"/>
    					</xsl:call-template> m
    				</p>
    			</body>
    		</html>
    	</xsl:template>
     
    	<xsl:template name="diff-pos">
    		<xsl:param name="etape-precedente"/>
    		<xsl:param name="etape"/>
    		<xsl:param name="total" select="0"/>
    		<xsl:choose>
    			<xsl:when test="$etape">
    				<xsl:call-template name="diff-pos">
    					<xsl:with-param name="etape-precedente" select="$etape"/>
    					<xsl:with-param name="etape" select="$etape/following-sibling::ETAPE[1]"/>
    					<xsl:with-param name="total">
    						<xsl:choose>
    							<xsl:when test="$etape-precedente">
    								<xsl:choose>
    									<xsl:when test="$etape/ALTITUDE &gt; $etape-precedente/ALTITUDE">
    										<xsl:value-of select="$total + $etape/ALTITUDE - $etape-precedente/ALTITUDE"/>
    									</xsl:when>
    									<xsl:otherwise><xsl:value-of select="$total"/></xsl:otherwise>
    								</xsl:choose>
    							</xsl:when>
    							<xsl:otherwise>0</xsl:otherwise>
    						</xsl:choose>
    					</xsl:with-param>
    				</xsl:call-template>
    			</xsl:when>
    			<xsl:otherwise><xsl:value-of select="$total"/></xsl:otherwise>
    		</xsl:choose>
    	</xsl:template>
     
    </xsl:stylesheet>
    FAQ XML
    ------------
    « Le moyen le plus sûr de cacher aux autres les limites de son savoir est de ne jamais les dépasser »
    Giacomo Leopardi

  5. #5
    Candidat au Club
    Inscrit en
    Septembre 2005
    Messages
    6
    Détails du profil
    Informations forums :
    Inscription : Septembre 2005
    Messages : 6
    Points : 4
    Points
    4
    Par défaut suite du test
    Merci, super
    Je suis arrivé à le refaire.
    j'avais bien essayé d'utiliser following-sibling, mais la syntaxe n'était pas correct et j'y arrivais pas.
    Super. c'est de l'optimisation !

  6. #6
    Candidat au Club
    Inscrit en
    Septembre 2005
    Messages
    6
    Détails du profil
    Informations forums :
    Inscription : Septembre 2005
    Messages : 6
    Points : 4
    Points
    4
    Par défaut Problème dans Xpath
    Bonjour,
    j'ai réessayé mais je me heurte à une erreur dans Xpath.
    Sous XMLSpy, la transformation se passe sans problème, mais via Xerces Ou Xalan 2_7_0 ça joue pas.

    Il semblerait que c'est le mm problème :
    la résolution du choose avec le test < ....qui pose problème :
    SI quelqu'un peut m'aider , merci. beaucoup.
    Car après ça j'aimerai bien aller vers XSL-FO....
    Bon WE à tous

    <xsl:choose>
    <xsl:when test="substring($etapeprec/ALTITUDE,1,4) &lt; substring($etape/ALTITUDE,1,4)">
    <xsl:value-of select="$cumul + substring($etape/ALTITUDE,1,4) - substring($etapeprec/ALTITUDE,1,4)"></xsl:value-of>
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="$cumul"></xsl:value-of>
    </xsl:otherwise>
    </xsl:choose>


    Erreur Xalan :
    ------------------
    file:/c:/temp/temp2.xsl; N░ de ligne41; N░ de colonne-1; Erreur XSLT (javax.xml. transform.TransformerException): Erreur inconnue dans XPath.

    Erreur xerces-2_6_2 : du style "Node ne peut etre converti... "
    -----------------


    XML :
    <?xml version="1.0" encoding="windows-1252"?>
    <RANDONNEE>
    <ETAPE>
    <POSITION>44.755566,6.792111</POSITION>
    <ALTITUDE>1360.000000</ALTITUDE>
    </ETAPE>
    <ETAPE>
    <POSITION>44.754704,6.792648</POSITION>
    <ALTITUDE>1374.687988</ALTITUDE>
    </ETAPE>
    <ETAPE>
    <POSITION>44.754021,6.793101</POSITION>
    <ALTITUDE>1401.425537</ALTITUDE>
    </ETAPE>
    <ETAPE>
    <POSITION>44.753437,6.792865</POSITION>
    <ALTITUDE>1424.439941</ALTITUDE>
    </ETAPE>
    <ETAPE>
    <POSITION>44.753113,6.791966</POSITION>
    <ALTITUDE>1432.319946</ALTITUDE>
    </ETAPE>
    <ETAPE>
    <POSITION>44.752747,6.791520</POSITION>
    <ALTITUDE>1444.740845</ALTITUDE>
    </ETAPE>
    <ETAPE>
    <POSITION>44.752060,6.791415</POSITION>
    <ALTITUDE>1451.968018</ALTITUDE>
    </ETAPE>
    </RANDONNEE>

    XSL :
    <?xml version="1.0"?>
    <xsl:stylesheet xmlnssl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">

    <xsl:output method="xml"/>

    <xsl:template match="/RANDONNEE">

    <xsl:element name="RANDO">
    <xsl:call-template name="CALCUL">
    <xsl:with-param name="etape" select="//ETAPE[1]"> </xsl:with-param>
    </xsl:call-template>
    </xsl:element>
    </xsl:template>

    <xsl:template name="CALCUL">
    <xsl:param name="etapeprec"></xsl:param>
    <xsl:param name="etape"> </xsl:param>
    <xsl:param name="cumul">0</xsl:param>
    <xsl:if test="$etapeprec">
    <xsl:element name="CUMINTER">
    <xsl:value-of select="$cumul"></xsl:value-of>
    </xsl:element>
    </xsl:if>
    <xsl:text>
    </xsl:text>

    <xsl:if test="$etape">
    <xsl:element name="ETAPE">
    <xsl:value-of select="substring($etape/ALTITUDE, 1,4)"></xsl:value-of>
    </xsl:element>
    </xsl:if>

    <xsl:choose>
    <xsl:when test="$etape">
    <xsl:call-template name="CALCUL">
    <xsl:with-param name="etapeprec" select="$etape"></xsl:with-param>
    <xsl:with-param name="etape" select="$etape/following-sibling::ETAPE[1]"></xsl:with-param>
    <xsl:with-param name="cumul">
    <xsl:choose>
    <xsl:when test="substring($etapeprec/ALTITUDE,1,4) &lt; substring($etape/ALTITUDE,1,4)">
    <xsl:value-of select="$cumul + substring($etape/ALTITUDE,1,4) - substring($etapeprec/ALTITUDE,1,4)"></xsl:value-of>
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="$cumul"></xsl:value-of>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:with-param>
    </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
    <xsl:element name="CUMUL">
    <xsl:value-of select="$cumul"></xsl:value-of>
    </xsl:element>

    </xsl:otherwise>
    </xsl:choose>

    </xsl:template>

    </xsl:stylesheet>

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Noob][XML][XSL]Comment faire ceci ??
    Par Devil666 dans le forum XSL/XSLT/XPATH
    Réponses: 5
    Dernier message: 31/08/2005, 16h00
  2. [XSL]Comment faire ceci ?? Mon for-each n'affiche pas tout !
    Par Devil666 dans le forum XSL/XSLT/XPATH
    Réponses: 4
    Dernier message: 27/07/2005, 15h04
  3. [Noob][XSL] Comment faire ceci ??
    Par Devil666 dans le forum XSL/XSLT/XPATH
    Réponses: 9
    Dernier message: 22/07/2005, 16h38
  4. [XSL] Comment faire pour trier de cette façon ?
    Par shupa dans le forum XSL/XSLT/XPATH
    Réponses: 4
    Dernier message: 30/06/2005, 17h39
  5. [XML][XSL]Comment atteindre ces 2 header séparément?
    Par Devil666 dans le forum XSL/XSLT/XPATH
    Réponses: 7
    Dernier message: 27/05/2005, 07h36

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo