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 :

Tri sur date ('jan','feb' etc) [XSLT 2.0]


Sujet :

XSL/XSLT/XPATH XML

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2008
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2008
    Messages : 16
    Par défaut Tri sur date ('jan','feb' etc)
    Bonjour à tous,
    dans le cadre d'un petit projet je dois réaliser une feuille de transformation XSLT qui présente des ouvrages dans leur ordre de parution

    Voici une partie du fichier xml :
    Code XML : 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
    <pulp-series-plus>
     
      <hero>&ds;</hero>
     
      <house-name by="robeson"/>
     
      <series>
        <item by="dent">
          <title><skippable>The </skippable>Annihilist</title>
          <pulp name="&dsm;" nb="22" year="1934" month="dec"/>
          <pocket-book publisher="Bantam" nb="31" year="1968" month="dec"/>
          <abstract>
            <par>
              The dread Annihilist was slaughtering the criminals of New York in
              wholesale lots. Hundreds of men were found mysteriously murdered,
              victims of the hideous pop-eyed death. The finger of suspicion
              pointed directly at one man, &ds; himself. Even as the &bzm;
              scrambled to solve the terrifying enigma, the invisible assassin
              began to play havoc with one of the humanity's most important
              secret defenses&em-dash;&ds;'s legendary crime college.
            </par>
          </abstract>
          <translation xml:lang="de" by="heinz" publisher="Pabel" nb="24" year="1974" month="oct">
            <title><skippable>Der </skippable>Superkiller</title>
          </translation>
          <translation xml:lang="fr" by="olivier" publisher="Marabout" nb="26" year="1972">
            <title><skippable>Le </skippable>destructeur</title>
          </translation>
        </item>
        <item by="dent">
          <title><skippable>The </skippable>Awful Egg</title>
          <pulp name="&dsm;" nb="88" month="jun" year="1940"/>
          <pocket-book publisher="Bantam" nb="92" month="oct" year="1978"/>
          <abstract>
            <par>
              From the frozen heart of the American continent comes a nameless
              prehistoric terror of unspeakable savagery, leaving a broken trail of
              mangled victims that shocks and baffles the world. Only the superman
              &bzm; can meet this horrifying menace on its own bloody
              ground&em-dash;and uncover the even greater evil that spawned it.
            </par>
          </abstract>
          <translation xml:lang="de" by="kurtz" publisher="Pabel" nb="83" year="1979" month="apr">
            <title><skippable>Das </skippable>Höhlenmonster</title>
          </translation>
        </item>
        <item by="dent">
          <title><skippable>The </skippable>Boss of Terror</title>
          <pulp name="&dsm;" nb="87" year="1940" month="may"/>
          <pocket-book publisher="Bantam" nb="85" year="1976" month="nov"/>
          <abstract>
            <par>
              Men by the name of Smith were being knocked off all over town. And
              they were all killed by lightning&em-dash;lightning that entered a
              room without leaving any marks, on a day when there was no lightning.
              As the &bzm; penetrated ever closer to the heart of this mystery, he
              was scared. For he knew he was closer to death that possibly at any
              other time in his hair-raising career.
            </par>
          </abstract>
          <translation xml:lang="de" by="kurtz" publisher="Pabel" nb="63" year="1977" month="oct">
            <title><skippable>Der </skippable>Boss des Schrekens</title>
          </translation>
        </item>
      </series>
    </pulp-series-plus>

    Toutefois, je ne parviens pas à afficher les résultats en triant sur les mois (jan, feb etc) en plus de l'année.

    Voici mon xslt qui m'affiche les ouvrages par année de parutaion :
    Code XSL : 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
    <?xml version="1.0" encoding="ISO-8859-1"?>
     
    <xsl:stylesheet version="2.0" id="lpro-savage"
                    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    exclude-result-prefixes="xsd">
     
        <xsd:month name="jan" order="01"/>
    	<xsd:month name="feb" order="02"/>
    	<xsd:month name="mar" order="03"/>
    	<xsd:month name="apr" order="04"/>
    	<xsd:month name="may" order="05"/>
    	<xsd:month name="jun" order="06"/>
    	<xsd:month name="jul" order="07"/>
    	<xsd:month name="aug" order="08"/>
    	<xsd:month name="sep" order="09"/>
    	<xsd:month name="oct" order="10"/>
    	<xsd:month name="nov" order="11"/>
    	<xsd:month name="dec" order="12"/>
     
    	<xsl:output method="text"/>
     
    	<xsl:strip-space elements="*"/>
     
    	<xsl:variable name="eol" select="'
    '"/>
     
    	<xsl:template match="pulp-series-plus">
    		<xsl:apply-templates select="series"/>
    	</xsl:template>
     
    	<xsl:template match="series">
    		<xsl:apply-templates select="item[pulp]">
    			<xsl:sort select="pulp/@year" data-type="number" order="ascending"/>
    		</xsl:apply-templates>
    	</xsl:template>
     
    	<xsl:template match="item">
    		<xsl:apply-templates select="pulp"/>
    		<xsl:if test="not(pulp[title])">
    			<xsl:apply-templates select="title"/>
    		</xsl:if>
    		<xsl:value-of select="$eol"/>
    	</xsl:template>
     
    	<xsl:template match="pulp">
    		<xsl:value-of select="$eol"/>
    		<xsl:value-of select="@nb,$eol"/>
    		<xsl:value-of select="@name,$eol"/>
    		<xsl:value-of select="@year,@month,$eol"/>
    		<xsl:value-of select="title"/>
    	</xsl:template>
     
    	<xsl:template match="title">
    		<xsl:apply-templates/>
    	</xsl:template>
     
    </xsl:stylesheet>

    J'aurais besoin d'un petit coup de pouce pour y parvenir.
    Je vous remercie.

  2. #2
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2008
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2008
    Messages : 16
    Par défaut
    j'ai trouvé tout seul.
    Si ça peut aider je poste.

    Code XSL : 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
    <?xml version="1.0" encoding="ISO-8859-1"?>
     
    <xsl:stylesheet version="2.0" id="lpro-savage"
                    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    xmlns:m ="urn:non-null-namespace"
                    exclude-result-prefixes="xsd">
     
    	<m:month name="jan" value="1" />
    	<m:month name="feb" value="2" />
    	<m:month name="mar" value="3" />
    	<m:month name="apr" value="4" />
    	<m:month name="may" value="5" />
    	<m:month name="jun" value="6" />
    	<m:month name="jul" value="7" />
    	<m:month name="aug" value="8" />
    	<m:month name="sep" value="9" />
    	<m:month name="oct" value="10" />
    	<m:month name="nov" value="11" />
    	<m:month name="dec" value="12" />
     
    	<xsl:output method="text"/>
     
    	<xsl:strip-space elements="*"/>
     
    	<xsl:variable name="eol" select="'
    '"/>
     
    	<xsl:template match="pulp-series-plus">
    		<xsl:apply-templates select="series"/>
    	</xsl:template>
     
    	<xsl:template match="series">
    		<xsl:apply-templates select="item[pulp]">
    			<xsl:sort select="concat(pulp/@year,document('')//m:month[@name=current()/pulp/@month]/@value)" data-type="number" />
    		</xsl:apply-templates>
    	</xsl:template>
     
    	<xsl:template match="item">
    		<xsl:apply-templates select="pulp"/>
    		<xsl:if test="not(pulp[title])">
    			<xsl:apply-templates select="title"/>
    		</xsl:if>
    		<xsl:value-of select="$eol"/>
    	</xsl:template>
     
    	<xsl:template match="pulp">
    		<xsl:value-of select="$eol"/>
    		<xsl:value-of select="@nb,$eol"/>
    		<xsl:value-of select="@name,$eol"/>
    		<xsl:value-of select="@year,@month,$eol"/>
    		<xsl:value-of select="title"/>
    	</xsl:template>
     
    	<xsl:template match="title">
    		<xsl:apply-templates/>
    	</xsl:template>
     
    </xsl:stylesheet>

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

Discussions similaires

  1. tri sur dates
    Par yalefe dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 13/09/2009, 16h56
  2. [PerformancePoint] Tri sur date dans Dashboard Designer
    Par Sam3oul dans le forum Microsoft BI
    Réponses: 0
    Dernier message: 09/09/2009, 14h06
  3. [MySQL 5] Double tri sur date et time
    Par titoine1978 dans le forum Langage SQL
    Réponses: 8
    Dernier message: 18/06/2006, 19h46
  4. requete avec tri sur date erronée
    Par olivll dans le forum Access
    Réponses: 11
    Dernier message: 20/10/2005, 15h45
  5. [Interbase 6] tri sur date et SQL
    Par Yogy dans le forum InterBase
    Réponses: 6
    Dernier message: 21/06/2005, 09h15

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