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 :

[XSLT] Optimisation


Sujet :

XSL/XSLT/XPATH XML

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    135
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 135
    Par défaut [XSLT] Optimisation
    Bonjour, je voudrais savoir si vous pouvez m'aider a optimiser mon xsl

    Voila un exemple de fichier xsl que j'essaie de parser avec mon xsl
    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
    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
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
     
    <ROOT>
    <LG>
      <!-- Identification du flux de type AAAAMMJJHHMMSS-->
      <ID>20060814160126</ID>
      <!--Nom du programme créateur-->
      <OU>FTP</OU>
    </LG>
    <LG>
      <!--Identification du flux-->
      <ID>20060814160126</ID>
      <!--horodatage de type AAAAMMJJHHMMSS-->
      <HD>20060814160126</HD>
      <!--Nom du programme créateur-->
      <OU>FTP</OU>
      <MSG>
        <!-- Nom du fichier que l'on télécharge -->
        <COD>100</COD>
        <TXT>FR53.2006042511134919.txt</TXT>
      </MSG>
      <MSG>
        <!-- Nom du fichier téléchargé -->
        <COD>101</COD>
        <TXT>FR53.2006042511134919.txt</TXT>
      </MSG>
    </LG>
    <LG>
      <!--Identification du flux-->
      <ID>20060814160126</ID>
      <!--horodatage de type AAAAMMJJHHMMSS-->
      <HD>20060814160126</HD>
      <!--Nom du programme créateur-->
      <OU>FTP</OU>
      <MSG>
        <!-- Succès du téléchargement -->
        <COD>131</COD>
        <TXT>Déconnection</TXT>
      </MSG>
    </LG>
    <LG>
      <!-- Identification du flux de type AAAAMMJJHHMMSS-->
      <ID>20060814160130</ID>
      <!--Nom du programme créateur-->
      <OU>DECOUP_PLAT</OU>
    </LG>
    <LG>
      <!--Identification du flux-->
      <ID>20060814160130</ID>
      <!--horodatage de type AAAAMMJJHHMMSS-->
      <HD>20060814160130</HD>
      <!--Nom du programme créateur-->
      <OU>DECOUP_PLAT</OU>
      <MSG>
        <!-- Lecture du fichier -->
        <COD>420</COD>
        <TXT>FR53.2006042511134919.txt</TXT>
      </MSG>
      <MSG>
        <!-- Création du fichier de sortie -->
        <COD>421</COD>
        <TXT>FR53.2006042511134919_001.txt</TXT>
      </MSG>
      <MSG>
        <!-- Création du fichier de sortie -->
        <COD>421</COD>
        <TXT>FR53.2006042511134919_002.txt</TXT>
      </MSG>
      <MSG>
        <!-- Création du fichier de sortie -->
        <COD>421</COD>
        <TXT>FR53.2006042511134919_003.txt</TXT>
      </MSG>
      <MSG>
        <!-- Création du fichier de sortie -->
        <COD>421</COD>
        <TXT>FR53.2006042511134919_004.txt</TXT>
      </MSG>
      <MSG>
        <!-- Création du fichier de sortie -->
        <COD>421</COD>
        <TXT>FR53.2006042511134919_005.txt</TXT>
      </MSG>
      <MSG>
        <!-- Création du fichier de sortie -->
        <COD>421</COD>
        <TXT>FR53.2006042511134919_006.txt</TXT>
      </MSG>
      <MSG>
        <!-- Création du fichier de sortie -->
        <COD>421</COD>
        <TXT>FR53.2006042511134919_007.txt</TXT>
      </MSG>
      <MSG>
        <!-- Création du fichier de sortie -->
        <COD>421</COD>
        <TXT>FR53.2006042511134919_008.txt</TXT>
      </MSG>
      <MSG>
        <!-- Création du fichier de sortie -->
        <COD>421</COD>
        <TXT>FR53.2006042511134919_009.txt</TXT>
      </MSG>
      <MSG>
        <!-- Création du fichier de sortie -->
        <COD>421</COD>
        <TXT>FR53.2006042511134919_010.txt</TXT>
      </MSG>
      <MSG>
        <!-- Création du fichier de sortie -->
        <COD>421</COD>
        <TXT>FR53.2006042511134919_011.txt</TXT>
      </MSG>
      <MSG>
        <!-- Création du fichier de sortie -->
        <COD>421</COD>
        <TXT>FR53.2006042511134919_012.txt</TXT>
      </MSG>
    </LG>
    ....
    </ROOT>
    Il y a près de 500 balises LG en plus

    Voici mon xsl
    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
    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
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
     
    	<!--  template de lancement qui tri par ID-->
    	<xsl:template match="/ROOT">
    		<ROOT>
    			<xsl:apply-templates select="/ROOT/LG[OU='FTP']" mode="nom" />
    		</ROOT>
    	</xsl:template>
     
    	<!-- template qui traite les noeuds ftp -->
    	<xsl:template match="/ROOT/LG[OU='FTP']" mode="nom">
    		<xsl:variable name="id_ftp_download" select="ID"/>
    		<!-- s' il s'agit d'un noeud ftp  -->
    		<xsl:if test="not(preceding-sibling::ID = $id_ftp_download) and ($id_ftp_download = /ROOT/LG[OU='FTP'][MSG[COD='100']]/ID)">
    			<xsl:if test="contains(MSG/TXT,'DOWN')">
    				<TRAITEMENT>
    					<xsl:call-template name="noeud_telechargement">
    						<xsl:with-param name="id_ftp_download">
    							<xsl:value-of select="$id_ftp_download"/>
    						</xsl:with-param>
    					</xsl:call-template>
    				</TRAITEMENT>
    			</xsl:if>
    		</xsl:if>
    	</xsl:template>
     
    	<!-- template du noeud ftp qui cherche les traitements suivants ou les liens casses -->
    	<xsl:template name="noeud_telechargement">
    		<xsl:param name="id_ftp_download"/>
    		<!-- <xsl:if test="contains(/ROOT/LG[OU='FTP'][ID=$id_ftp_download]/MSG/TXT,'DOWN')"> -->
    			<xsl:for-each select="/ROOT/LG[OU='FTP'][ID=$id_ftp_download][MSG[COD='100']]">
    					<!--  on recupere un nom de fichier telecharger -->
    					<xsl:variable name="nom_fichier" select="./MSG[COD='101']/TXT"/>
    					<!--  on teste si c un lien casse ou pas -->
    					<xsl:variable name="casse">
    						<xsl:call-template name="test_lien_casse">
    							<xsl:with-param name="id" select="$id_ftp_download" />
    							<xsl:with-param name="fichier" select="$nom_fichier" />						
    						</xsl:call-template>
    					</xsl:variable> 
     
    					<!-- si casse = 0 alors pas de lien casse sinon -->
    					<xsl:choose>
    						<xsl:when test="$casse!='0'">	
    							<MODULE type="telechargement">
    							<LG>
    								<xsl:copy-of select="ID"/>
    								<xsl:copy-of select="HD"/>
    								<xsl:copy-of select="OU"/>
    								<xsl:for-each select="./MSG">
    									<xsl:if test="COD!='101'">
    										<xsl:copy-of select="."/>
    									</xsl:if>
    									<xsl:if test="COD='101'">
    										<xsl:copy-of select="."/>
    										<xsl:call-template name="next_LG">
    											<xsl:with-param name="id">
    												<xsl:value-of select="$id_ftp_download"/>
    											</xsl:with-param>
    											<xsl:with-param name="fichier_renomme">
    												<xsl:value-of select="./TXT"/>
    											</xsl:with-param>
    										</xsl:call-template>
    									</xsl:if>
    								</xsl:for-each>
    							</LG>
    							</MODULE>
    						</xsl:when>
    						<xsl:otherwise>
    						<MODULE type="telechargement">
    							<LG>
    								<xsl:copy-of select="/ROOT/LG[ID=$id_ftp_download][OU='FTP'][MSG[COD='100'][TXT=$nom_fichier]]/ID"/>
    								<xsl:copy-of select="/ROOT/LG[ID=$id_ftp_download][OU='FTP'][MSG[COD='100'][TXT=$nom_fichier]]/HD"/>
    								<xsl:copy-of select="/ROOT/LG[ID=$id_ftp_download][OU='FTP'][MSG[COD='100'][TXT=$nom_fichier]]/OU"/>
    								<xsl:copy-of select="/ROOT/LG[ID=$id_ftp_download][OU='FTP'][MSG[COD='100'][TXT=$nom_fichier]]/MSG"/>
    							</LG>
    								<xsl:for-each select="./MSG[COD='101']">
    									<xsl:variable name="id_suivant">
    										<xsl:call-template name="find_id_suivant">
    											<xsl:with-param name="id" select="$id_ftp_download"/>
    											<xsl:with-param name="nom_fichier" select="./TXT"/>
    										</xsl:call-template>
    									</xsl:variable>
    									<xsl:if test="$id_suivant=''">
    										<LG>
    											<ID>0</ID>
    											<HD>0</HD>
    											<MSG>
    												<COD>0</COD>
    												<TXT>lien casse</TXT>
    											</MSG>
    											<xsl:call-template name="lien_casse">
    												<xsl:with-param name="id_courant" select="$id_ftp_download"/>
    												<xsl:with-param name="list_clef_courante" select="./TXT"/>
    											</xsl:call-template>
    										</LG>
    									</xsl:if>
    								</xsl:for-each>
    							</MODULE>						
    						</xsl:otherwise>
    					</xsl:choose>
    			</xsl:for-each>
    		<!-- </xsl:if> -->
    	</xsl:template>
     
    	<!--  template qui teste s il y a un lien casse ou pas -->
    	<xsl:template name="test_lien_casse">
    		<xsl:param name="id"/>
    		<xsl:param name="fichier"/>
    		<xsl:variable name="test_var">
    			<xsl:call-template name="find_id_suivant">
    				<xsl:with-param name="id" select="$id" />
    				<xsl:with-param name="nom_fichier" select="$fichier" />
    			</xsl:call-template>
    		</xsl:variable>
    		<xsl:choose>
    			<xsl:when test="normalize-space($test_var)!=''">1</xsl:when>
    			<xsl:otherwise>0</xsl:otherwise>
    		</xsl:choose>
    	</xsl:template>
     
    	<!-- template pour trouver le prochain ID de traitement, il prend en argument l ID du traitement precedent et le nom de fichier traite en entree -->
    	<xsl:template name="find_id_suivant">
    		<xsl:param name="id"/>
    		<xsl:param name="nom_fichier"/>
    		<xsl:variable name="id_suivant">
    			<xsl:value-of select="/ROOT/LG[ID=$id][last()]/following-sibling::LG[MSG[TXT=$nom_fichier]]/ID"/>
    		</xsl:variable>
    		<xsl:value-of select="$id_suivant"/>
    	</xsl:template>
     
    	<!-- template pour trouver le prochain ID, il prend en argument l ID du traitement precedent -->
    	<xsl:template name="find_next_id">
    		<xsl:param name="id"/>
    		<xsl:variable name="next_id">
    			<xsl:value-of select="/ROOT/LG[ID=$id][last()]/following-sibling::LG[ID!=$id][1]/ID"/>
    		</xsl:variable>
    		<xsl:value-of select="$next_id"/>
    	</xsl:template>
     
    	<!--  template qui construit les modules et leurs LG : c long comme template car chaque traitement a son propre code il faut donc les traitees 1 par 1 -->
    	<xsl:template name="next_LG">
    		<xsl:param name="id"/>
    		<xsl:param name="fichier_renomme"/>
    		<!-- on recherche le prochain id du traitement de id -->
    		<xsl:variable name="next_ID">
    			<xsl:call-template name="find_next_id">
    				<xsl:with-param name="id">
    					<xsl:value-of select="$id"/>
    				</xsl:with-param>
    			</xsl:call-template>
    		</xsl:variable>
    		<!-- *********** LISTE DE PRG qui ont un code 100 en entrée et 101 en sortie CTRL, TRAD, RENO, FACORI, FTP ******************** -->
    		<xsl:choose>
    			<!-- FTP -->
    			<xsl:when test="/ROOT/LG[ID=$next_ID][OU='FTP'][MSG[COD='100'][TXT=$fichier_renomme]]">
    				<xsl:comment>FTP UPLOAD</xsl:comment>
    				<MODULE type="fichier upload">
    					<LG>
    						<xsl:copy-of select="/ROOT/LG[ID=$next_ID][OU='FTP'][MSG[COD='100'][TXT=$fichier_renomme]]/ID"/>
    						<xsl:copy-of select="/ROOT/LG[ID=$next_ID][OU='FTP'][MSG[COD='100'][TXT=$fichier_renomme]]/HD"/>
    						<xsl:copy-of select="/ROOT/LG[ID=$next_ID][OU='FTP'][MSG[COD='100'][TXT=$fichier_renomme]]/OU"/>
    						<xsl:copy-of select="/ROOT/LG[ID=$next_ID][OU='FTP'][MSG[COD='100'][TXT=$fichier_renomme]]/MSG"/>
    					</LG>
    				</MODULE>
    			</xsl:when>
    			<!-- controle -->
    			<xsl:when test="/ROOT/LG[ID=$next_ID][OU='CTRL'][MSG[COD='100'][TXT=$fichier_renomme]]">
    				<xsl:comment>CTRL</xsl:comment>
    				<MODULE type="fichier xml">
    					<LG>
    						<xsl:copy-of select="/ROOT/LG[ID=$next_ID][OU='CTRL'][MSG[COD='100'][TXT=$fichier_renomme]]/ID"/>
    						<xsl:copy-of select="/ROOT/LG[ID=$next_ID][OU='CTRL'][MSG[COD='100'][TXT=$fichier_renomme]]/HD"/>
    						<xsl:copy-of select="/ROOT/LG[ID=$next_ID][OU='CTRL'][MSG[COD='100'][TXT=$fichier_renomme]]/OU"/>
    						<xsl:copy-of select="/ROOT/LG[ID=$next_ID][OU='CTRL'][MSG[COD='100'][TXT=$fichier_renomme]]/MSG"/>
    						<xsl:call-template name="next_LG">
    							<xsl:with-param name="id">
    								<xsl:value-of select="$next_ID"/>
    							</xsl:with-param>
    							<xsl:with-param name="fichier_renomme">
    								<xsl:value-of select="$fichier_renomme"/>
    							</xsl:with-param>
    						</xsl:call-template>
    					</LG>
    				</MODULE>
    			</xsl:when>
    ....
    Dans mon xsl, je fais des for-each et des following-sibling

    Quelqu'un veut il bien m'aider

    La structure de mon xsl est une suite de balise LG qui contient des info sur le resultat d'un traitement pour plusieurs fichier ce qui fait que l'on a à la fin un historique de raitement à un jour donnée.

    Le but de mon xsl est de reconstruire mon fichier xml en un autre fichier xml qui ne serait plus l'historique du traitement mais plutot l'historique du fichier.

    Si je vous demande c'est que je block vraiment.

    Merci

  2. #2
    Rédacteur

    Avatar de Erwy
    Homme Profil pro
    Développeur Web
    Inscrit en
    Novembre 2003
    Messages
    4 967
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Novembre 2003
    Messages : 4 967
    Par défaut
    Pour les optimisation c'est surtout les chemins xpath qui comptent ainsi tous les ="/ROOT/quelque chose "que tu utilise sont tres mauvais.Ils obligent le parseur a reprendre tous le documents à chaque fois.
    Il faut utiliser des chemins relatifs quand c'est possible.
    Pareil dans les match de tes templates normalement c'est les noms des balises vise uniquement.

    Elimine tous les xpath qui commencent par / et tu gagneras enormement de performances

Discussions similaires

  1. Probléme et optimisation XSLT
    Par artaheranthares dans le forum XSL/XSLT/XPATH
    Réponses: 12
    Dernier message: 12/07/2011, 16h38
  2. [XSLT] Optimisation fichiers XSL
    Par tahatriki dans le forum XSL/XSLT/XPATH
    Réponses: 1
    Dernier message: 06/01/2011, 17h08
  3. [XSLT] Prémunir serveur contre surcharge - optimisation XSL
    Par thibaut06 dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 22/11/2006, 18h51
  4. [XSLT] Comment optimiser les traitements XML/XSL ?
    Par thibaut06 dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 24/03/2006, 16h39
  5. optimisation de temps de traitement xml/xslt
    Par Erwy dans le forum XSL/XSLT/XPATH
    Réponses: 2
    Dernier message: 06/05/2004, 16h08

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