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 :

Extraction de contenu de mon xml : données manquantes


Sujet :

XSL/XSLT/XPATH XML

  1. #1
    Candidat au Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2011
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2011
    Messages : 7
    Points : 4
    Points
    4
    Par défaut Extraction de contenu de mon xml : données manquantes
    Bonjour tout le monde,
    J'ai un soucis avec ma feuille d'extraction xslt que je vous montre ici:
    Code XML:
    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
    <?xml version="1.0" encoding="Cp1252"?>
    <html><body class="noscroll">
     
    <div class="rcmBody" lang="EN-US">
    <div class="WordSection1">
     
    <p style="margin: 0in; margin-bottom: .0001pt"><span style="font-size: 11.0pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;">_ _ _ _ _ _ _ _ _ _ _ _
    </span></p>
    <p class="MsoNormal"><span style="font-size: 10.0pt">http://thehill.com/opinion/op-ed/220075-congress-needed-on-water-power</span></p>
    <p class="MsoNormal"><b><span style="font-size: 10.0pt">TI: Congress needed on water, power</span></b></p>
    <p class="MsoNormal"><span style="font-size:10.0pt">CO: Blablabla blabla</span></p>
    <p class="MsoNormal"><span style="font-size: 10.0pt">AB: By Jon Freedman (GEWPT) - 10/07/14 By now most people are all too familiar with the extended drought in the American Southwest. Pictures of wildfires in California, decimated agricultural lands and the
     effects of a diminishing water supply regularly make the news. What most people might not know, yet just as devastating, is the potential effect of the 14-year drought in the Colorado River basin on the Southwest’s energy supply</span></p>
    <p style="margin: 0in; margin-bottom: .0001pt"><span style="font-size: 11.0pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;">_ _ _ _ _ _ _ _ _ _ _ _
    </span></p>
     
    <p class="MsoNormal"><span style="font-size: 10.0pt">*</span></p>
    <p class="MsoNormal"><span style="font-size: 10.0pt">http://www.whatech.com/market-research-reports/press-release/industrial/31670-global-water-level-sensor-industry-report-2014</span></p>
    <p class="MsoNormal"><b><span style="font-size: 10.0pt">TI:* Global water level sensor industry explored in new report</span></b></p>
    <p class="MsoNormal"><span style="font-size:10.0pt">CO: BlueField Research</span></p>
    <p class="MsoNormal"><span style="font-size: 10.0pt">AB: This report has introduced Water Level Sensor basic information included Water Level Sensor definition classification application industry chain structure industry overview.</span></p>
    <p class="MsoNormal"><span style="font-size: 10.0pt">To access full report with TOC, please visit 2014 Market Research Report on Global Water Level Sensor Industry (http://www.reportstack.com/product/175905/2014-market-research-report-on-global-water-level-sensor-industry.html#src=whatech)</span></p>
     
    </div>
    </div>
    </body></html>

    Code xslt:

    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
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml" version="1.0">
    	<xsl:output encoding="UTF-8" method="xml" indent="yes"/>
    	<xsl:template match="html">
    	<sections>
    	<xsl:apply-templates select="//div[@class='WordSection1']"/>
    	</sections>
    	</xsl:template>
    	<xsl:template match="//div[@class='WordSection1']">
    	    <xsl:for-each select="p[contains(.,'_ _ _ _ _ _ _ ')]">
    	     <section>
    	       <title>
    		   <xsl:value-of select="substring-after(following-sibling::p//span[contains(text(),'TI:')],'TI:')"/>
    		    </title>
                 <details>
    		    <HTML>
    						<xsl:value-of select="following-sibling::p//span[contains(text(),'CO:')]"/>
    						<br/><br/>
    						<xsl:value-of select="following-sibling::p//span[contains(text(),'AB:')]"/>
    						<xsl:value-of select="following-sibling::p//span[contains(text(),'')]"/>
    		    </HTML>
    		</details>
    		<commentary></commentary>
    		<links>
    					<xsl:value-of select="following-sibling::p//span[contains(text(),'http:')]"/>
    		</links>
                <from></from>
    		 </section>
    		</xsl:for-each>
    	</xsl:template>
    </xsl:stylesheet>
    Résultat actuel:

    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
    <?xml version="1.0" encoding="UTF-8"?>
    <sections xmlns:xhtml="http://www.w3.org/1999/xhtml">
    	<section>
    		<title> Congress needed on water, power</title>
    		<details>
    			<HTML>CO: Blablabla blabla<br/><br/>AB: By Jon Freedman (GEWPT) - 10/07/14 By now most people are all too familiar with the extended drought in the American Southwest. Pictures of wildfires in California, decimated agricultural lands and the
     effects of a diminishing water supply regularly make the news. What most people might not know, yet just as devastating, is the potential effect of the 14-year drought in the Colorado River basin on the Southwest’s energy supplyhttp://thehill.com/opinion/op-ed/220075-congress-needed-on-water-power</HTML>
    		</details>
    		<commentary/>
    		<links>http://thehill.com/opinion/op-ed/220075-congress-needed-on-water-power</links>
    		<from/>
    	</section>
    	<section>
    		<title>* Global water level sensor industry explored in new report</title>
    		<details>
    			<HTML>CO: BlueField Research<br/><br/>AB: This report has introduced Water Level Sensor basic information included Water Level Sensor definition classification application industry chain structure industry overview.*</HTML>
    		</details>
    		<commentary/>
    		<links>http://www.whatech.com/market-research-reports/press-release/industrial/31670-global-water-level-sensor-industry-report-2014</links>
    		<from/>
    	</section>
    </sections>


    Ma question est la suivante :

    Pourquoi le texte de la deuxième section n'est pas entièrement repris?

    Il manque le contenu suivant:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <p class="MsoNormal"><span style="font-size: 10.0pt">To access full report with TOC, please visit 2014 Market Research Report on Global Water Level Sensor Industry (http://www.reportstack.com/product/175905/2014-market-research-report-on-global-water-level-sensor-industry.html#src=whatech)</span></p>

    Pouvez-vous svp m'aider à résoudre ce problème?

    Merci pour votre aide.

  2. #2
    Candidat au Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2011
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2011
    Messages : 7
    Points : 4
    Points
    4
    Par défaut Pouvez-vous m'aider svp
    Re bonjour quelqu'un aurait peut être une idée?

  3. #3
    Modérateur

    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    12 559
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 12 559
    Points : 21 621
    Points
    21 621
    Par défaut
    La réponse au "pourquoi" est très simple :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    <xsl:value-of select="following-sibling::p//span[contains(text(),'AB:')]"/>
    <xsl:value-of select="following-sibling::p//span[contains(text(),'')]"/>
    Chercher un texte qui contient la chaîne vide ?... Mais... Tous les textes contiennent la chaîne vide !
    Il manque rien dans ton résultat, c'est juste que la chaîne ajoutée c'est celle de <p class="MsoNormal"><span style="font-size: 10.0pt">*</span></p>, pas de <p class="MsoNormal"><span style="font-size: 10.0pt">To access full report with TOC, please visit 2014 Market Research Report on Global Water Level Sensor Industry (http://www.reportstack.com/product/175905/2014-market-research-report-on-global-water-level-sensor-industry.html#src=whatech)</span></p>.

    La réponse à "comment résoudre le problème" eh ben... C'est assez rude en XSLT 1.0.
    Je cherche une solution pas trop compliquée. En gros 'faudrait regrouper les <p> par élément _ _ _ _ _ _ _ qui les précède, et pour ça il faut un regroupement Muench utilisant le generate-id() du premier _ _ _ _ _ _ _ rencontré dans les preceding-sibling...
    Mais même une fois ce regroupement fait, il faut dedans trouver le TI: et faire un traitement particulier dessus, puis afficher normalement tout ce qu'il y a après... C'est rude.

    Pas très adapté au besoin, ce fichier XML de départ. Ce serait plus facile dans un langage de programmation que dans un langage de style.

  4. #4
    Candidat au Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2011
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2011
    Messages : 7
    Points : 4
    Points
    4
    Par défaut
    Merci bcp thelvin pour ta réponse.
    Effectivement le fait de chercher une chaine vide (je l'ai fait ex prêt pour voir s'il va récupérer tous le texte) mais ce n'est pas le cas .

    pourras-tu stp m'éclaircir un peu mieux ta proposition concernant le generate id() pour prendre les <p> contenant _ _ _ _ _ _ _ _ comme point d’arrêt de chaque itération?

    Encore un grand merci.

Discussions similaires

  1. recuperer le chemin d'un fichier contenu dans mon xml
    Par kaking dans le forum XML/XSL et SOAP
    Réponses: 3
    Dernier message: 18/07/2012, 07h53
  2. Réponses: 5
    Dernier message: 09/04/2012, 12h48
  3. Réponses: 7
    Dernier message: 16/10/2010, 15h48
  4. Que choisir pour vérifier le contenu de mon fichier XML?
    Par nadsky dans le forum Format d'échange (XML, JSON...)
    Réponses: 2
    Dernier message: 16/06/2009, 16h01

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