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 :

transformer schema xml html


Sujet :

XSL/XSLT/XPATH XML

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Février 2009
    Messages
    330
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Février 2009
    Messages : 330
    Points : 93
    Points
    93
    Par défaut transformer schema xml html
    Bonjour voici un bout de schema 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
    <analyse>
    	<s xml:lang="fr" id="0">
    		<phr type="DP" function="subj" level="0">
    			<w type="det" lemma="le">Le</w>
    			<w type="adj" lemma="joli">joli</w>
    			<w type="nom" lemma="chat">chat</w>
     
    			<phr type="" function="D-obj" level="1">
    				<w type="pro" lemma="que">que</w>
    			</phr>
     
    			<phr type="" function="subj" level="1">
    				<w type="nom" lemma="je">j'</w>
    			</phr>
     
    			<phr type="" function="predicate" level="1">
    				<w type="aux" lemma="avoir">ai</w>
    				<phr type="" function="CC" level="2">
    					<w type="adv" lemma="gentiment">gentiment</w>
    				</phr>
    				<w type="partpass" lemma="adopter">adopté</w>
    			</phr>
    		</phr>
    </analyse>
    voici mon debut de code xslt :

    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
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:tei="http://www.tei-c.org/ns/1.0" xmlns="http://www.tei-c.org/ns/1.0" version="1.0">
     
        <xsl:output encoding="UTF-8" method="html" indent="yes" doctype-public=""/>
     
        <xsl:template match="analyse/s">
            <html>
                <head> </head>
                <body>
                    <div>
                        <xsl:for-each select="phr">
                            <xsl:element name="span">
                                <xsl:attribute name="class">
                                    <xsl:value-of select="@function"/>
                                    <xsl:value-of select="@level"/>
                                </xsl:attribute>
                                <xsl:apply-templates select="node()"/>
                            </xsl:element>
     
                        </xsl:for-each>
                    </div>
                </body>
            </html>
        </xsl:template>
     
    </xsl:stylesheet>
    le resultat est :
    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
    <span class="subj0">
    			Le
    			joli
    			chat
     
     
    				que
     
     
     
    				j'
     
     
     
    				ai
     
    					gentiment
     
    				adopté
     
    		</span>
    le soucis est que je voudrai avoir ce resultat :
    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
    <span class="subj0">
    			Le
    			joli
    			chat
     
     
    				<span class="D-obj1"> que</span>
     
     
     
    				<span class="subj1">j'</span>
     
     
     
    				<span class="predicate1"> ai
     
    					 <span class="CC2">gentiment</span>
     
    				adopté
    			        </span>
    		</span>
    je narrive pas a recuperer les noeud enfant de phr apparament

    merci

  2. #2
    Membre à l'essai
    Profil pro
    Inscrit en
    Février 2010
    Messages
    8
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2010
    Messages : 8
    Points : 10
    Points
    10
    Par défaut
    C'est mieux d'éviter les for-each quand ils ne sont pas nécessaires :
    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
     
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:tei="http://www.tei-c.org/ns/1.0" xmlns="http://www.tei-c.org/ns/1.0" version="1.0">
     
        <xsl:output encoding="UTF-8" method="html" indent="yes" doctype-public=""/>
     
        <xsl:template match="analyse">
            <html>
                <head> </head>
                <body>
                    <div>
                        <xsl:apply-templates />
                    </div>
                </body>
            </html>
        </xsl:template>
        <xsl:template match="phr">
                            <xsl:element name="span">
                                <xsl:attribute name="class">
                                    <xsl:value-of select="@function"/>
                                    <xsl:value-of select="@level"/>
                                </xsl:attribute>
                                <xsl:apply-templates select="node()"/>
                            </xsl:element>
        </xsl:template>
     
    </xsl:stylesheet>

  3. #3
    Membre régulier
    Profil pro
    Inscrit en
    Février 2009
    Messages
    330
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Février 2009
    Messages : 330
    Points : 93
    Points
    93
    Par défaut
    Citation Envoyé par datrinite Voir le message
    C'est mieux d'éviter les for-each quand ils ne sont pas nécessaires :
    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
     
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:tei="http://www.tei-c.org/ns/1.0" xmlns="http://www.tei-c.org/ns/1.0" version="1.0">
     
        <xsl:output encoding="UTF-8" method="html" indent="yes" doctype-public=""/>
     
        <xsl:template match="analyse">
            <html>
                <head> </head>
                <body>
                    <div>
                        <xsl:apply-templates />
                    </div>
                </body>
            </html>
        </xsl:template>
        <xsl:template match="phr">
                            <xsl:element name="span">
                                <xsl:attribute name="class">
                                    <xsl:value-of select="@function"/>
                                    <xsl:value-of select="@level"/>
                                </xsl:attribute>
                                <xsl:apply-templates select="node()"/>
                            </xsl:element>
        </xsl:template>
     
    </xsl:stylesheet>
    merci de la réponse. c'est prometteur. j'ai trouvé une alternative en php mais je serai curieux de savoir si je peux obtenir mon resultat en xslt.
    en fait je voudrai rajouter un niveau pour obtenir au final :
    (cf un bout de fichier 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
     
    <span class="Subj0">
    			<span class="det" title="det">Le</span>
    			<span class="adj" title="adj">joli</span>
    			<span class="nom" title="nom">chat</span>
     
     
    			<span class="DO1">
    				<span class="pro" title="pro">que</span>
     
    			</span>
     
    			<span class="Subj1">
    				<span class="nom" title="nom">j'</span>
     
    			</span>
     
    			<span class="predicate1">
    				<span class="aux" title="aux">ai</span>
     
    				<span class="CC2">
    					<span class="adv"title="adv">gentiment</span>
     
    				</span>
    				<span class="partpass" title="partpass">adopté</span>
     
    			</span>
    		</span>
    merci

  4. #4
    Membre régulier
    Profil pro
    Inscrit en
    Février 2009
    Messages
    330
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Février 2009
    Messages : 330
    Points : 93
    Points
    93
    Par défaut
    finalement je crois avoir trouvé !
    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
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:tei="http://www.tei-c.org/ns/1.0" xmlns="http://www.tei-c.org/ns/1.0" version="1.0">
     
        <xsl:output encoding="UTF-8" method="html" indent="yes" doctype-public=""/>
     
        <xsl:template match="analyse">
            <html>
                <head> </head>
                <body>
                    <div>
                        <xsl:apply-templates />
                    </div>
                </body>
            </html>
        </xsl:template>
        <xsl:template match="phr">
            <xsl:element name="span">
                <xsl:attribute name="class">
                    <xsl:value-of select="@function"/>
                    <xsl:value-of select="@n"/>
                </xsl:attribute>
     
                <xsl:apply-templates select="node()"/>
            </xsl:element>
       </xsl:template>
        <xsl:template match="w">
            <xsl:element name="span">
                <xsl:attribute name="class">
                    <xsl:value-of select="@type"/>   
                </xsl:attribute>
     
                <xsl:apply-templates select="node()"/>
            </xsl:element>
     
        </xsl:template>
    </xsl:stylesheet>

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

Discussions similaires

  1. HTML épuré puis transformé en XML
    Par kdick dans le forum Format d'échange (XML, JSON...)
    Réponses: 4
    Dernier message: 20/04/2007, 15h24
  2. [XSLT] Transformer un xml en HTML : problème sur les liens
    Par elhout dans le forum XSL/XSLT/XPATH
    Réponses: 2
    Dernier message: 19/03/2007, 10h46
  3. [XSLT][>HTML] transformer un XML
    Par ouiam dans le forum XSL/XSLT/XPATH
    Réponses: 11
    Dernier message: 25/07/2006, 17h59
  4. [VB.NET] Transformation XML -> HTML
    Par marsu381 dans le forum ASP.NET
    Réponses: 7
    Dernier message: 27/09/2005, 10h38
  5. [XSLT] [XML->HTML] transformation XML -> HTML via XSL
    Par Great Sayaman dans le forum XSL/XSLT/XPATH
    Réponses: 4
    Dernier message: 11/12/2004, 22h12

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