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 :

débutant - Mise en forme document


Sujet :

XSL/XSLT/XPATH XML

  1. #1
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2017
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Aisne (Picardie)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2017
    Messages : 8
    Points : 2
    Points
    2
    Par défaut débutant - Mise en forme document
    Bonjour,
    Je débute avec XML/XSD/XSLT.
    J'aurais aimé mettre en forme ce document de façon très simple :

    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
    <?xml version="1.0" encoding="utf-8"?>
    <?xml-stylesheet type="text/xsl" href="intervention-new.xsl"?>
     
    <intervention
    xmlns="http://www.w3schools.com"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.w3schools.com intervention-new.xsd">
     
    	<nomintervention>Vidange</nomintervention>
     
    	<nombreemecaniciens>1</nombreemecaniciens>
     
    	<dureetauxhoraire1 unite="heures">1</dureetauxhoraire1>
     
    	<dureetauxhoraire2 unite="heures">0</dureetauxhoraire2>	
     
    	<materiel>
     
    		<piece>
    			<quantite unite="filtre">1</quantite>
    			<nompiece>filtre</nompiece>
    		</piece>
     
    		<piece>
    			<quantite unite="joint">1</quantite>
    			<nompiece>joint</nompiece>
    		</piece>
     
    		<piece>
    			<quantite unite="litre">4</quantite>
    			<nompiece>huile</nompiece>			
    		</piece>
     
    	</materiel>
     
    	<instructions>
    		<etape>Dévisser le bouchon de vidange à l'aide d'une clé de 13</etape>
    		<etape>Faire couler l'huile usagée</etape>
    		<etape>Revisser le bouchon de vidange</etape>
    		<etape>Dévisser le bouchon moteur et vider l'huile neuve</etape>
    		<etape>Faire le niveau et reboucher</etape>
    	</instructions>
     
    </intervention>
    J'ai écrit ce document XSLT, mais je n'arrive pas à récupérer les données :

    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
    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    	<table width="100%" border="1">		
    		<tr>
    			<td colspan="2"><xsl:value-of select="nomintervention"/></td>
    		</tr>			
    		<tr>
    			<td width="50%">Nombre de mécaniciens : </td>
    			<td><xsl:value-of select="nombreemecaniciens"/></td>
    		</tr>			
    		<tr>
    			<td>Durée au taux horaire 1 : </td>
    			<td><xsl:value-of select="dureetauxhoraire1"/><xsl:value-of select="dureetauxhoraire1/@unite"/></td>
    		</tr>			
    		<tr>
    			<td>Durée au taux horaire 2 : </td>
    			<td><xsl:value-of select="dureetauxhoraire2"/><xsl:value-of select="dureetauxhoraire1/@unite"/></td>
    		</tr>			
    		<tr>
    			<td colspan="2">Matériel : </td>
    		</tr>		
    		<xsl:for-each select="intervention/materiel/piece">
    		<tr>
    			<td colspan="2"><xsl:value-of select="quantite"/><xsl:value-of select="quantite/@unite"/><xsl:value-of select="nompiece"/></td>
    		</tr>
    		</xsl:for-each>		
    		<tr>
    			<td colspan="2">Instructions : </td>
    		</tr>		
    		<xsl:for-each select="intervention/instructions">
    		<tr>
    			<td colspan="2"><xsl:value-of select="etape"/></td>
    		</tr>
    		</xsl:for-each>			
    	</table>
    </xsl:template>
    </xsl:stylesheet>
    Voyez-vous ce qui ne va pas ?
    Merci beaucoup pour votre aide.

  2. #2
    Membre actif
    Homme Profil pro
    Chargé d'affaire
    Inscrit en
    Avril 2007
    Messages
    199
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Chargé d'affaire
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2007
    Messages : 199
    Points : 297
    Points
    297
    Par défaut
    Avec ca ca fonctionne :

    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
    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="intervention.xsl"?>
    <intervention>
    	<nomintervention>Vidange</nomintervention>
    	<nombreemecaniciens>1</nombreemecaniciens>
    	<dureetauxhoraire1 unite="heures">1</dureetauxhoraire1>
    	<dureetauxhoraire2 unite="heures">0</dureetauxhoraire2>
    	<materiel>
    		<piece>
    			<quantite unite="filtre">1</quantite>
    			<nompiece>filtre</nompiece>
    		</piece>
    		<piece>
    			<quantite unite="joint">1</quantite>
    			<nompiece>joint</nompiece>
    		</piece>
    		<piece>
    			<quantite unite="litre">4</quantite>
    			<nompiece>huile</nompiece>
    		</piece>
    	</materiel>
    	<instructions>
    		<etape>Dévisser le bouchon de vidange à l'aide d'une clé de 13</etape>
    		<etape>Faire couler l'huile usagée</etape>
    		<etape>Revisser le bouchon de vidange</etape>
    		<etape>Dévisser le bouchon moteur et vider l'huile neuve</etape>
    		<etape>Faire le niveau et reboucher</etape>
    	</instructions>
    </intervention>
    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
    <?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" media-type="text/html" omit-xml-declaration="yes" indent="yes" encoding="UTF-8" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"/>
    	<xsl:template match="/">
     
    	<html>
    		<head>
    			<title><xsl:value-of select="/intervention/nomintervention"/></title>
    		</head>
    		<body>
     
    	<xsl:for-each select="intervention">
    			<table width="100%" border="1">
    			<tr>
    				<td colspan="2">
    					<xsl:value-of select="nomintervention"/>
    				</td>
    			</tr>
    			<tr>
    				<td width="50%">Nombre de mécaniciens : </td>
    				<td>
    					<xsl:value-of select="nombreemecaniciens"/>
    				</td>
    			</tr>
    			<tr>
    				<td>Durée au taux horaire 1 : </td>
    				<td>
    					<xsl:value-of select="dureetauxhoraire1"/>
    					<xsl:value-of select="dureetauxhoraire1/@unite"/>
    				</td>
    			</tr>
    			<tr>
    				<td>Durée au taux horaire 2 : </td>
    				<td>
    					<xsl:value-of select="dureetauxhoraire2"/>
    					<xsl:value-of select="dureetauxhoraire1/@unite"/>
    				</td>
    			</tr>
    			<tr>
    				<td colspan="2">Matériel : </td>
    			</tr>
    			<xsl:for-each select="materiel/piece">
    				<tr>
    					<td colspan="2">
    						<xsl:value-of select="quantite"/>
    						<xsl:value-of select="quantite/@unite"/>
    						<xsl:value-of select="nompiece"/>
    					</td>
    				</tr>
    			</xsl:for-each>
    			<tr>
    				<td colspan="2">Instructions : </td>
    			</tr>
    			<xsl:for-each select="instructions">
    				<tr>
    					<td colspan="2">
    						<xsl:value-of select="etape"/>
    					</td>
    				</tr>
    			</xsl:for-each>
    		</table>
     
     
    </xsl:for-each>		
     
    </body>
    </html>
     
     
    	</xsl:template>
     
     
     
     
    </xsl:stylesheet>
    "Chuck Norris a déjà compté jusqu'à l'infini. Deux fois."

  3. #3
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2017
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Aisne (Picardie)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2017
    Messages : 8
    Points : 2
    Points
    2
    Par défaut
    Merci beaucoup pour ta réponse caballo.

    Ca fonctionne quasi parfaitement. En fait pour la partie instructions il n'y a que la première étape d'affichée, et pas tout l'ensemble. Le code me parait pourtant logique, je ne comprends pas.

    Sinon, comment écrire l'en-tête du fichier xml pour qu'il y ait toujours la référence vers le fichier xsd ? Apparemment j'avais mal écrit l'entête.

  4. #4
    Membre actif
    Homme Profil pro
    Chargé d'affaire
    Inscrit en
    Avril 2007
    Messages
    199
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Chargé d'affaire
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2007
    Messages : 199
    Points : 297
    Points
    297
    Par défaut
    Il faut pour cela que tu fasses une boucle sur la balise de type etape et afficher sa valeur

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    			<xsl:for-each select="instructions/etape">
    				<tr>
    					<td colspan="2">
    						<xsl:value-of select="."/>
    					</td>
    				</tr>
    			</xsl:for-each>
    Pour le XSD par exemple :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <intervention xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:///C:/intervention.xsd">
    "Chuck Norris a déjà compté jusqu'à l'infini. Deux fois."

  5. #5
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2017
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Aisne (Picardie)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2017
    Messages : 8
    Points : 2
    Points
    2
    Par défaut
    Merci, effectivement ça fonctionne avec ce nouveau code.
    Par contre je ne comprends pas pourquoi sur la liste d'avant on pouvait se permettre de rester une balise au dessus (<piece>), et de spécifier ensuite la balise concernée dans le value-of-select ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    		<xsl:for-each select="intervention/materiel/piece">
    		<tr>
    			<td colspan="2"><xsl:value-of select="quantite"/><xsl:value-of select="quantite/@unite"/><xsl:value-of select="nompiece"/></td>
    		</tr>
    		</xsl:for-each>
    Pour le lien XSD, si je comprends bien, on met dans le fichier XML le code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <intervention xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:///C:/intervention.xsd">
    à la place de <intervention> ?

  6. #6
    Membre actif
    Homme Profil pro
    Chargé d'affaire
    Inscrit en
    Avril 2007
    Messages
    199
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Chargé d'affaire
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2007
    Messages : 199
    Points : 297
    Points
    297
    Par défaut
    Pour le point 1, il te faut comprendre comment fonctionne les XPATH (voir le tutoriel en tête de ce forum).

    Pour le point 2, oui, à toi d'adapter xsi:noNamespaceSchemaLocation="file:///C:/intervention.xsd" en fonction de ce que tu veux faire.
    "Chuck Norris a déjà compté jusqu'à l'infini. Deux fois."

  7. #7
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2017
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Aisne (Picardie)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2017
    Messages : 8
    Points : 2
    Points
    2
    Par défaut
    Merci beaucoup, je vais regarder les XPATH pour essayer de comprendre.

    Par contre si ma feuille XSLT fonctionne parfaitement à présent avec le code XML, j'ai un problème de validation avec mon XSD
    Son en-tête est la suivante :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3schools.com" xmlns="http://www.w3schools.com" elementFormDefault="qualified">
    Que dois-je changer dans le XML et éventuellement dans le XSL pour que ça fonctionne avec mon XSD ?

  8. #8
    Membre actif
    Homme Profil pro
    Chargé d'affaire
    Inscrit en
    Avril 2007
    Messages
    199
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Chargé d'affaire
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2007
    Messages : 199
    Points : 297
    Points
    297
    Par défaut
    Essaye avec :


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
    "Chuck Norris a déjà compté jusqu'à l'infini. Deux fois."

  9. #9
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2017
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Aisne (Picardie)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2017
    Messages : 8
    Points : 2
    Points
    2
    Par défaut
    Merci pour ton aide, cela fonctionne à présent.

Discussions similaires

  1. [LabView 8.5][Débutant] Mise en forme d'un signal
    Par geoffrey.ru dans le forum LabVIEW
    Réponses: 1
    Dernier message: 21/04/2008, 17h01
  2. [Débutant]-Mise en forme simpliste
    Par bdaboah dans le forum AWT/Swing
    Réponses: 4
    Dernier message: 24/12/2007, 17h32
  3. [Débutant] Mise en forme avec XSL
    Par sidahmed dans le forum XSL/XSLT/XPATH
    Réponses: 13
    Dernier message: 24/09/2007, 14h57
  4. [CR9-Débutant] Création et mise en forme
    Par jbrasselet dans le forum SAP Crystal Reports
    Réponses: 1
    Dernier message: 03/08/2007, 09h19
  5. Mise en forme : changer la police du texte de mon document
    Par mmb04 dans le forum Mise en forme
    Réponses: 2
    Dernier message: 08/06/2007, 13h35

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