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

  FORUM HardWare.fr
  Programmation
  XML/XSL

  peut simplifier cette boucle

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

peut simplifier cette boucle

n°1203963
xiluoc
un pc pour les unirs ....
Posté le 21-09-2005 à 08:35:23  profilanswer
 

:hello: ,
 

Code :
  1. <table style= "padding: 5px; " border='0' cellspacing='0' cellpadding='2'>
  2. <tr style= " background-color: #50b56d;" >
  3.  <th style = "border-right: 1px white solid; padding-left: 5px; padding-right: 5px;">Id</th>
  4.  <th style = "border-right: 1px white solid; padding-left: 5px; padding-right: 5px;">TestScript</th>
  5.  <th style = "border-right: 1px white solid; padding-left: 5px; padding-right: 5px;">Thread</th>
  6.  <th style = "border-right: 1px white solid; padding-left: 5px; padding-right: 5px;">User</th>
  7.  <th>Event</th>
  8.  <th>Response</th>
  9.  <th>ActualResponse</th>
  10.  <th>Validity</th>
  11.  <th>Timing</th>
  12.  <th>Date</th>
  13.  <th>Hour</th>
  14. </tr>
  15. <xsl:for-each select="log/transaction">
  16. <tr>
  17.    <td> <xsl:value-of select="ID"/> </td>
  18.    <td> <xsl:value-of select="TestScript"/> </td>
  19.    <td> <xsl:value-of select="Thread"/> </td>
  20.    <td> <xsl:value-of select="User"/> </td>
  21.    <td> <xsl:value-of select="Event"/> </td>
  22.    <td> <xsl:value-of select="Response"/> </td>
  23.    <td> <xsl:value-of select="ActualResponse"/> </td>
  24.    <td> <xsl:value-of select="Validity"/> </td>
  25.    <td> <xsl:value-of select="Timing"/> </td>
  26.    <td> <xsl:value-of select="Date"/> </td>
  27.    <td> <xsl:value-of select="Hour"/> </td>
  28.     </tr>
  29.     </xsl:for-each>
  30.    
  31.     </table>


 
Est it possible poiur la premiere ligne de <tr> <th> de remplacer par select attributes names de <transaction></transactions>
de meme pour les <td> ?
 
je debute en xsl.
 [:alarmclock119]

mood
Publicité
Posté le 21-09-2005 à 08:35:23  profilanswer
 

n°1204036
avander
Posté le 21-09-2005 à 10:14:13  profilanswer
 

Tu peux faire usage d'un xsl:attribute-set, c'est plus facile à gérer parce que tu définit tes attributs à un seul endroit, puis tu fais appel à celui-ci.
 
définition d'un set ( avant les templates!)

 
<xsl:attribute-set name="th.style">
    <xsl:attribute name="style">border-right: 1px white solid; padding-left: 5px; padding-right: 5px;</xsl:attribute>
</xsl:attribute-set>


 
puis dans tes templates tu fait appel à la définition du set comme ceci:

 
   ...
   <th xsl:use-attribute-sets="th.style">Id</th>
   ...


n°1204274
xiluoc
un pc pour les unirs ....
Posté le 21-09-2005 à 13:40:20  profilanswer
 

que veus tu dire avant les templates ?
j ai essayer

Code :
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" style="background-color: #858687;">
  3. <head>
  4.   <title>Log Data </title>
  5. </head>
  6. <body style= "background-color: #ffffff;
  7.    margin: 10px;
  8.    border-style: solid;
  9.    border-width: 2px;
  10.    border-color: #000000;
  11.    font-family: arial, helvetica, sans-serif;
  12.    padding: 5px;">
  13. <h1 style="font-size: 16px; border-bottom: 1px black solid; padding-bottom: 5px;">Log Data - LogViewer - S@ACUS - 2005 </h1>
  14. <xsl:attribute-set name="th.style">
  15.      <xsl:attribute name="style">border-right: 1px white solid; padding-left: 5px; padding-right: 5px;</xsl:attribute>
  16. </xsl:attribute-set>
  17. <table style= "padding: 5px; " border='0' cellspacing='0' cellpadding='2'>
  18. <tr style= " background-color: #50b56d;" >
  19.  <th xsl:use-attribute-sets="th.style">Id</th>
  20.  <th xsl:use-attribute-sets="th.style">TestScript</th>
  21.  <th xsl:use-attribute-sets="th.style">Thread</th>
  22.  <th xsl:use-attribute-sets="th.style">User</th>
  23.  <th xsl:use-attribute-sets="th.style">Event</th>
  24.  <th xsl:use-attribute-sets="th.style">Response</th>
  25.  <th xsl:use-attribute-sets="th.style">ActualResponse</th>
  26.  <th xsl:use-attribute-sets="th.style">Validity</th>
  27.  <th xsl:use-attribute-sets="th.style">Timing</th>
  28.  <th xsl:use-attribute-sets="th.style">Date</th>
  29.  <th xsl:use-attribute-sets="th.style">Hour</th>
  30. </tr>
  31. <xsl:for-each select="log/transaction">
  32. <tr>
  33.    <td> <xsl:value-of select="ID"/> </td>
  34.    <td> <xsl:value-of select="TestScript"/> </td>
  35.    <td> <xsl:value-of select="Thread"/> </td>
  36.    <td> <xsl:value-of select="User"/> </td>
  37.    <td> <xsl:value-of select="Event"/> </td>
  38.    <td> <xsl:value-of select="Response"/> </td>
  39.    <td> <xsl:value-of select="ActualResponse"/> </td>
  40.    <td> <xsl:value-of select="Validity"/> </td>
  41.    <td> <xsl:value-of select="Timing"/> </td>
  42.    <td> <xsl:value-of select="Date"/> </td>
  43.    <td> <xsl:value-of select="Hour"/> </td>
  44.     </tr>
  45.     </xsl:for-each>
  46.    
  47.     </table>
  48.    
  49. </body>
  50. </html>


 
en mettant le  
<cpp>
<xsl:attribute-set name="th.style">
    <xsl:attribute name="style">border-right: 1px white solid; padding-left: 5px; padding-right: 5px;</xsl:attribute>
</xsl:attribute-set>
</cpp>
 
ad differetne endroit mais ca produit une erreur

n°1204306
xiluoc
un pc pour les unirs ....
Posté le 21-09-2005 à 14:04:17  profilanswer
 

hum cest bon je my prenais mal.

n°1204314
FlorentG
Unité de Masse
Posté le 21-09-2005 à 14:12:39  profilanswer
 

Et accessoirement, en faisant ça dans les règles, et en mettant ce putain de code CSS dans un putain de fichier à part, d'utiliser des <col> et des <colgroup>, des attributs class, et surtout d'apprendre à faire un document HTML convenablement et un document CSS convenablement
 
Désolé de l'énervement, bonne soirée [:dawa]

n°1204565
xiluoc
un pc pour les unirs ....
Posté le 21-09-2005 à 16:42:32  profilanswer
 

ah cest bien ce que je me disais on peut donc linker en doc xsl et un css.

n°1204658
xiluoc
un pc pour les unirs ....
Posté le 21-09-2005 à 18:35:46  profilanswer
 

c'est mieux ?
 
xsl

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="html"/>
  4. <!-- define the limit of the timing for appropriate coloring -->
  5. <xsl:param name="timing_limit" select="150"/>
  6. <xsl:template match="log">
  7. <html>
  8.  <head>
  9.    <title>Log Data </title>
  10.    <link rel="stylesheet" type="text/css" href="log.css" />
  11.  </head>
  12.  <body>
  13.   <h1>
  14.    Log Data - LogViewer - S@ACUS - 2005
  15.   </h1>
  16.   <p>
  17.    Number of transactions : <xsl:value-of select="count(transaction)"/>.
  18.    <br />
  19.    The average timing is <b> to do </b> ms.
  20.   </p>
  21.   <table border='0' cellspacing='2' cellpadding='2'>
  22.       <colgroup>
  23.          <col width="2%"/>
  24.          <col width="5%"/>
  25.          <col width="5%"/>
  26.          <col width="5%"/>
  27.          <col width="20%"/>
  28.     <col width="20%"/>
  29.     <col width="20%"/>
  30.     <col width="5%"/>
  31.     <col width="5%"/>
  32.     <col width="5%"/>
  33.     <col width="5%"/>
  34.       </colgroup>
  35.       <thead>
  36.          <tr>
  37.          <xsl:for-each select="transaction/*">
  38.            <th>
  39.                 <xsl:value-of select="name()"/>
  40.           </th>
  41.           </xsl:for-each>
  42.            </tr>
  43.           
  44.      
  45.        
  46.       </thead>
  47.  
  48.    <xsl:for-each select="transaction">
  49.     <tr>
  50.      <td> <xsl:value-of select="ID"/> </td>
  51.      <td> <xsl:value-of select="TestScript"/> </td>
  52.      <td> <xsl:value-of select="Thread"/> </td>
  53.      <td> <xsl:value-of select="User"/> </td>
  54.      <td> <xsl:value-of select="Event"/> </td>
  55.      <td> <xsl:value-of select="Response"/> </td>
  56.      <td> <xsl:value-of select="ActualResponse"/> </td>
  57.      <td> <xsl:value-of select="Validity"/> </td>
  58.      <td> <xsl:value-of select="Timing"/> </td>
  59.      <td> <xsl:value-of select="Date"/> </td>
  60.      <td> <xsl:value-of select="Hour"/> </td>
  61.     </tr>
  62.       </xsl:for-each>  
  63.       </table>
  64.  </body>
  65. </html>
  66. </xsl:template>
  67. </xsl:stylesheet>


 
css

Code :
  1. html {
  2. background-color: #858687;
  3. }
  4. body {
  5. background-color: #ffffff;
  6. margin: 10px;
  7. border-style: solid;
  8. border-width: 2px;
  9. border-color: #000000;
  10. font-family: arial, helvetica, sans-serif;
  11. padding: 5px;
  12. }
  13. th {
  14. border-right: 1px white solid;
  15. padding-left: 5px;
  16. padding-right: 5px;
  17. }
  18. h1 {
  19. font-size: 1em;
  20. border-bottom: 1px black solid;
  21. padding-bottom: 5px;
  22. }
  23. thead {
  24. background-color: #50b56d;
  25. font-size: 0.9em;
  26. }
  27. td,p {
  28. font-size: 0.8em;
  29. }


 
par contre au lieu de faire <th>id</th> ect pour tous les noms de fields
jaimerai recupere leur nom avec names() et les affichers
 

Code :
  1. <xsl:for-each select="transaction/*">
  2.            <th>
  3.                 <xsl:value-of select="name()"/>
  4.           </th>
  5.           </xsl:for-each>


 
le problem cets que ca maffiche la liste des noms bien comme il faut mais [b]  n [/n] fois.
ou n est le nombre de <transaction> </transacion>
Donc soit je limite le resultat a 1 (comment faire), ou bien il y a une autre solution que je ne trouve pas.
Ou alors il faut mettre les fields un par un.

n°1204919
avander
Posté le 22-09-2005 à 11:30:02  profilanswer
 

oui c'est normal tu demande de traiter tous les enfants des noeuds 'transaction'...  
 

<xsl:for-each select="transaction[1]/*">


 
xpath powaa  :whistle:

n°1206250
Je@nb
Kindly give dime
Posté le 23-09-2005 à 20:11:00  profilanswer
 

Pourquoi quand tu génères tes lignes tu fais un for-each ?  
C'est pas mieux de mettre un apply-templates et faire un tremplate transaction ?

n°1207467
avander
Posté le 26-09-2005 à 11:32:45  profilanswer
 

Je@nb >  
 
D'accord avec toi, le for-each n'est pas vraiment nécessaire, on pourrait très bien s'en sortir avec des apply-templates et un template pour l'élément transaction. Dans ce template on générera l'entête du tableau pour le premier élément transaction en testant sa position avec la fonction position().  


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

  peut simplifier cette boucle

 

Sujets relatifs
comment faire ma boucle ?![RESOLU]Boucle dans remplacement regex
comment faire une boucle "toutes les 3 secondes"?[ms-dos]Comment, avec boucle FOR, trouver le lecteur assigné au CD
probleme de Boucle avec une macro!!!!Construction d'un tableau dans une boucle while
boucle selection condition excel[Batch] Boucle sur plusieurs fichiers - RESOLU
Blocage dans une boucle forBoucle pour enregistrer plusieur fichiers
Plus de sujets relatifs à : peut simplifier cette boucle


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