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

Format d'échange (XML, JSON...) Java Discussion :

Problème de transformation XML avec un fichier xslt


Sujet :

Format d'échange (XML, JSON...) Java

  1. #1
    Membre à l'essai
    Inscrit en
    Août 2002
    Messages
    15
    Détails du profil
    Informations forums :
    Inscription : Août 2002
    Messages : 15
    Points : 17
    Points
    17
    Par défaut Problème de transformation XML avec un fichier xslt
    Salut,

    J'ai un pb de transformation d'un xml en java à l'aide d'un fichier xslt

    Le code java qui transforme le xml en html est :

    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
     
    **
    	 * Cette methode est utilisee pour transformer un XML en utilsant un XSL. xslFile indique le chemin en relatif 
    	 * depuis le document root de la webapp, par ex:
    	 * file://staticXML/file1.xsl
    	 * 
    	 * @param xslInput      : fichier xsl de tranformation
    	 * @param node          : node a transformer en genrale la racine du document
    	 * @param output        : la chaine de sortie
    	 * @throws XMLException : gestion généralisée des exceptions par une classe dédiée
    	 */	
    	public static void xslTransform(InputStream xslInput, Node node,OutputStream output) throws XMLException
    	{
    		Log	loggeur	= LogServiceHelper.getLog("com.unilog.epshom.share.XMLUtils");
    		loggeur.debug("Entree dans la methode de tranformation du xsl sans URIResolver");
     
    		try
    		{
    			TransformerFactory.newInstance().newTransformer(
    			new StreamSource(xslInput)).transform(new DOMSource(node),
    			new StreamResult(output));
    			loggeur.debug("Traitement effectué.");
    		}
    		catch (TransformerConfigurationException tce)
    		{
    			loggeur.error("TransformerConfigurationException la serialisation a échouée");
    			throw new XMLException(tce);
     
    		}
    		catch (TransformerException te)
    		{
    			loggeur.error("TransformerException la serialisation a échouée");
    			throw new XMLException(te);
    		}
    		finally
    		{
    			loggeur.debug("Sortie de xslTranform (InputStream, Node, OutputStream) sans URIResolver");
    		}
    	}
    Le fichier xslt contient les lignes :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    <xsl:if test="ends-with( . , 'gif') or  ends-with( . , 'jpg') or ends-with( . , 'jpeg') or  ends-with( . , 'JPG') or  ends-with( . , 'GIF') or  ends-with( . , 'JPEG')" >
    			 <img border="0">
    				<xsl:attribute name="src"><xsl:value-of select="." /></xsl:attribute>
    			</img>
            </xsl:if>
    Sans le "if" le code ne plante pas mais si le fichier xsl contient le "if", ca plante.

    L'erreur est la suivante :

    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
    [2005-08-19 12:19:39,002] [TP-Processor1] ERROR DocumentXML  - Erreur lors de la transformation du fichier xml 
    org.apache.xerces.validators.datatype.XMLException
    	at com.unilog.epshom.share.XMLUtils.xslTransform(XMLUtils.java:137)
    	at com.unilog.epshom.indexeur.Documents.DocumentXML.getContenuHTML(DocumentXML.java:176)
    	at com.unilog.epshom.synthese.GestionDocuments.getContenu(GestionDocuments.java:67)
    	at com.unilog.moteur.web.affiche.action.AfficherDetails.perform(AfficherDetails.java:70)
    	at org.apache.struts.action.Action.execute(Action.java:420)
    	at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
    	at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
    	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
    	at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
    	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
    	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
    	at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
    	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
    	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
    	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
    	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
    	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
    	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
    	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
    	at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
    	at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:300)
    	at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:374)
    	at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:743)
    	at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:675)
    	at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:866)
    	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    	at java.lang.Thread.run(Unknown Source)



    QQ'un a une idée?

    Merci

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Juillet 2005
    Messages
    274
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 274
    Points : 307
    Points
    307
    Par défaut
    Bonjour,

    est-tu sur de la fonction "ends-with" je ne la connais pas (même si la fonction starts-with existe) ?


    tu peux utiliser la fonction contains à la place.

  3. #3
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    38
    Détails du profil
    Informations personnelles :
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Mars 2006
    Messages : 38
    Points : 37
    Points
    37
    Par défaut
    bonjour

    as tu résolu ton pb depuis ?

    je ne sais pas si ça vient de là mais pour charger ma feuille xslt, j'utilise le context de ma servlet pour avoir le chemin :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    String    filePath  = this.getServletContext().getRealPath("WEB-INF/toXHTML.xsl");
    sinon, j'ai aussi un problème traitant de ce sujet : http://www.developpez.net/forums/sho...d.php?t=134992

    je te tiens au courant si j'ai du nouveau pour ton pb
    l'union fait la force !

    bye

Discussions similaires

  1. Réponses: 2
    Dernier message: 15/04/2014, 14h58
  2. Création d'un fichier XML avec SAX et XSLT
    Par Ioan dans le forum Codes sources à télécharger
    Réponses: 0
    Dernier message: 08/03/2011, 18h50
  3. [XSLT] transformation xsl avec un fichier xml en utf8
    Par thierry_b dans le forum XSL/XSLT/XPATH
    Réponses: 2
    Dernier message: 08/12/2008, 10h46
  4. Lien vers un fichier XML avec une feuille XSLT
    Par Raphael_Lemaire dans le forum XSL/XSLT/XPATH
    Réponses: 2
    Dernier message: 01/10/2008, 23h16
  5. [XSLT] transformation XML d'un fichier ant
    Par fornorst dans le forum XSL/XSLT/XPATH
    Réponses: 7
    Dernier message: 28/10/2005, 17h52

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