benoitbalon posteets tagged xml,calendrier  [ Profile ]

Sort by: Date / Title /

  1. 11 months ago
    Copier-coller ce code dans un fichier avec une extension ".xsl" (modifier la langue et l'année au besoin). Le fichier devra être appelé dans le fichier XML contenant les données calendaires, celui-ci étant le fichier à ouvrir avec le navigateur Internet.
    1. <?xml version="1.0" encoding="ISO-8859-1"?>
    2.  
    3. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    4.  
    5.         <xsl:template match="/">
    6.                 <html>
    7.                         <head>
    8.                                 <title>Calendrier</title>
    9.                                 <style type='text/css' media='all'>@import 'calendrier.css';</style>
    10.                         </head>
    11.  
    12.                         <body xml:lang="fr">
    13.                                 <xsl:apply-templates>
    14.                                         <xsl:with-param name="langue">fr</xsl:with-param>
    15.                                         <xsl:with-param name="annee">2008</xsl:with-param>
    16.                                 </xsl:apply-templates>
    17.                         </body>
    18.                 </html>
    19.         </xsl:template >
    20.  
    21.         <xsl:template name="noms_mois" match="/calendrier/noms_mois">
    22.                 <xsl:param name="langue"/>
    23.                 <xsl:param name="num"/>
    24.                 <xsl:for-each select="/calendrier/noms_mois/nom[@numero = $num and @lang = $langue]">
    25.                         <div class="titremois"><xsl:value-of select="text()"/></div>
    26.                 </xsl:for-each>
    27.         </xsl:template >
    28.  
    29.         <xsl:template name="noms_jours" match="/calendrier/noms_jours">
    30.                 <xsl:param name="langue"/>
    31.                 <xsl:for-each select="/calendrier/noms_jours/nom[@lang = $langue]">
    32.                         <div class="titrejour{@numero}"><xsl:value-of select="substring(text(), 1, 2)"/></div>
    33.                 </xsl:for-each>
    34.         </xsl:template >
    35.        
    36.         <xsl:template name="principal" match="calendrier">
    37.                 <xsl:param name="langue"/>
    38.                 <xsl:param name="annee"/>
    39.                 <xsl:for-each select="./annee[@numero = $annee]">
    40.                         <div class="annee">
    41.                                 <xsl:for-each select="./mois">
    42.                                         <div class="mois">
    43.                                                 <xsl:call-template name="noms_mois">
    44.                                                         <xsl:with-param name="num"><xsl:value-of select="@numero"/></xsl:with-param>
    45.                                                         <xsl:with-param name="langue"><xsl:value-of select="$langue"/></xsl:with-param>
    46.                                                 </xsl:call-template>
    47.                                                 <div class="jours">
    48.                                                         <xsl:call-template name="noms_jours">
    49.                                                                 <xsl:with-param name="langue"><xsl:value-of select="$langue"/></xsl:with-param>
    50.                                                         </xsl:call-template>
    51.                                                 </div>
    52.                                                 <div class="numeros">
    53.                                                         <xsl:for-each select="./jour">
    54.                                                                 <xsl:if test="@nom=1 and @numero=1">
    55.                                                                         <div class="jour{@nom}"><xsl:value-of select="@numero"/></div>
    56.                                                                 </xsl:if>
    57.                                                                 <xsl:if test="@nom=2 and @numero=1">
    58.                                                                         <div class="vide">&#160;</div>
    59.                                                                         <div class="jour{@nom}"><xsl:value-of select="@numero"/></div>
    60.                                                                 </xsl:if>
    61.                                                                 <xsl:if test="@nom=3 and @numero=1">
    62.                                                                         <div class="vide">&#160;</div>
    63.                                                                         <div class="vide">&#160;</div>
    64.                                                                         <div class="jour{@nom}"><xsl:value-of select="@numero"/></div>
    65.                                                                 </xsl:if>
    66.                                                                 <xsl:if test="@nom=4 and @numero=1">
    67.                                                                         <div class="vide">&#160;</div>
    68.                                                                         <div class="vide">&#160;</div>
    69.                                                                         <div class="vide">&#160;</div>
    70.                                                                         <div class="jour{@nom}"><xsl:value-of select="@numero"/></div>
    71.                                                                 </xsl:if>
    72.                                                                 <xsl:if test="@nom=5 and @numero=1">
    73.                                                                         <div class="vide">&#160;</div>
    74.                                                                         <div class="vide">&#160;</div>
    75.                                                                         <div class="vide">&#160;</div>
    76.                                                                         <div class="vide">&#160;</div>
    77.                                                                         <div class="jour{@nom}"><xsl:value-of select="@numero"/></div>
    78.                                                                 </xsl:if>
    79.                                                                 <xsl:if test="@nom=6 and @numero=1">
    80.                                                                         <div class="vide">&#160;</div>
    81.                                                                         <div class="vide">&#160;</div>
    82.                                                                         <div class="vide">&#160;</div>
    83.                                                                         <div class="vide">&#160;</div>
    84.                                                                         <div class="vide">&#160;</div>
    85.                                                                         <div class="jour{@nom}"><xsl:value-of select="@numero"/></div>
    86.                                                                 </xsl:if>
    87.                                                                 <xsl:if test="@nom=7 and @numero=1">
    88.                                                                         <div class="vide">&#160;</div>
    89.                                                                         <div class="vide">&#160;</div>
    90.                                                                         <div class="vide">&#160;</div>
    91.                                                                         <div class="vide">&#160;</div>
    92.                                                                         <div class="vide">&#160;</div>
    93.                                                                         <div class="vide">&#160;</div>
    94.                                                                         <div class="jour{@nom}"><xsl:value-of select="@numero"/></div>
    95.                                                                 </xsl:if>
    96.                                                                 <xsl:if test="@numero!=1">
    97.                                                                         <div class="jour{@nom}"><xsl:value-of select="@numero"/></div>
    98.                                                                 </xsl:if>
    99.                                                         </xsl:for-each>
    100.                                                 </div>
    101.                                         </div>
    102.                                 </xsl:for-each>
    103.                         </div>
    104.                 </xsl:for-each>
    105.  
    106.         </xsl:template >
    107. </xsl:stylesheet>
  2. 11 months ago
    Copier ce code dans un fichier Shell/Bash, et exécuter le script en mettant en argument la liste des années voulues. Ne pas oublier d'exporter la sortie vers fichier XML ex : $~ : ./generer_calendrier.sh 2008 2009 2010 > calendrier.xml
    1. #!/bin/sh
    2.  
    3. annee="$1"
    4. true=1
    5. false=0
    6.  
    7. # permet de lancer la commande cal pour un mois et une annee precis, et de traiter le decoupage des semaines
    8. get_month ()
    9. {
    10.         annee="$1"
    11.         mois="$2"
    12.         numligne="0"
    13.        
    14.         # execution de cal, et lecture de la sortie ligne par ligne
    15.         cal -m $mois $annee | while read ligne
    16.         do
    17.                 numligne=$((numligne + 1))
    18.                
    19.                 # on ne tient pas compte des lignes vides retournees par cal
    20.                 if test "`echo $ligne | tr -d ' '`" != ""
    21.                 then
    22.                        
    23.                         # on ne tient pas compte de la premiere ligne (mois et annee en cours) et de la deuxieme ligne (noms des jours)
    24.                         if test "$numligne" -gt 2
    25.                         then
    26.                                
    27.                                 # on tient compte de la premiere semaine du mois, afin de connaitre la position du premier jour
    28.                                 if test "$numligne" -lt 4
    29.                                 then
    30.                                         set_days $true $ligne
    31.                                 else
    32.                                         set_days $false $ligne
    33.                                 fi
    34.                                
    35.                         fi
    36.                        
    37.                 fi
    38.                
    39.         done
    40. }
    41.  
    42. # permet de decouper une semaine (une ligne retournee par cal) en jours
    43. set_days ()
    44. {
    45.         nb_jours=`expr $# - 1`
    46.         is_first_line=$1
    47.        
    48.         # on identifie le nombre de jours du mois en cours compris dans la semaine que l'on traite
    49.         case $nb_jours in
    50.                 1) # cette semaine ne comprend qu'un jour du mois en cours, le premier ou le dernier jour du mois
    51.                         if test "$is_first_line" = "$true"
    52.                         then
    53.                                 set_day 7 $2
    54.                         else
    55.                                 set_day 1 $2
    56.                         fi
    57.                         ;;
    58.                 2) # cette semaine comprend deux jours du mois en cours, les deux premiers ou les deux derniers
    59.                         if test "$is_first_line" = "$true"
    60.                         then
    61.                                 set_day 6 $2
    62.                                 set_day 7 $3
    63.                         else
    64.                                 set_day 1 $2
    65.                                 set_day 2 $3
    66.                         fi
    67.                         ;;
    68.                 3) # cette semaine comprend trois jours du mois en cours, les trois premiers ou les trois derniers
    69.                         if test "$is_first_line" = "$true"
    70.                         then
    71.                                 set_day 5 $2
    72.                                 set_day 6 $3
    73.                                 set_day 7 $4
    74.                         else
    75.                                 set_day 1 $2
    76.                                 set_day 2 $3
    77.                                 set_day 3 $4
    78.                         fi
    79.                         ;;
    80.                 4) # cette semaine comprend quatre jours du mois en cours, les quatre premiers ou les quatre derniers
    81.                         if test "$is_first_line" = "$true"
    82.                         then
    83.                                 set_day 4 $2
    84.                                 set_day 5 $3
    85.                                 set_day 6 $4
    86.                                 set_day 7 $5
    87.                         else
    88.                                 set_day 1 $2
    89.                                 set_day 2 $3
    90.                                 set_day 3 $4
    91.                                 set_day 4 $5
    92.                         fi
    93.                         ;;
    94.                 5) # cette semaine comprend cinq jours du mois en cours, les cinq premiers ou les cinq derniers
    95.                         if test "$is_first_line" = "$true"
    96.                         then
    97.                                 set_day 3 $2
    98.                                 set_day 4 $3
    99.                                 set_day 5 $4
    100.                                 set_day 6 $5
    101.                                 set_day 7 $6
    102.                         else
    103.                                 set_day 1 $2
    104.                                 set_day 2 $3
    105.                                 set_day 3 $4
    106.                                 set_day 4 $5
    107.                                 set_day 5 $6
    108.                         fi
    109.                         ;;
    110.                 6) # cette semaine comprend six jours du mois en cours, les six premiers ou les six derniers
    111.                         if test "$is_first_line" = "$true"
    112.                         then
    113.                                 set_day 2 $2
    114.                                 set_day 3 $3
    115.                                 set_day 4 $4
    116.                                 set_day 5 $5
    117.                                 set_day 6 $6
    118.                                 set_day 7 $7
    119.                         else
    120.                                 set_day 1 $2
    121.                                 set_day 2 $3
    122.                                 set_day 3 $4
    123.                                 set_day 4 $5
    124.                                 set_day 5 $6
    125.                                 set_day 6 $7
    126.                         fi
    127.                         ;;
    128.                 7) # cette semaine est pleine, donc on sait que le premier numero correspondra au lundi
    129.                         set_day 1 $2
    130.                         set_day 2 $3
    131.                         set_day 3 $4
    132.                         set_day 4 $5
    133.                         set_day 5 $6
    134.                         set_day 6 $7
    135.                         set_day 7 $8
    136.                         ;;
    137.                 *)
    138.                         echo "Un probleme a du survenir..."
    139.                         exit 1
    140.                         ;;
    141.         esac
    142. }
    143.  
    144. # permet de recopier en sortie la correspondance entre le jour et son numero dans le mois
    145. set_day ()
    146. {
    147.         echo "          <jour nom=\"$1\" numero=\"$2\"/>"
    148. }
    149.  
    150. # lance le traitement pour le calendrier d'une annee, mois par mois
    151. make_calendrier ()
    152. {
    153.         echo "<annee numero=\"$annee\">"
    154.        
    155.         echo "     <mois numero=\"1\">"
    156.         get_month $annee 1
    157.         echo "     </mois>"
    158.        
    159.         echo "     <mois numero=\"2\">"
    160.         get_month $annee 2
    161.         echo "     </mois>"
    162.        
    163.         echo "     <mois numero=\"3\">"
    164.         get_month $annee 3
    165.         echo "     </mois>"
    166.        
    167.         echo "     <mois numero=\"4\">"
    168.         get_month $annee 4
    169.         echo "     </mois>"
    170.        
    171.         echo "     <mois numero=\"5\">"
    172.         get_month $annee 5
    173.         echo "     </mois>"
    174.        
    175.         echo "     <mois numero=\"6\">"
    176.         get_month $annee 6
    177.         echo "     </mois>"
    178.        
    179.         echo "     <mois numero=\"7\">"
    180.         get_month $annee 7
    181.         echo "     </mois>"
    182.        
    183.         echo "     <mois numero=\"8\">"
    184.         get_month $annee 8
    185.         echo "     </mois>"
    186.        
    187.         echo "     <mois numero=\"9\">"
    188.         get_month $annee 9
    189.         echo "     </mois>"
    190.        
    191.         echo "     <mois numero=\"10\">"
    192.         get_month $annee 10
    193.         echo "     </mois>"
    194.        
    195.         echo "     <mois numero=\"11\">"
    196.         get_month $annee 11
    197.         echo "     </mois>"
    198.        
    199.         echo "     <mois numero=\"12\">"
    200.         get_month $annee 12
    201.         echo "     </mois>"
    202.  
    203.         echo "</annee>"
    204. }
    205.  
    206. echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"
    207. echo "<!--?xml-stylesheet href=\"calendrier.xsl\" type=\"text/xsl\"?-->"
    208. echo "<calendrier>"
    209. echo "<noms_jours>"
    210. echo "  <nom numero=\"1\" lang=\"fr\">lundi</nom>"
    211. echo "  <nom numero=\"2\" lang=\"fr\">mardi</nom>"
    212. echo "  <nom numero=\"3\" lang=\"fr\">mercredi</nom>"
    213. echo "  <nom numero=\"4\" lang=\"fr\">jeudi</nom>"
    214. echo "  <nom numero=\"5\" lang=\"fr\">vendredi</nom>"
    215. echo "  <nom numero=\"6\" lang=\"fr\">samedi</nom>"
    216. echo "  <nom numero=\"7\" lang=\"fr\">dimanche</nom>"
    217. echo "  <nom numero=\"1\" lang=\"it\">luned&#236;</nom>"
    218. echo "  <nom numero=\"2\" lang=\"it\">marted&#236;</nom>"
    219. echo "  <nom numero=\"3\" lang=\"it\">mercoled&#236;</nom>"
    220. echo "  <nom numero=\"4\" lang=\"it\">gioved&#236;</nom>"
    221. echo "  <nom numero=\"5\" lang=\"it\">venerd&#236;</nom>"
    222. echo "  <nom numero=\"6\" lang=\"it\">sabato</nom>"
    223. echo "  <nom numero=\"7\" lang=\"it\">domenica</nom>"
    224. echo "  <nom numero=\"1\" lang=\"en\">monday</nom>"
    225. echo "  <nom numero=\"2\" lang=\"en\">tuesday</nom>"
    226. echo "  <nom numero=\"3\" lang=\"en\">wednesday</nom>"
    227. echo "  <nom numero=\"4\" lang=\"en\">thursday</nom>"
    228. echo "  <nom numero=\"5\" lang=\"en\">friday</nom>"
    229. echo "  <nom numero=\"6\" lang=\"en\">saturday</nom>"
    230. echo "  <nom numero=\"7\" lang=\"en\">sunday</nom>"
    231. echo "  <nom numero=\"1\" lang=\"de\">montag</nom>"
    232. echo "  <nom numero=\"2\" lang=\"de\">dienstag</nom>"
    233. echo "  <nom numero=\"3\" lang=\"de\">mittwoch</nom>"
    234. echo "  <nom numero=\"4\" lang=\"de\">donnerstag</nom>"
    235. echo "  <nom numero=\"5\" lang=\"de\">freitag</nom>"
    236. echo "  <nom numero=\"6\" lang=\"de\">samstag</nom>"
    237. echo "  <nom numero=\"7\" lang=\"de\">sonntag</nom>"
    238. echo "  <nom numero=\"1\" lang=\"es\">lunes</nom>"
    239. echo "  <nom numero=\"2\" lang=\"es\">martes</nom>"
    240. echo "  <nom numero=\"3\" lang=\"es\">mi&#233;rcoles</nom>"
    241. echo "  <nom numero=\"4\" lang=\"es\">jueves</nom>"
    242. echo "  <nom numero=\"5\" lang=\"es\">viernes</nom>"
    243. echo "  <nom numero=\"6\" lang=\"es\">s&#225;bado</nom>"
    244. echo "  <nom numero=\"7\" lang=\"es\">domingo</nom>"
    245. echo "</noms_jours>"
    246. echo "<noms_mois>"
    247. echo "  <nom numero=\"1\" lang=\"fr\">janvier</nom>"
    248. echo "  <nom numero=\"2\" lang=\"fr\">f&#233;vrier</nom>"
    249. echo "  <nom numero=\"3\" lang=\"fr\">mars</nom>"
    250. echo "  <nom numero=\"4\" lang=\"fr\">avril</nom>"
    251. echo "  <nom numero=\"5\" lang=\"fr\">mai</nom>"
    252. echo "  <nom numero=\"6\" lang=\"fr\">juin</nom>"
    253. echo "  <nom numero=\"7\" lang=\"fr\">juillet</nom>"
    254. echo "  <nom numero=\"8\" lang=\"fr\">ao&#251;t</nom>"
    255. echo "  <nom numero=\"9\" lang=\"fr\">septembre</nom>"
    256. echo "  <nom numero=\"10\" lang=\"fr\">octobre</nom>"
    257. echo "  <nom numero=\"11\" lang=\"fr\">novembre</nom>"
    258. echo "  <nom numero=\"12\" lang=\"fr\">d&#233;cembre</nom>"
    259. echo "  <nom numero=\"1\" lang=\"en\">january</nom>"
    260. echo "  <nom numero=\"2\" lang=\"en\">february</nom>"
    261. echo "  <nom numero=\"3\" lang=\"en\">march</nom>"
    262. echo "  <nom numero=\"4\" lang=\"en\">april</nom>"
    263. echo "  <nom numero=\"5\" lang=\"en\">may</nom>"
    264. echo "  <nom numero=\"6\" lang=\"en\">june</nom>"
    265. echo "  <nom numero=\"7\" lang=\"en\">july</nom>"
    266. echo "  <nom numero=\"8\" lang=\"en\">august</nom>"
    267. echo "  <nom numero=\"9\" lang=\"en\">september</nom>"
    268. echo "  <nom numero=\"10\" lang=\"en\">october</nom>"
    269. echo "  <nom numero=\"11\" lang=\"en\">november</nom>"
    270. echo "  <nom numero=\"12\" lang=\"en\">december</nom>"
    271. echo "  <nom numero=\"1\" lang=\"es\">enero</nom>"
    272. echo "  <nom numero=\"2\" lang=\"es\">febrero</nom>"
    273. echo "  <nom numero=\"3\" lang=\"es\">marzo</nom>"
    274. echo "  <nom numero=\"4\" lang=\"es\">abril</nom>"
    275. echo "  <nom numero=\"5\" lang=\"es\">mayo</nom>"
    276. echo "  <nom numero=\"6\" lang=\"es\">junio</nom>"
    277. echo "  <nom numero=\"7\" lang=\"es\">julio</nom>"
    278. echo "  <nom numero=\"8\" lang=\"es\">agosto</nom>"
    279. echo "  <nom numero=\"9\" lang=\"es\">septiembre</nom>"
    280. echo "  <nom numero=\"10\" lang=\"es\">octubre</nom>"
    281. echo "  <nom numero=\"11\" lang=\"es\">noviembre</nom>"
    282. echo "  <nom numero=\"12\" lang=\"es\">diciembre</nom>"
    283. echo "  <nom numero=\"1\" lang=\"de\">januar</nom>"
    284. echo "  <nom numero=\"2\" lang=\"de\">februar</nom>"
    285. echo "  <nom numero=\"3\" lang=\"de\">m&#228;rz</nom>"
    286. echo "  <nom numero=\"4\" lang=\"de\">april</nom>"
    287. echo "  <nom numero=\"5\" lang=\"de\">mai</nom>"
    288. echo "  <nom numero=\"6\" lang=\"de\">juni</nom>"
    289. echo "  <nom numero=\"7\" lang=\"de\">juli</nom>"
    290. echo "  <nom numero=\"8\" lang=\"de\">august</nom>"
    291. echo "  <nom numero=\"9\" lang=\"de\">september</nom>"
    292. echo "  <nom numero=\"10\" lang=\"de\">oktober</nom>"
    293. echo "  <nom numero=\"11\" lang=\"de\">november</nom>"
    294. echo "  <nom numero=\"12\" lang=\"de\">dezember</nom>"
    295. echo "  <nom numero=\"1\" lang=\"it\">gennaio</nom>"
    296. echo "  <nom numero=\"2\" lang=\"it\">febbraio</nom>"
    297. echo "  <nom numero=\"3\" lang=\"it\">marzo</nom>"
    298. echo "  <nom numero=\"4\" lang=\"it\">aprile</nom>"
    299. echo "  <nom numero=\"5\" lang=\"it\">maggio</nom>"
    300. echo "  <nom numero=\"6\" lang=\"it\">giugno</nom>"
    301. echo "  <nom numero=\"7\" lang=\"it\">luglio</nom>"
    302. echo "  <nom numero=\"8\" lang=\"it\">agosto</nom>"
    303. echo "  <nom numero=\"9\" lang=\"it\">settembre</nom>"
    304. echo "  <nom numero=\"10\" lang=\"it\">ottobre</nom>"
    305. echo "  <nom numero=\"11\" lang=\"it\">novembre</nom>"
    306. echo "  <nom numero=\"12\" lang=\"it\">dicembre</nom>"
    307. echo "</noms_mois>"
    308.  
    309. # lance le traitement du calendrier de chaque annee passee en parametre du script
    310. for annee in $@
    311. do
    312.         make_calendrier $annee
    313. done
    314.  
    315. echo "</calendrier>"
    316.  
    317. exit 0

First / Previous / Next / Last / Page 1 of 1 (2 posteets)