Bonjour,
Voila, j'ai un xml avec un noeud tarif dans lequel il y a plusieurs tarifs. Je voudrais récupérer le tarif le moins élevé. Mais le code que j'ai implémenté ne fonctionne pas et je ne vois pas ou ca plante ....?
Voici le code xml :
ET voici mon code 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 <tif:Tarifs> - <tif:ModesPaiement> <tif:ModePaiement type="13.02.05" xml:lang="FR">Carte de crédit</tif:ModePaiement> <tif:ObservationModePaiement xml:lang="FR">Cartes de crédit acceptées : Visa,EuroCard</tif:ObservationModePaiement> </tif:ModesPaiement> - <tif:DetailTarifs> - <tif:DetailTarif type="13.04.02.01" libelle="Prix adulte / jour" xml:lang="FR"> <tif:TarifRef>O</tif:TarifRef> <tif:TarifMin>4</tif:TarifMin> </tif:DetailTarif> - <tif:DetailTarif type="13.04.02.07" libelle="Prix enfant / jour" xml:lang="FR"> <tif:TarifRef>N</tif:TarifRef> <tif:TarifMin>3</tif:TarifMin> </tif:DetailTarif> - <tif:DetailTarif type="13.04.02.02" libelle="Prix animal / jour" xml:lang="FR"> <tif:TarifRef>N</tif:TarifRef> <tif:TarifMin>1</tif:TarifMin> </tif:DetailTarif> - <tif:DetailTarif type="13.04.02.06" libelle="Prix emplacement camping-car" xml:lang="FR"> <tif:TarifRef>N</tif:TarifRef> <tif:TarifMin>12</tif:TarifMin> </tif:DetailTarif> - <tif:DetailTarif type="13.04.07.15" libelle="Forfait" xml:lang="FR"> <tif:TarifRef>N</tif:TarifRef> <tif:TarifMin>16</tif:TarifMin> - <tif:DescriptionTarif> Forfait 1jour avec Tente/Caravane, pour 2 adultes Réduction hors-saison </tif:DescriptionTarif> </tif:DetailTarif> </tif:DetailTarifs> </tif:Tarifs>
Il m'affiche tout le temps la valeur 0, j'ai l'impression que la valeur de la variable prixMin ne change jamais et reste toujours à 100000.
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 <!-- J'initialise une variable a 100000 car je suis sur qu'aucun tarif ne le dépasse--> <xsl:variable name="prixMin" select="number(100000)"></xsl:variable> <!-- Je boucle sur tous les tarifs --> <xsl:for-each select="tif:Tarifs/tif:DetailTarifs/tif:DetailTarif/tif:TarifMin"> <!-- Je stocke le tarif minimum --> <xsl:variable name="prix" select="number(tif:Tarifs/tif:DetailTarifs/tif:DetailTarif/tif:TarifMin)"></xsl:variable> <!-- Je teste si ce tarif est inférieur au précédent --> <xsl:if test="$prix < $prixMin"> <!-- Si il est inférieur àalors je l'enregistre --> <xsl:variable name="prixMin" >$prix</xsl:variable> </xsl:if> </xsl:for-each> <!-- J'affiche mon résultat --> <xsl:choose> <xsl:when test="$prixMin = 100000"> <xsl:text>0</xsl:text> </xsl:when> <xsl:otherwise> <xsl:value-of select="$prixMin"/> </xsl:otherwise> </xsl:choose>
Si quelqu'un voit une solution je suis tout ouïe.
Merci d'avance
Sylvere
Partager