Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
3145 connectés 

  FORUM HardWare.fr
  Programmation
  XML/XSL

  Est ce possible de faire ça ?

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Est ce possible de faire ça ?

n°1202468
sbucci2
Posté le 19-09-2005 à 14:55:45  profilanswer
 

Bonjour,
 
Alors voila mon soucis, mon but global est d'écrire un fichier xsl
 
J'ai un fichier final qui ressemble à cela :
La structure du fichier ne peut pas être modiffier

Code :
  1. -- KWORD  AP_ID MNEMONIC NB_OBSERVABLES MNEMO_OBS BYTE_OFFSET BIT_OFFSET
  2. --
  3. INFOS_PAQUETS_TM_CYCLIC_4HZ 96 MCOPROP 4 MCDELTAW 0 7
  4. INFOS_PAQUETS_TM_CYCLIC_4HZ 96 MCOPROP 4 TMGYRX 24 7
  5. INFOS_PAQUETS_TM_CYCLIC_4HZ 96 MCOPROP 4 TMGYRY 27 7
  6. INFOS_PAQUETS_TM_CYCLIC_4HZ 96 MCOPROP 4 TMGYRZ 30 7


 
J'ai ecris un fichier xml à la main qui devrait ressembler à ca au final :
 

Code :
  1. <?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
  2. <?xml-stylesheet href="proto.xsl"?>
  3. <!DOCTYPE LV [
  4. <!ELEMENT LV (TYPE)>
  5. <!ELEMENT TYPE (DESC, LIGNE+)>
  6. <!ELEMENT LIGNE (APID, MNEMO, NB, OBSERVABLES)>
  7. <!ELEMENT OBSERVABLES (OBSERVABLE+)>
  8. <!ELEMENT OBSERVABLE (LIBELLE, BYTEOFFSET, BITOFFSET)>
  9. <!ELEMENT DESC (#PCDATA)>
  10. <!ELEMENT APID (#PCDATA)>
  11. <!ELEMENT MNEMO (#PCDATA)>
  12. <!ELEMENT NB (#PCDATA)>
  13. <!ELEMENT LIBELLE (#PCDATA)>
  14. <!ELEMENT BYTEOFFSET (#PCDATA)>
  15. <!ELEMENT BITOFFSET (#PCDATA)>
  16. ]>
  17. <LV>
  18. <TYPE>
  19.  <DESC>INFOS_PAQUETS_TM_CYCLIC_1HZ</DESC>
  20.  <LIGNE>
  21.   <APID>1</APID>
  22.   <MNEMO>PMODESAT</MNEMO>
  23.   <NB>4</NB>
  24.   <OBSERVABLES>
  25.    <OBSERVABLE>
  26.     <LIBELLE>MCDELTAW</LIBELLE>
  27.     <BYTEOFFSET>24</BYTEOFFSET>
  28.     <BITOFFSET>7</BITOFFSET>
  29.    </OBSERVABLE>
  30.    <OBSERVABLE>
  31.     <LIBELLE>TMGYRX</LIBELLE>
  32.     <BYTEOFFSET>3</BYTEOFFSET>
  33.     <BITOFFSET>7</BITOFFSET>
  34.    </OBSERVABLE>
  35.    <OBSERVABLE>
  36.     <LIBELLE>TMGYRY</LIBELLE>
  37.     <BYTEOFFSET>3</BYTEOFFSET>
  38.     <BITOFFSET>7</BITOFFSET>
  39.    </OBSERVABLE>
  40.    <OBSERVABLE>
  41.     <LIBELLE>TMGYRZ</LIBELLE>
  42.     <BYTEOFFSET>3</BYTEOFFSET>
  43.     <BITOFFSET>7</BITOFFSET>
  44.    </OBSERVABLE>
  45.   </OBSERVABLES>
  46.  </LIGNE>
  47. </TYPE>
  48. </LV>


 
La colonne BYTE_OFFSET est la somme des valeurs <BYTEOFFSET></BYTEOFFSET>.
 
Est ce possible de faire ça avec un xsl. Je débute en xml/xsl et je sais po du tt par ou commencer.
Si vous avez un exemple de xsl qui pourrait ressembler au mien je suis preneur
 
Merci de votre aide.


Message édité par sbucci2 le 19-09-2005 à 16:50:38
mood
Publicité
Posté le 19-09-2005 à 14:55:45  profilanswer
 

n°1202521
sbucci2
Posté le 19-09-2005 à 15:44:47  profilanswer
 

up

n°1202594
avander
Posté le 19-09-2005 à 16:32:08  profilanswer
 

faut regarder du côté des axes xpath et en particulier l'axe preceding-sibling::

n°1202626
avander
Posté le 19-09-2005 à 17:09:20  profilanswer
 

c'est possible, le stylesheet:

<?xml version="1.0" encoding="ISO-8859-1"?>
 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
  <xsl:output
    method="xml" omit-xml-declaration="yes" indent="yes" encoding="ISO-8859-1"
    doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
 
<xsl:template match="/">
  <html>
    <head />
    <body>
      <table border="1">
        <!-- entete de la table -->  
        <tr>
          <td />
          <td>BYTEOFFSET</td>
          <td>BITOFFSET</td>
        </tr>
        <xsl:apply-templates select="//BYTEOFFSET" />    
      </table>
    </body>
  </html>
</xsl:template>  
 
<xsl:template match="BYTEOFFSET">
  <tr>
    <td>
      <xsl:value-of select="preceding-sibling::LIBELLE[1]" />
    </td>
    <td>
      <xsl:value-of select="sum( preceding-sibling::BYTEOFFSET)" />
    </td>
    <td>
      <xsl:value-of select="following-sibling::BITOFFSET[1]" />
    </td>
  </tr>
</xsl:template>
</xsl:stylesheet>  
<!-- eof -->


 
qui donnera:

BYTEOFFSET  BITOFFSET
MCDELTAW  0  7
TMGYRX  24  7
TMGYRY  27  7
TMGYRZ  30  7

n°1202693
sbucci2
Posté le 19-09-2005 à 18:09:05  profilanswer
 

Merci bcp.
 
Puis je abusé un peu ?
Ton xsl marche tres bien avec le fichier xml que j ai donné tout à l heure mais j ai rajoute une subdivision dans observable.
Qu est ce qui faut modifier à ton script pour qu il marche de nouveau ?
 
Encore merci

n°1202789
avander
Posté le 19-09-2005 à 21:13:39  profilanswer
 

J'ai failli te faire a remarque que la structure n'était pas top, qu'il fallait rajouter un niveau vu les répétitions dans 'observables'... j'ai passé outre puisque le xsl était d'autant plus simple, en effet dans la première structure les BYTEOFFSET étaient de vrais 'frères', en introduisant un niveau supplémentaire ils ne sont plus que 'cousins'...  
 
il faut donc un peu repenser l'approche du xsl...

n°1203465
sbucci2
Posté le 20-09-2005 à 15:12:41  profilanswer
 

j'ai résussi à faire cela :
mais je n'arrive à adapter ton script de la somme à mon xsl
 
peux tu m aider ?
 
merci
 

Code :
  1. <?xml version='1.0' encoding='ISO-8859-1' ?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  3. <xsl:output method="text" indent="no" encoding="ISO-8859-1"/>
  4. <xsl:template match="/">
  5.  <xsl:for-each select="LV/TYPE">
  6.   <xsl:for-each select="LIGNE">
  7.    <xsl:for-each select="OBSERVABLES/OBSERVABLE">
  8.     <xsl:value-of select="../../../DESC"/><xsl:text>&#09;</xsl:text>
  9.     <xsl:value-of select="../../APID"/><xsl:text>&#09;</xsl:text>
  10.     <xsl:value-of select="../../NB"/><xsl:text>&#09;</xsl:text>
  11.     <xsl:value-of select="LIBELLE"/><xsl:text>&#09;</xsl:text>
  12.     <xsl:value-of select="BYTEOFFSET"/><xsl:text>&#09;</xsl:text>
  13.     <xsl:value-of select="BITOFFSET"/><xsl:text>
  14. </xsl:text>
  15.    </xsl:for-each>
  16.   </xsl:for-each>
  17.  </xsl:for-each>
  18. </xsl:template>
  19. </xsl:stylesheet>


Message édité par sbucci2 le 20-09-2005 à 15:18:46
n°1203509
avander
Posté le 20-09-2005 à 15:39:15  profilanswer
 

trois <xsl:for-each> imbriqués... pourquoi tant de haine?  :ange:  

n°1203519
sbucci2
Posté le 20-09-2005 à 15:46:44  profilanswer
 

je debute en xsl, et je ne sais pas comment faire autrement car à terme il y aura N lignes dans X types  :o
Sinon une idée, une piste ?
 
merci


Message édité par sbucci2 le 20-09-2005 à 15:47:41
n°1203540
avander
Posté le 20-09-2005 à 15:57:10  profilanswer
 

Ce n'est pas un reproche, tous les débuts sont durs, mais le fait d'abuser d'<xsl:for-each> démontre surtout qu'on a pas compris, voir pas pris la peine de comprendre le fonctionnement d'un moteur XSLT... tant qu'on a pas vu cette lumière on galère en XSLT, enfin soit, c'est un mal ( très) répandu.
 
La modif est finalement moins grande que prévue...  
 

<?xml version="1.0" encoding="ISO-8859-1"?>
 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
  <xsl:output
    method="xml" omit-xml-declaration="yes" indent="yes" encoding="ISO-8859-1"
    doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
 
<xsl:template match="/">
  <html>
    <head />
    <body>
      <table border="1">
        <!-- entete de la table -->  
        <tr>
          <td>deuxième edition</td>
          <td>BYTEOFFSET</td>
          <td>BITOFFSET</td>
        </tr>
        <xsl:apply-templates select="//OBSERVABLE" />    
      </table>
    </body>
  </html>
</xsl:template>  
 
<xsl:template match="OBSERVABLE">
  <tr>
    <td>
      <xsl:value-of select="./LIBELLE" />
    </td>
    <td>
      <xsl:value-of select="sum( preceding-sibling::OBSERVABLE/BYTEOFFSET)" />
    </td>
    <td>
      <xsl:value-of select="./BITOFFSET" />
    </td>
  </tr>
</xsl:template>
 
</xsl:stylesheet>  
<!-- eof -->


 
Si tu es maitre du format xml il vaut mieux adopter des noms de balise en minuscules...  

mood
Publicité
Posté le 20-09-2005 à 15:57:10  profilanswer
 

n°1203548
sbucci2
Posté le 20-09-2005 à 16:01:15  profilanswer
 

j en suis mettre en effet, pourquoi le mettre en minuscule ?
 
encore merci pour ton aide  :jap:


Message édité par sbucci2 le 20-09-2005 à 16:01:30
n°1203557
sbucci2
Posté le 20-09-2005 à 16:08:50  profilanswer
 

plus que 2 for each  :)  
 

Code :
  1. <?xml version='1.0' encoding='ISO-8859-1' ?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  3. <xsl:output method="text" indent="no" encoding="ISO-8859-1"/>
  4. <xsl:template match="/">
  5.  <xsl:for-each select="LV/TYPE">
  6.   <xsl:for-each select="LIGNE">
  7.     <xsl:apply-templates select="//OBSERVABLE" />   
  8.   </xsl:for-each>
  9.  </xsl:for-each>
  10. </xsl:template>
  11. <xsl:template match="OBSERVABLE">
  12.  <xsl:value-of select="../../../DESC"/><xsl:text>&#09;</xsl:text>
  13.  <xsl:value-of select="../../APID"/><xsl:text>&#09;</xsl:text>
  14.  <xsl:value-of select="../../NB"/><xsl:text>&#09;</xsl:text>
  15.  <xsl:value-of select="./LIBELLE" /><xsl:text>&#09;</xsl:text>
  16.  <xsl:value-of select="sum( preceding-sibling::OBSERVABLE/BYTEOFFSET)" /><xsl:text>&#09;</xsl:text>
  17.  <xsl:value-of select="./BITOFFSET" /><xsl:text>
  18. </xsl:text>
  19. </xsl:template>
  20. </xsl:stylesheet>

n°1203572
avander
Posté le 20-09-2005 à 16:23:34  profilanswer
 


:lol: encore 2 en trop alors...  
 


<xsl:template match="/">
   <xsl:apply-templates select="//OBSERVABLE" />    
</xsl:template>


 
Le select="//OBSERVABLE" demande au moteur XSLT de parcourir tout le xml et de chercher une correspondance dans le stylesheet uniquement pour les noeuds OBSERVABLE et ce à n'importe quel niveau de la structure...  

n°1203601
sbucci2
Posté le 20-09-2005 à 16:48:25  profilanswer
 

:jap:  :jap:  :jap:

n°1203608
avander
Posté le 20-09-2005 à 16:58:20  profilanswer
 

pas de quoi, sinon ma remarque concernant les minuscules est inspirée par l'analogie avec l'évolution HTML ( balises en majuscules) vers le XHTML ( balises en minuscules obligatoirement)...


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  XML/XSL

  Est ce possible de faire ça ?

 

Sujets relatifs
Simulation d'un envoi demail possible ?Dreamweaver : Zones réactives sur des images en *.gif, est-ce possible
url rewriting probleme - dossiers -> variable, possible ?[javascript] possible de savoir l'index de window.history ?
Images survolées en PHP, est-ce possible?Est il possible de savoir quant un fichier mdb est en phase de synchro
Est-il possible de mettre un composant "MonthCalendar" dans une Toobaruploader un fichier par mail c possible ?
Demo Atari Amiga etc... et sur PC possible?Comment est ce possible.
Plus de sujets relatifs à : Est ce possible de faire ça ?


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR