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 :

[XSLT] [PHP] executer une fonction PHP lors de la transformation


Sujet :

XSL/XSLT/XPATH XML

  1. #1
    Membre régulier
    Profil pro
    Étudiant
    Inscrit en
    Février 2007
    Messages
    379
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2007
    Messages : 379
    Points : 123
    Points
    123
    Par défaut [XSLT] [PHP] executer une fonction PHP lors de la transformation
    Bonjour,

    Est ce que je peux ecrire du code php dans un fichier XSL ???

    En fait j'effectue des lectures (des noms et prenoms) d'un fichier XML, et je veux mettre la premiere lettre en majiscule et le reste en miniscule!

    ou bien est ce que c'est possible de faire ca en xslt ?


    merci



    ...

  2. #2
    Expert éminent sénior

    Profil pro
    Inscrit en
    Juin 2002
    Messages
    6 152
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2002
    Messages : 6 152
    Points : 17 777
    Points
    17 777
    Par défaut
    Si le traitement est effectué côté serveur et par PHP 5 il vous est alors possible d'utiliser les fonctions PHP dans votre feuille de style (EXSLT). Il vous faudra activer ce support via la méthode registerPHPFunctions (de la classe XSLTProcessor - voir le lien pour de plus amples détails).

    En espérant que cela répond à vos attentes.

  3. #3
    Membre régulier
    Profil pro
    Étudiant
    Inscrit en
    Février 2007
    Messages
    379
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2007
    Messages : 379
    Points : 123
    Points
    123
    Par défaut
    je m'excuse pour le retard!

    En fait je n'ai pas compris votre reponse

    si j'ecris du code php dans le xsl par exemple

    <?php

    echo"hey";

    ?>


    dois je modifier l'extension de mon fichier en un .php ?

    et je ne comprend pas l'affaire de la méthode registerPHPFunctions.

    En fait ce que je veux faire c'est des decoupage de chaines de caractere et mettre la premiere lettre en majiscule



    merci julp!



    ...

  4. #4
    Expert éminent sénior

    Profil pro
    Inscrit en
    Juin 2002
    Messages
    6 152
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2002
    Messages : 6 152
    Points : 17 777
    Points
    17 777
    Par défaut
    Ce n'est pas si simple surtout si le traitement est effectué côté serveur, ce qui devrait être votre cas d'après vos précédentes discussions. Si vous placez du code PHP dans votre feuille de style et changer son extension en .php ça fonctionnera sans doute pour le client mais niveau serveur vous allez l'obliger à se comporter comme tel (à faire une requête HTTP pour lui-même ...).

    La "solution" que je vous proposais était d'utiliser les fonctions PHP dans votre feuille de style. Un exemple bête comme chou consistant à lister les login et à les mettre en majuscule à l'aide de la fonction PHP strtoupper :
    Un fichier XML :
    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    <?xml version="1.0" encoding="iso-8859-1"?>
    <utilisateurs>
        <utilisateur login="éric" mdp="55502c4c916b0ff4b6fc62d24d6868314a2561b47726696558ecae201e8e3c12" />
        <utilisateur login="guillaume" mdp="274c8009224625d893a48ad78481d1130dc31b32c8500b335bfcf73168f6fa54" />
        <utilisateur login="rémi" mdp="e760178ca98e1a8b3722a4559d89e31557d064c022038f84bf66c0e49f819eb5" />
    </utilisateurs>
    Un fichier XSL :
    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" exclude-result-prefixes="php">
    
        <xsl:output method="html" encoding="iso-8859-1" indent="no"/>
    
        <xsl:template match="/">
            <ul>
                <xsl:apply-templates />
            </ul>
        </xsl:template>
    
        <xsl:template match="utilisateur">
            <li><xsl:value-of select="php:function('strtoupper', string(@login))" /></li>
        </xsl:template>
    
    </xsl:stylesheet>
    Et le code PHP pour mettre les deux en relations :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <?php
    $dom = DomDocument::load('test.xsl');
    $proc = new XSLTProcessor;
    $proc->importStylesheet($dom);
    $proc->registerPHPFunctions();
     
    $dom = new DomDocument;
    $dom->preserveWhiteSpace = FALSE;
    $dom->formatOutput = TRUE;
    $dom->load('test.xml');
     
    echo $proc->transformToXML($dom);
    Le résultat :
    * éRIC
    * GUILLAUME
    * RéMI
    (les accents ne sont pas passés, ce n'est pas grave : un petit problème de locales)

    Sachant que pour répondre à la question initiale, il vous suffirait d'employer la fonction ucfirst.

  5. #5
    Membre régulier
    Profil pro
    Étudiant
    Inscrit en
    Février 2007
    Messages
    379
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2007
    Messages : 379
    Points : 123
    Points
    123
    Par défaut
    et le code php je le met dans le fichier XSL ?


    merci

    ...

  6. #6
    Membre régulier
    Profil pro
    Étudiant
    Inscrit en
    Février 2007
    Messages
    379
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2007
    Messages : 379
    Points : 123
    Points
    123
    Par défaut
    J'ai compris je dois ajouter le ligne : $proc->registerPHPFunctions(); dans le fichier php correspondant au fichier xsl

    mais je suis encore perdu!

    par exemple ici :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <td align="center"><xsl:value-of select="struct/var[@name='implicationprojet']" /></td>
    je voudrais utiliser la fonction str_replace pour remplacer le / par un retour chariot (\n) dans "struct/var[@name='implicationprojet']", je ne vois comment mettre les arguments dans le str_replace!!



    ...

  7. #7
    Expert éminent sénior

    Profil pro
    Inscrit en
    Juin 2002
    Messages
    6 152
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2002
    Messages : 6 152
    Points : 17 777
    Points
    17 777
    Par défaut
    Citation Envoyé par Mo_Poly Voir le message
    J'ai compris je dois ajouter le ligne : $proc->registerPHPFunctions(); dans le fichier php correspondant au fichier xsl
    Ce n'est pas suffisant : j'ai marqué tous les éléments importants en rouge

    Modifier votre fichier XSL :
    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
    <td align="center"><xsl:value-of disable-output-escaping="yes" select="php:function('format_implicationprojet', string(struct/var[@name='implicationprojet']))" /></td>

    Et ajouter dans votre fichier PHP une fonction comme celle-ci :
    Code PHP : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    function format_implicationprojet($str) {
        return str_replace('/', "\n", $str);
        #return str_replace('/', '<br />', $str); // Pour des retours à la ligne HTML !
    }

  8. #8
    Membre régulier
    Profil pro
    Étudiant
    Inscrit en
    Février 2007
    Messages
    379
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2007
    Messages : 379
    Points : 123
    Points
    123
    Par défaut
    Citation Envoyé par julp Voir le message

    Modifier votre fichier XSL :
    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
    <td align="center"><xsl:value-of disable-output-escaping="yes" select="php:function('format_implicationprojet', string(struct/var[@name='implicationprojet'])" /></td>
    quand j'ai modifié mon code xsl avec cette ligne ca ma donné 4 erreurs :


    Warning: XSLTProcessor::importStylesheet() [function.XSLTProcessor-importStylesheet]: Invalid expression in C:\Documents and Settings\mo\Mes documents\html\5.php on line 17

    Warning: XSLTProcessor::importStylesheet() [function.XSLTProcessor-importStylesheet]: compilation error: file file:///C%3A/Documents%20and%20Settings/mo/Mes%20documents/html/personnes.xsl line 86 element value-of in C:\Documents and Settings\mo\Mes documents\html\5.php on line 17

    Warning: XSLTProcessor::importStylesheet() [function.XSLTProcessor-importStylesheet]: xsl:value-of : could not compile select expression 'php:function('format_implicationprojet', string(struct/var[@name='implicationprojet'])' in C:\Documents and Settings\mo\Mes documents\html\5.php on line 17

    Warning: XSLTProcessor::transformToXml() [function.XSLTProcessor-transformToXml]: No stylesheet associated to this object in C:\Documents and Settings\mo\Mes documents\html\5.php on line 25


    voici mes codes

    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
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    <?xml version="1.0" encoding="utf-8"?><!DOCTYPE xsl:stylesheet  [
    	<!ENTITY nbsp   " ">
    	<!ENTITY copy   "©">
    	<!ENTITY reg    "®">
    	<!ENTITY trade  "™">
    	<!ENTITY mdash  "—">
    	<!ENTITY ldquo  "“">
    	<!ENTITY rdquo  "”"> 
    	<!ENTITY pound  "£">
    	<!ENTITY yen    "¥">
    	<!ENTITY euro   "€">
    ]>
        <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" exclude-result-prefixes="php">
        <xsl:output method="html" encoding="iso-8859-1" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
     
        <xsl:template match="database">
            <html xmlns="http://www.w3.org/1999/xhtml">
                <head>
    				<link rel="stylesheet" media="screen" href="2.css"/> 
                    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
                    <title>Untitled Document</title>
                </head>
                <body>
    			<div id="en_tete">
    			</div>
     
    			<div id="menu">
     
     
    			<div class="element_menu">
     
    						   <ul>
    							   <li><a href="aj-pers.php">Ajouter une personne</a></li>
    							   <li><a href="5.php">Gérer la liste du personnel du laboratoire</a></li>
    							   <li><a href="impr.php" target="new">Version imprimable</a></li>
    						   </ul>
    					   </div> 
    			</div>
    			<div id="corps">
                    <center>
                        <form method="POST" action="del.php">
                            <table border="1">
    						<p>     
                                <input type="submit" name="action" value="Editer" />
                                <input type="submit" name="action" value="Supprimer" />
                            </p>
                                <tr>
                                    <th width="200" align="center">Id</th>
                                    <th width="200" align="center">Nom</th>
                                    <th width="200" align="center">Prenom</th>
                                    <th width="200" align="center">statut</th>
                                    <th width="200" align="center">Page Web</th>
                                    <th width="200" align="center">pageWebGRMIAO</th>
                                    <th width="200" align="center">photo</th>
                                    <th width="200" align="center">distinctions</th>
                                    <th width="200" align="center">implication projet</th>
                                    <th width="200" align="center">X</th>
                                </tr>
                                <xsl:apply-templates />
                            </table>
                            <p>     
     
                                <input type="submit" name="action" value="Editer" />
                                <input type="submit" name="action" value="Supprimer" />
                            </p>
                        </form>
                    </center>
    				</div>
     
    				<div id="pied_de_page">
    				</div>
                </body>
            </html>
        </xsl:template>
     
        <xsl:template match="fiche">
            <tr>
                <td align="center"><xsl:value-of select="struct/var[@name='id']" /></td>
                <td align="center"><xsl:value-of select="struct/var[@name='nom']" /></td>
                <td align="center"><xsl:value-of select="struct/var[@name='prenom']" /></td>
                <td align="center"><xsl:value-of select="struct/var[@name='statut']" /></td>
                <td align="center"><xsl:value-of select="struct/var[@name='pageWebPerso']" /></td>
                <td align="center"><xsl:value-of select="struct/var[@name='pageWebGRMIAO']" /></td>
                <td align="center"><xsl:value-of select="struct/var[@name='photo']" /></td>
                <td align="center"><xsl:value-of select="struct/var[@name='distinctions']" /></td>
                <td align="center"><xsl:value-of disable-output-escaping="yes" select="php:function('format_implicationprojet', string(struct/var[@name='implicationprojet'])" /></td>
                <td>
     
                    <xsl:element name="input">
                        <xsl:attribute name="name">selection[]</xsl:attribute>
                        <xsl:attribute name="type">checkbox</xsl:attribute>
                        <xsl:attribute name="value"><xsl:value-of select="struct/var[@name='id']" /></xsl:attribute>
                    </xsl:element>
                </td>
            </tr>
        </xsl:template>
    </xsl:stylesheet>
    et php

    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
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Le personnel du lab MAGNU</title>
    </head>
     
    <body>
    <?php
     
    function format_implicationprojet($str) {
        return str_replace('/', '<br />', $str); 
    }
     
    $dom=DomDocument::load("personnes.xsl");
    $proc= new XSLTProcessor;
    $proc->importStyleSheet($dom);
    $proc->registerPHPFunctions();
     
    $dom= new DomDocument;
    $dom->preserveWhiteSpace = FALSE;
    $dom->formatOutput = TRUE;
    $dom->load("personnes.xml");
     
    echo $proc->transformToXML($dom); 
    ?>
     
    </body>
    </html>


    je ne comprend pas le probléme



    ...

  9. #9
    Expert éminent sénior

    Profil pro
    Inscrit en
    Juin 2002
    Messages
    6 152
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2002
    Messages : 6 152
    Points : 17 777
    Points
    17 777
    Par défaut
    Désolé, c'est sans doute une erreur de ma part : j'ai supprimé par inadvertance une parenthèse fermante au niveau de la valeur de l'attribut select (cf ci-dessus) lorsque j'ai voulu adapter à votre situation.

  10. #10
    Membre régulier
    Profil pro
    Étudiant
    Inscrit en
    Février 2007
    Messages
    379
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2007
    Messages : 379
    Points : 123
    Points
    123
    Par défaut
    ca marche mais je ne sais pas pourquoi ca me crée un autre probléme

    la page xsl que je viens de modifier , contient un bouton modifier, en cliquant sur ce bouton on obtient un formulaire initialisé avec les données pour la personne selectionnée.

    en cliquand sur modifier j'obtient ca :


    Warning: XSLTProcessor::transformToXml() [function.XSLTProcessor-transformToXml]: xsltExtFunctionTest: PHP Object did not register PHP functions in C:\Documents and Settings\mo\Mes documents\html\del.php on line 226

    et cette erreur se repete plus que 100 fois, et l'affichage que j'avais en bas de la page ne marche plus ... pourtant la modification que j'ai fait dans mon fichier XSL n'a aucun rapport avec le fichier de modification en question!

    voici le fichier del.php

    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
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Document sans titre</title>
    </head>
    
    <body>
    
    <?php
    $fichier_xml = 'personnes.xml';
    $fichier_xsl = 'personnes.xsl';
    
    $fichier_xml2 = 'projets.xml';
    
    
     
    $dom = DomDocument::load($fichier_xsl);
    $proc = new XSLTProcessor;
    $proc->importStylesheet($dom);
     
    $dom = new DomDocument;
    $dom->preserveWhiteSpace = FALSE;
    $dom->formatOutput = TRUE;
    $dom->load($fichier_xml);
    
     
    $dom2 = new DomDocument;
    $dom2->preserveWhiteSpace = FALSE;
    $dom2->formatOutput = TRUE;
    $dom2->load($fichier_xml2);
    
    
     
    function getFicheById($dom, $id)
    {
        $xpath = new DOMXPath($dom);
        $res = $xpath->query(sprintf('//fiche[struct/var[@name = "id"]/text() = "%d"]', $id));
        if ($res->length == 1) {
            return $res->item(0);
        } else {
            return FALSE;
        }
    }
    
    function getVarByName($fiche, $name)
    {
        $xpath = new DOMXPath($fiche->ownerDocument);
        $res = $xpath->query(sprintf('struct/var[@name = "%s"]', $name), $fiche);
        if (!$res or $res->length == 1) {
            return $res->item(0)->nodeValue;
        } else {
            return FALSE;
        }
    }
     
    if (isset($_POST['action'])) {
        switch (strtolower($_POST['action'])) {
            case 'editer':
    		
    				$proj= array();
    				$i=0;
    				$listeProjets = $dom2->getElementsByTagName('nom');
    				foreach ($listeProjets as $projets)
    				{
    					$proj[$i]= $projets->firstChild->nodeValue ;
    					$i++;
    				}
                if (is_array($_POST['selection'])) {
    				if ($fiche = getFicheById($dom, $_POST['selection'][0])) {
    				$id=$_POST['selection'][0];
    				if ($fiche->hasAttribute("type")) {
        					$type=$fiche->getAttribute("type");
        			}
    				
    				$nom=getVarByName($fiche, 'nom');
    				$prenom=getVarByName($fiche, 'prenom');
    				$statut=getVarByName($fiche, 'statut');
    				$pageWeb=getVarByName($fiche, 'pageWebPerso');
    				$pageWebGRMIAO=getVarByName($fiche, 'pageWebGRMIAO');
    				$photo=getVarByName($fiche, 'photo');
    				$distinctions=utf8_decode(getVarByName($fiche, 'distinctions'));
    				$implicationprojet=getVarByName($fiche, 'implicationprojet');
    				
    				$projets=split("/",$implicationprojet);
    				
    				
    				
    					echo"
    						<div class=\"formulaire\">
    						<FORM method=post action=\"modif.php\">
    							<TABLE BORDER=0>
    							
    							<TR>
    								<TD>type</TD>
    								<TD>
    								<INPUT type=text name=\"type\" value=$type>
    								</TD>
    							</TR>
    							
    							<TR>
    								<TD>id</TD>
    								<TD>
    								<INPUT type=text name=\"id\"  value= $id>
    								</TD>
    							</TR>
    							
    							<TR>
    								<TD>nom</TD>
    								<TD>
    								<INPUT type=text name=\"nom\" value= $nom >
    								</TD>
    							</TR>
    							
    							<TR>
    								<TD>prenom</TD>
    								<TD>
    								<INPUT type=text name=\"prenom\" value= $prenom>
    								</TD>
    								</TR>
    								<TR>
    								<TD>statut</TD><td>
    								<select name=\"statut\" title=\"statut\" STYLE=\"width:145\"><option value=\"\"></option><option value=\"Professeur\"";
    								if($statut == 'Professeur'){
    								echo 'selected = "selected"';
    								}
    								 
    								echo ">Professeur</option><option value=\"Etudiant\"";
    								if($statut == 'Etudiant'){
    								echo 'selected = "selected"';
    								}
    								 
    								echo ">Etudiant</option><option value=\"Chercheur\"";
    								 
    								if($statut == 'Chercheur'){
    								echo 'selected = "selected"';
    								} 
    								 
    								echo ">Chercheur</option></select>";
    								echo"</td></TR>";
    	
    								echo"<TR>
    
    								<TD>pageWebPerso</TD>
    								<TD>
    								<INPUT type=text name=\"pageWebPerso\" value=$pageWeb>
    								</TD>
    							</TR>
    							
    							<TR>
    								<TD>pageWebGRMIAO</TD>
    								<TD>
    								<INPUT type=text name=\"pageWebGRMIAO\" value= $pageWebGRMIAO>
    								</TD>
    							</TR>
    							
    							<TR>
    								<TD>photo</TD>
    								<TD>
    								<INPUT type=text name=\"photo\" value= $photo>
    								</TD>
    							</TR>
    							
    							<TR>
    								<TD>distinctions</TD>
    								<TD>
    								<INPUT type=text name=\"distinctions\" value= \"$distinctions\">
    								</TD>
    							</TR>
    							
    							<TR>
    								<TD>Implication dans le projet</TD>
    								<TD>";
    								$tmp=0;
    								foreach ($proj as $v) {
    										
    										for($i=0;$i<count($projets);$i++)
    										{
    											if($v==$projets[$i])
    												$tmp++;
    										}
    										if($tmp==1){
    											echo "<input type=\"checkbox\" name=\"implicationprojet[]\" value=$v CHECKED> ";
    											echo" $v <Br/>";
    										}
    										else{
    											echo "<input type=\"checkbox\" name=\"implicationprojet[]\" value=$v> ";
    											echo" $v <Br/>";
    										}
    										$tmp=0;
    								}
    								
    								echo"</TD>
    							</TR>
    							
    							<TR>
    								<TD COLSPAN=2>&nbsp;</TD>
    							</TR>
    							
    							</TABLE>
    						<input name=\"modifier\" type=\"submit\" value=\"Modifier\" />
    						<input name=\"annuler\" type=\"submit\" value=\"Annuler\" />
    						</FORM>
    						</div>
    						";
    						
    				}
    			}
                break;
            case 'supprimer':
                if (is_array($_POST['selection'])) {
                    foreach ($_POST['selection'] as $id) {
                        if ($fiche = getFicheById($dom, $id)) {
                            $fiche->parentNode->removeChild($fiche);
                        } else {
                            die("Erreur au niveau de l'expression XPath");
                        }
                    }
    				
                }
                break;
        }
        $dom->save('personnes.xml');
    }
     
    echo $proc->transformToXML($dom);//l'erreur est ici!!!
    ?>
    
    </body>
    </html>

    help



    ...

  11. #11
    Expert éminent sénior

    Profil pro
    Inscrit en
    Juin 2002
    Messages
    6 152
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2002
    Messages : 6 152
    Points : 17 777
    Points
    17 777
    Par défaut
    Ne manquerait-il pas par hasard : $proc->registerPHPFunctions(); dont j'ai pris la peine, à plusieurs reprises, de mentionner toute son importance ?

    Si ça ne vient pas de là il faudrait nous donner l'ensemble (surtout le fichier XSL et se limiter à l'essentiel).

  12. #12
    Membre régulier
    Profil pro
    Étudiant
    Inscrit en
    Février 2007
    Messages
    379
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2007
    Messages : 379
    Points : 123
    Points
    123
    Par défaut
    ok je vais expliquer avec beaucoup de details , et je n'ai pas oublié le $proc->registerPHPFunctions(); !!

    ok j'ai cette page




    la liste des personnes est longue et ca vient d'un fichier XML , le code de cette page et ce fichier 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
     <xsl:template match="database">
            <html xmlns="http://www.w3.org/1999/xhtml">
                <head>
    				<link rel="stylesheet" media="screen" href="2.css"/> 
                    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
                    <title>Modification/Suppression de la liste du personnel du laboratoire MAGNU</title>
                </head>
                <body>
    			<div id="en_tete">
    			</div>
     
    			<div id="menu">
     
     
    			<div class="element_menu">
     
    						   <ul>
    							   <li><a href="aj-pers.php">Ajouter une personne</a></li>
    							   <li><a href="5.php">Gérer la liste du personnel du laboratoire</a></li>
    							   <li><a href="impr.php" target="new">Version imprimable</a></li>
    						   </ul>
    					   </div> 
    			</div>
    			<div id="corps">
                    <center>
                        <form method="POST" action="del.php">
                            <table border="1">
    						<p>     
                                <input type="submit" name="action" value="Editer" />
                                <input type="submit" name="action" value="Supprimer" />
                            </p>
                                <tr>
                                    <th width="200" align="center">Id</th>
                                    <th width="200" align="center">Nom</th>
                                    <th width="200" align="center">Prenom</th>
                                    <th width="200" align="center">statut</th>
                                    <th width="200" align="center">Page Web</th>
                                    <th width="200" align="center">pageWebGRMIAO</th>
                                    <th width="200" align="center">photo</th>
                                    <th width="200" align="center">distinctions</th>
                                    <th width="200" align="center">implication projet</th>
                                    <th width="200" align="center">X</th>
                                </tr>
                                <xsl:apply-templates />
                            </table>
                            <p>     
     
                                <input type="submit" name="action" value="Editer" />
                                <input type="submit" name="action" value="Supprimer" />
                            </p>
                        </form>
                    </center>
    				</div>
     
    				<div id="pied_de_page">
    				</div>
                </body>
            </html>
        </xsl:template>
     
        <xsl:template match="fiche">
            <tr>
                <td align="center"><xsl:value-of select="struct/var[@name='id']" /></td>
                <td align="center"><xsl:value-of select="struct/var[@name='nom']" /></td>
                <td align="center"><xsl:value-of select="struct/var[@name='prenom']" /></td>
                <td align="center"><xsl:value-of select="struct/var[@name='statut']" /></td>
                <td align="center"><xsl:value-of select="struct/var[@name='pageWebPerso']" /></td>
                <td align="center"><xsl:value-of select="struct/var[@name='pageWebGRMIAO']" /></td>
                <td align="center"><xsl:value-of select="struct/var[@name='photo']" /></td>
                <td align="center"><xsl:value-of select="struct/var[@name='distinctions']" /></td>
                <td align="center"><xsl:value-of disable-output-escaping="yes" select="php:function('format_implicationprojet', string(struct/var[@name='implicationprojet']))" /></td>
                <td>
     
                    <xsl:element name="input">
                        <xsl:attribute name="name">selection[]</xsl:attribute>
                        <xsl:attribute name="type">checkbox</xsl:attribute>
                        <xsl:attribute name="value"><xsl:value-of select="struct/var[@name='id']" /></xsl:attribute>
                    </xsl:element>
                </td>
            </tr>
        </xsl:template>
    </xsl:stylesheet>
    le fichier PHP qui va avec est celui la :
    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
    <?php
     
    function format_implicationprojet($str) {
        return str_replace('/', '<br />', $str); 
    }
     
    $dom=DomDocument::load("personnes.xsl");
    $proc= new XSLTProcessor;
    $proc->importStyleSheet($dom);
    $proc->registerPHPFunctions();
     
    $dom= new DomDocument;
    $dom->preserveWhiteSpace = FALSE;
    $dom->formatOutput = TRUE;
    $dom->load("personnes.xml");
     
    echo $proc->transformToXML($dom); 
    ?>
    jusque la tout va bien! et la fonction php marche trés bien! la dans l'image que j'ai mis au dessus, je selectionne une personne et je clique sur modifier

    voila ce que j'obtient :



    normalment j'obtient le formulaire mais la liste des personnes reste en bas, mais la j'ai cette erreur qui je pense est généré pour chaque ligne du tableau (cette erreur se repete une centaine de fois dans la page dont je viens de vous montrer une partie.

    le code qui va avec est le fichier del.php je vous montre l'essentiel de ce fichier :

    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
    
    <?php
    $fichier_xml = 'personnes.xml';
    $fichier_xsl = 'personnes.xsl';
    
    $fichier_xml2 = 'projets.xml';
    
    
     
    $dom = DomDocument::load($fichier_xsl);
    $proc = new XSLTProcessor;
    $proc->importStylesheet($dom);
    $proc->registerPHPFunctions();
     
    $dom = new DomDocument;
    $dom->preserveWhiteSpace = FALSE;
    $dom->formatOutput = TRUE;
    $dom->load($fichier_xml);
    
     
    $dom2 = new DomDocument;
    $dom2->preserveWhiteSpace = FALSE;
    $dom2->formatOutput = TRUE;
    $dom2->load($fichier_xml2);
    
    
    
     
    if (isset($_POST['action'])) {
        switch (strtolower($_POST['action'])) {
            case 'editer'://dans le cas d'une edition
    		
    				$proj= array();
    				$i=0;
    				$listeProjets = $dom2->getElementsByTagName('nom');
    				foreach ($listeProjets as $projets)
    				{
    					$proj[$i]= $projets->firstChild->nodeValue ;
    					$i++;
    				}
                if (is_array($_POST['selection'])) {
    				if ($fiche = getFicheById($dom, $_POST['selection'][0])) {
    				$id=$_POST['selection'][0];
    				if ($fiche->hasAttribute("type")) {
        					$type=$fiche->getAttribute("type");
        			}
    				
    				$nom=getVarByName($fiche, 'nom');
    				$prenom=getVarByName($fiche, 'prenom');
    				$statut=getVarByName($fiche, 'statut');
    				$pageWeb=getVarByName($fiche, 'pageWebPerso');
    				$pageWebGRMIAO=getVarByName($fiche, 'pageWebGRMIAO');
    				$photo=getVarByName($fiche, 'photo');
    				$distinctions=utf8_decode(getVarByName($fiche, 'distinctions'));
    				$implicationprojet=getVarByName($fiche, 'implicationprojet');
    				
    				$projets=split("/",$implicationprojet);
    				
    				
    				
    	//...ici j'ai le code du formulaire initialisé avec les valeurs ...
            case 'supprimer'://ici on clique sur le boutton supprimer
                if (is_array($_POST['selection'])) {
                    foreach ($_POST['selection'] as $id) {
                        if ($fiche = getFicheById($dom, $id)) {
                            $fiche->parentNode->removeChild($fiche);
                        } else {
                            die("Erreur au niveau de l'expression XPath");
                        }
                    }
    				
                }
                break;
        }
        $dom->save('personnes.xml');
    }
     
    echo $proc->transformToXML($dom);//l'erreur est ici
    ?>
    
    </body>
    </html>

    voila




    ...

  13. #13
    Expert éminent sénior

    Profil pro
    Inscrit en
    Juin 2002
    Messages
    6 152
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2002
    Messages : 6 152
    Points : 17 777
    Points
    17 777
    Par défaut
    Il faut que je rassemble le puzzle Vous avez deux fichiers XML, deux fichiers PHP et un fichier XSL ?

    Mais a priori, il vous manque votre fonction PHP format_implicationprojet dans votre deuxième fichier PHP.

  14. #14
    Membre régulier
    Profil pro
    Étudiant
    Inscrit en
    Février 2007
    Messages
    379
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2007
    Messages : 379
    Points : 123
    Points
    123
    Par défaut
    Citation Envoyé par julp Voir le message
    Il faut que je rassemble le puzzle Vous avez deux fichiers XML, deux fichiers PHP et un fichier XSL ?

    Mais a priori, il vous manque votre fonction PHP format_implicationprojet dans votre deuxième fichier PHP.

    le 2eme fichier XML est petit, et j'avais besoin seulement d'une petite lecture donc j'ai travaillé avec DOM ! et non pas le XSL
    le code est ci haut (dans le dernier code php)

    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
    $dom2 = new DomDocument;
    $dom2->preserveWhiteSpace = FALSE;
    $dom2->formatOutput = TRUE;
    $dom2->load($fichier_xml2);
     
    ...
     
     
    $proj= array();
    				$i=0;
    				$listeProjets = $dom2->getElementsByTagName('nom');
    				foreach ($listeProjets as $projets)
    				{
    					$proj[$i]= $projets->firstChild->nodeValue ;
    					$i++;
    				}
     
     
    ...

    voila

  15. #15
    Expert éminent sénior

    Profil pro
    Inscrit en
    Juin 2002
    Messages
    6 152
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2002
    Messages : 6 152
    Points : 17 777
    Points
    17 777
    Par défaut
    Citation Envoyé par Mo_Poly Voir le message
    le fichier PHP qui va avec est celui la :
    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
    <?php
    
    function format_implicationprojet($str) {
        return str_replace('/', '<br />', $str); 
    }
    
    $dom=DomDocument::load("personnes.xsl");
    $proc= new XSLTProcessor;
    $proc->importStyleSheet($dom);
    $proc->registerPHPFunctions();
    
    $dom= new DomDocument;
    $dom->preserveWhiteSpace = FALSE;
    $dom->formatOutput = TRUE;
    $dom->load("personnes.xml");
    
    echo $proc->transformToXML($dom); 
    ?>
    Celui-là rien à dire : on a bien la fonction ...

    Citation Envoyé par Mo_Poly Voir le message
    le code qui va avec est le fichier del.php je vous montre l'essentiel de ce fichier :

    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
    <?php
    $fichier_xml = 'personnes.xml';
    $fichier_xsl = 'personnes.xsl';
    
    $fichier_xml2 = 'projets.xml';
    
    
     
    $dom = DomDocument::load($fichier_xsl);
    $proc = new XSLTProcessor;
    $proc->importStylesheet($dom);
    $proc->registerPHPFunctions();
     
    $dom = new DomDocument;
    $dom->preserveWhiteSpace = FALSE;
    $dom->formatOutput = TRUE;
    $dom->load($fichier_xml);
    
     
    $dom2 = new DomDocument;
    $dom2->preserveWhiteSpace = FALSE;
    $dom2->formatOutput = TRUE;
    $dom2->load($fichier_xml2);
    
    
    
     
    if (isset($_POST['action'])) {
        switch (strtolower($_POST['action'])) {
            case 'editer'://dans le cas d'une edition
    		
    				$proj= array();
    				$i=0;
    				$listeProjets = $dom2->getElementsByTagName('nom');
    				foreach ($listeProjets as $projets)
    				{
    					$proj[$i]= $projets->firstChild->nodeValue ;
    					$i++;
    				}
                if (is_array($_POST['selection'])) {
    				if ($fiche = getFicheById($dom, $_POST['selection'][0])) {
    				$id=$_POST['selection'][0];
    				if ($fiche->hasAttribute("type")) {
        					$type=$fiche->getAttribute("type");
        			}
    				
    				$nom=getVarByName($fiche, 'nom');
    				$prenom=getVarByName($fiche, 'prenom');
    				$statut=getVarByName($fiche, 'statut');
    				$pageWeb=getVarByName($fiche, 'pageWebPerso');
    				$pageWebGRMIAO=getVarByName($fiche, 'pageWebGRMIAO');
    				$photo=getVarByName($fiche, 'photo');
    				$distinctions=utf8_decode(getVarByName($fiche, 'distinctions'));
    				$implicationprojet=getVarByName($fiche, 'implicationprojet');
    				
    				$projets=split("/",$implicationprojet);
    				
    				
    				
    	//...ici j'ai le code du formulaire initialisé avec les valeurs ...
            case 'supprimer'://ici on clique sur le boutton supprimer
                if (is_array($_POST['selection'])) {
                    foreach ($_POST['selection'] as $id) {
                        if ($fiche = getFicheById($dom, $id)) {
                            $fiche->parentNode->removeChild($fiche);
                        } else {
                            die("Erreur au niveau de l'expression XPath");
                        }
                    }
    				
                }
                break;
        }
        $dom->save('personnes.xml');
    }
     
    echo $proc->transformToXML($dom);//l'erreur est ici
    ?>
    
    </body>
    </html>
    En revanche, elle n'y est pas dans celui-là, d'après ce que vous donnez, alors qu'il en a besoin lors de la transformation, que vous demandez à la fin du script.

  16. #16
    Membre régulier
    Profil pro
    Étudiant
    Inscrit en
    Février 2007
    Messages
    379
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2007
    Messages : 379
    Points : 123
    Points
    123
    Par défaut
    oui c'etait ca fallait mettre la fonction dans l'autre fichier aussi


    merci



    ...

  17. #17
    Membre averti Avatar de dacid
    Homme Profil pro
    Inscrit en
    Juin 2003
    Messages
    1 064
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 1 064
    Points : 420
    Points
    420
    Par défaut
    Les messages de Warning
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Warning: XSLTProcessor::transformToXml() [function.XSLTProcessor-transformToXml]: xsltExtFunctionTest: PHP Object did not register PHP functions in C:\Documents and Settings\mo\Mes documents\html\del.php on line 226
    viennent du fait que vous essayez de lier une XSL à un XML qui en a déjà une de déclarée dans son entête:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <?xml-stylesheet href="init.xsl" type="text/xsl"?>

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

Discussions similaires

  1. appeler une fonction php dans une fonction javaScript
    Par geeksDeve dans le forum Langage
    Réponses: 3
    Dernier message: 17/04/2012, 15h30
  2. Réponses: 10
    Dernier message: 14/03/2009, 13h36
  3. Réponses: 18
    Dernier message: 27/10/2006, 14h15
  4. [PHP-JS] une variable php dans une fonction javascript
    Par megapacman dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 12/06/2006, 14h08
  5. [PHP-JS] une variable php dans une fonction javascript
    Par megapacman dans le forum Langage
    Réponses: 3
    Dernier message: 12/06/2006, 14h02

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