Salut tout le monde,
j'ai à réaliser un projet XML. C une sorte d'un e-service d'achat de produits. Ces produits sont classés par catégorie (informatique, mobilier et papeterie).
Donc je dispose de trois fichiers xml: inf.xml, mob.xml et pap.xml qui contiennent une liste des produits selon la catégorie. et j'ai un fichier afficherCategorie.xsl.
Dans le fichier html résultat je dois avoir un combobox qui contient les trois categories, et un bouton "afficher". En choisissant une categorie et en cliquant sur le bouton, les produits de la categorie correspondante doivent etre affichés dans un tableau.
Donc, on a besoin je pense d'une fonction javascript qui affecte une valeur a une variable xsl selon la categorie choisie. et apres on utilise la variable pour afficher le fichier xml qui correspond a cette categorie.
En fait, ce n'est qu'une idée pour résoudre le problème mais je ne sais pas comment l'implémenter, surtout comment affecter la valeur de la variable xsl depuis la fonction javascript, et comment utiliser cette variable pour choisir le fichier xml convenable.
est ce que klk1 peut me guider la dessus car je suis bloquée, et merci d'avance.
fichier inf.xml
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 <?xml version="1.0" encoding="UTF-8"?> <!--!DOCTYPE Classe SYSTEM "classe.dtd"--> <?xml-stylesheet type="text/xml" href="afficherCategorie.xsl"?> <!--?xml-stylesheet href="Styles.css" type= "text/css" ?--> <Prod_informatiques> <Produit> <Reference>064658</Reference> <Designation>TOSHIBA A100-991</Designation> <Disponible>Oui</Disponible> <Prix>8990,21</Prix> <Source>images/064658.jpg</Source> </Produit> <Produit> <Reference>062401</Reference> <Designation>TOSHIBA P100-340</Designation> <Disponible>Oui</Disponible> <Prix>images/11490,21</Prix> <Source>images/062401.jpg</Source> </Produit> <Produit> <Reference>067027</Reference> <Designation>HP PC Pavilion M7330 Média Center Pentium 4524 3,06 Ghz</Designation> <Disponible>Non</Disponible> <Prix>6000,05</Prix> <Source>images/067027.jpg</Source> </Produit> <Produit> <Reference>067456</Reference> <Designation>FUJITSU PC ESPRIMO P5700 Celeron 3,4 Ghz</Designation> <Disponible>Oui</Disponible> <Prix>5000,05</Prix> <Source>images/067456.jpg</Source> </Produit> <Produit> <Reference>064734</Reference> <Designation>FUJITSU PC ESPRIMO P5915 Pentium 4 3,4 Ghz</Designation> <Disponible>Oui</Disponible> <Prix>6300,05</Prix> <Source>images/064734.jpg</Source> </Produit> <Produit> <Reference>065813</Reference> <Designation>Ecran plat 19" TFT PHILIPS 190 C7</Designation> <Disponible>Oui</Disponible> <Prix>2090,84</Prix> <Source>images/065813.jpg</Source> </Produit> <Produit> <Reference>066962</Reference> <Designation>Ecran plat 19" NIS DAEWOO</Designation> <Disponible>Non</Disponible> <Prix>1790,84</Prix> <Source>images/066962.jpg</Source> </Produit> <Produit> <Reference>066961</Reference> <Designation>Ecran plat 17" NIS DAEWOO</Designation> <Disponible>Oui</Disponible> <Prix>1490,84</Prix> <Source>images/066961.jpg</Source> </Produit> <Produit> <Reference>063129</Reference> <Designation>Ecran plat 17" SYM DAEWOO</Designation> <Disponible>Non</Disponible> <Prix>1690,84</Prix> <Source>images/063129.jpg</Source> </Produit> <Produit> <Reference>064572</Reference> <Designation>Ecran plat LCD 203 B-20" SAMSUNG</Designation> <Disponible>Oui</Disponible> <Prix>2490,84</Prix> <Source>images/064572.jpg</Source> </Produit> <Produit> <Reference>064571</Reference> <Designation>Ecran plat LCD 720 N-17" SAMSUNG</Designation> <Disponible>Oui</Disponible> <Prix>1690,84</Prix> <Source>images/064571.jpg</Source> </Produit> <Produit> <Reference>067535</Reference> <Designation>Scanner Lide 600F CANON</Designation> <Disponible>Oui</Disponible> <Prix>1290,13</Prix> <Source>images/067535.jpg</Source> </Produit> <Produit> <Reference>067124</Reference> <Designation>Scanner ScanJet G4050 HP</Designation> <Disponible>Oui</Disponible> <Prix>1690,42</Prix> <Source>images/067124.jpg</Source> </Produit> <Produit> <Reference>064653</Reference> <Designation>Scanner ScanJet N6010 HP</Designation> <Disponible>Oui</Disponible> <Prix>3990,42</Prix> <Source>images/064653.jpg</Source> </Produit> </Prod_informatiques>
fichier afficherCategorie.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85 <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:template match="/"> <HTML> <HEAD> <TITLE>Affichage des produits par categorie</TITLE> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <link rel="stylesheet" media="screen" type="text/css" title="Design" href="Styles.css" /> <script type="text/javascript" src="Lib.js"></script> </HEAD> <BODY BGCOLOR="#FFFFFF"> <tr bgcolor="#1e90ff"> <th align="left" width="900"> <h2>Achat en Ligne</h2> </th> </tr> <br></br> <tr> <th width="100" class="titre">Categorie : </th> <th width="150" align="left"> <select name="categorie"> <option value="Informatique">Informatique</option> <option value="Mobilier">Mobilier</option> <option value="Papeterie">Papeterie</option> </select> </th> <th><input type="button" value="Afficher" size="200" onclick="afficher(this);"/></th> </tr> <br></br> <br></br> <table bgcolor="#1e90ff"> <tr> <th class="titre" width="80" align="left">Reference</th> <th class="titre" width="100" align="left">Source</th> <th class="titre" width="500" align="left">Designation</th> <th class="titre" width="150"><img src="images/Panier.gif" alt="Panier" /></th> </tr> </table> <div style="overflow-y:scroll; height:600px; width:860px; border:1px solid black; border-color:#87cefa"> <xsl:apply-templates/> </div> <br></br> <br></br> <tr> <th width="800" align="right"><input type="button" value="Ajouter au panier" size="300" onclick="ajouter();"/></th> <th witdh="300" align="right"><input type="button" value="Voir le panier" size="300" onclick="voir();"/></th> </tr> </BODY> </HTML> </xsl:template > <xsl:template match="Prod_informatiques/Produit" > <table> <tbody> <tr> <xsl:if test="contains(Disponible,'Oui')"> <th class="element" width="80" align="left"><xsl:value-of select="Reference"/></th> <th width="100" align="center"> <img> <xsl:attribute name="src"> <xsl:value-of select="Source"/> </xsl:attribute> </img> </th> <th class="element" width="500" align="left"><xsl:value-of select="Designation"/></th> <th class="element" width="150"><input type="text" name="quantite" size="5"/></th> </xsl:if> <xsl:if test="contains(Disponible,'Non')"> <th class="gris" width="80" align="left"><xsl:value-of select="Reference"/></th> <th width="100" align="center"> <img> <xsl:attribute name="src"> <xsl:value-of select="Source"/> </xsl:attribute> </img> </th> <th class="gris" width="500" align="left"><xsl:value-of select="Designation"/></th> <th width="150"><input type="text" name="quantite" size="5" disabled="true"/></th> </xsl:if> </tr> </tbody> </table> </xsl:template > </xsl:stylesheet>
fichier Lib.js
En fait j'ai essayé d'utiliser cette fonction pour donner une valeur a une variable xsl mais ça marche pa
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 function afficher(){ with (document.forms[0].categorie.value){ document.getElementById('xlslogin')[0].innerHTML='Prod_informatiques/Produit'; } with (document.forms[0].categorie.value){ document.getElementById('xlslogin')[0].innerHTML='Prod_mobilier/Produit'; } with (document.forms[0].categorie.value){ document.getElementById('xlslogin')[0].innerHTML='Prod_papeterie/Produit'; } }
Partager