From: Ricaud Matthieu (matthieu.ricaud@cned.fr)
Date: 05/05/2004 - 15:25
Il faut que tu passe ta variable en paramètre à ta XSL :
Page resultat.asp
<%
'-----------------------------------------------------------'
Function loadXMLFile(strXMLFile, strXSLFile, Param, ValeurParam)
Dim objXML
Dim objXSL
set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.async = false
objXML.load(strXMLFile)
set objXSL = Server.CreateObject("Microsoft.XMLDOM")
objXSL.async = false
objXSL.load(strXSLFile)
Dim xslt, xslProc
Set xslt = server.CreateObject(Msxml2.XSLTemplate)
xslt.stylesheet = objXSL
Set xslProc = xslt.createProcessor()
xslProc.input = objXML
xslProc.addParameter Param, ValeurParam ' ==> C là que tu passes le
parametre à la XSL
xslProc.Transform
response.write(xslProc.output)
Set objXML=Nothing
Set objXSL=Nothing
Set xslt=Nothing
Set xslProc=Nothing
End Function
'-----------------------------------------------------------'
Dim variable
variable = Request.QueryString("nom")
loadXMLFile
server.MapPath("XML.xml"),server.MapPath("XSL.xsl"),"Nom",variable
'-----------------------------------------------------------'
%>
Page XSL.xsl
<?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:param name="Param"/> <!-- ==> là tu déclare le
paramètre qui est passé (avec le même nom!)-->
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="personnes/personne[@nom=$Param]"> <!--là tu
utilise un prédicat avec $param qui te permet de choisir le bon noeud-->
<b>
<font face="arial" size="3">
<xsl:value-of select="prenom"/>
</font>
</b>
<xsl:value-of select="age"/>
<xsl:value-of select="ville"/>
</xsl:for-each>
</font>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Voila voila, g pas tester mais normalement ça marche...
-----Message d'origine-----
De : xml-tech-bounce@xmlfr.org [mailto:xml-tech-bounce@xmlfr.org]De la
part de Lara Callaway
Envoyé : mercredi 5 mai 2004 16:10
À : xml-tech@xmlfr.org
Objet : [xml-tech] Utiliser une variable ASP avec XSL
Bonjour :o)
Je vous expose mon problème :
J'ai une page ASP qui m'affiche grace à une fonction les données de mon
fichier
XML mises en forme avec un fichier XSL. "variable" est une variable qui
contient un nom et qui est récupérée par formulaire de la page précédente
Page resultat.asp
<%
'-----------------------------------------------------------'
Function loadXMLFile(strXMLFile, strXSLFile)
Dim objXML
Dim objXSL
set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.async = false
objXML.load(strXMLFile)
set objXSL = Server.CreateObject("Microsoft.XMLDOM")
objXSL.async = false
objXSL.load(strXSLFile)
Response.Write(objXML.transformNode(objXSL))
End Function
'-----------------------------------------------------------'
Dim variable
variable = Request.QueryString("nom")
loadXMLFile server.MapPath("XML.xml"),server.MapPath("XSL.xsl"),variable
'-----------------------------------------------------------'
%>
Page XML.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<PERSONNES>
<PERSONNE nom="dupont">
<PRENOM>Pierre</PRENOM>
<AGE>30</AGE>
<VILLE>Paris</VILLE>
</PERSONNE>
<PERSONNE nom="dupond">
<PRENOM>Jean</PRENOM>
<AGE>20</AGE>
<VILLE>Bordeaux</VILLE>
</PERSONNE>
<PERSONNE nom="choco">
<PRENOM>Lucie</PRENOM>
<AGE>10</AGE>
<VILLE>Nancy</VILLE>
</PERSONNE>
<PERSONNE nom="rose">
<PRENOM>Zoe</PRENOM>
<AGE>19</AGE>
<VILLE>Nice</VILLE>
</PERSONNE>
</PERSONNES>
Page XSL.xsl
<?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>
<body>
<xsl:for-each select="personnes/personne">
<b>
<font face="arial" size="3">
<xsl:value-of select="prenom"/>
</font>
</b>
<xsl:value-of select="age"/>
<xsl:value-of select="ville"/>
</xsl:for-each>
</font>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Alors je voudrais que resultat.asp affiche uniquement les informations de la
personne dont le nom est contenu dans ma variable "variable". Par exemple si
variable="choco" je voudrais que ça m'affiche :
Lucie
10
Nancy
J'ai essayé plein de choses mais je n'arrive pas à m'en sortir... Pouvez
vous
m'aider ? Je vous remercie ;-)
--
Devenez redacteur <XML>fr et contribuez au developpement du
xml francophone (http://xmlfr.org/infos/redacteurs/) !
Liste de diffusion "xml-tech@xmlfr.org" (http://xmlfr.org).
Cette liste est a votre disposition pour discuter en francais de
tout sujet technique lie a XML.
Pour resilier votre abonnement, envoyez un message contenant
la commande "unsubscribe" a xml-tech-request@xmlfr.org
(mailto:xml-tech-request@xmlfr.org?Subject=unsubscribe)
--
Devenez redacteur <XML>fr et contribuez au developpement du
xml francophone (http://xmlfr.org/infos/redacteurs/) !
Liste de diffusion "xml-tech@xmlfr.org" (http://xmlfr.org).
Cette liste est a votre disposition pour discuter en francais de
tout sujet technique lie a XML.
Pour resilier votre abonnement, envoyez un message contenant
la commande "unsubscribe" a xml-tech-request@xmlfr.org
(mailto:xml-tech-request@xmlfr.org?Subject=unsubscribe)
Archive générée par hypermail 2.1.3 le 28/06/2004 - 11:06 UTC
webmaster@xmlfr.org
|