You're code looks fine to me.  Does any kind of exception occur? It could
well help us figure out whats wrong.

It might well be worth printing out the document you've just parsed before
you transform it, just in case something wierd's happening at the parse
stage. (e.g. you've got the wrong path or whatever).

James
----- Original Message -----
From: "Alex" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, April 23, 2002 9:59 PM
Subject: dom4j question


> i am trying to use your dom4j Quick Start Guide
> http://www.dom4j.org/guide.html#Converting%20to%20and%20from%20Strings
>
> and have transformation result empty (it returns only  <?xml version="1.0"
> encoding="UTF-8"?> )
> but my xml editors and browsers show selected values
>
> can you tell me what is wrong?
>
> thank you
>
> i am using simple xml file and xsl file and here is the java
transformSample
> file:
>
============================================================================
> ===========
> import javax.xml.transform.*;
> import javax.xml.transform.stream.*;
> import org.dom4j.*;
> import org.dom4j.io.*;
> import java.net.URL;
> import java.io.File;
>
>
> public class transformSample {
>
>     public static void main(String[] args) {
>         try {
> String s = "";
> String xmlFile = "";
> String xslFile = "";
>
> xmlFile = "D:\\Alex\\java\\Java\\vCafe\\SQLProcs.xml";
> Document xmlDoc = parseFl(xmlFile);
>
> xslFile = "D:\\Alex\\java\\Java\\vCafe\\SQLProcs.xsl";
> s = styleDocument(xmlDoc, xslFile);
>
>             System.out.println(s);
>         }
>         catch (Exception ex) { ex.printStackTrace(); }
>     }
>
>     public static String styleDocument(Document document, String
> stylesheet){
> Document transformedDoc = null;
> try{
>         // load the transformer using JAXP
>         TransformerFactory factory = TransformerFactory.newInstance();
>         Transformer transformer = factory.newTransformer(new
> StreamSource(stylesheet));
>
>         // now lets style the given document
>         DocumentSource source = new DocumentSource( document );
>         DocumentResult result = new DocumentResult();
>         transformer.transform( source, result );
>
>         // return the transformed document
>         transformedDoc = result.getDocument();
> }
>         catch (Exception ex) { ex.printStackTrace(); }
>         finally{return transformedDoc.asXML();}
>     }
>
> public static Document parseFl(String filePath) {
>     Document document = null;
>     try{
>         File f = new File(filePath);
>         document = parseUrl(f.toURL());
>     }
>     catch (java.net.MalformedURLException ex) { ex.printStackTrace(); }
>     catch (DocumentException dex) { dex.printStackTrace(); }
>     finally {return document;}
>     }
>
> public static Document parseTxt(String xmlText) throws DocumentException {
>         return DocumentHelper.parseText(xmlText);
>     }
>
> public static Document parseUrl(URL url) throws DocumentException {
>         SAXReader reader = new SAXReader();
>         Document document = reader.read(url);
>         return document;
>     }
> }
> ==================================================================
> xml file
> ==================================================================
> <Set language="en" date="Mon Apr 15 16:18:30 PDT 2002" pc="shell"
> ip="192.168.1.100" connection="family" cn_type="odbc">
> <Types/>
> <Data>
> <Procedures>
> <Procedure name="get_contact" generate="false">
> <arg argName="p_person_id" argLength="4" argType="int"
> argNullable="true" argOut="false"/>
> <arg argName="test" argLength="4" argType="int" argNullable="true"
> argOut="true"/>
> </Procedure>
> <Procedure name="get_contactest"/>
> <Procedure name="get_contactint" generate="true">
> <arg argName="testX" argLength="4" argType="int" argNullable="true"
> argOut="true"/>
> </Procedure>
> <Procedure name="get_contacts" generate="true"/>
> <Procedure name="get_people"/>
> </Procedures>
> </Data>
> </Set>
> ==================================================================
> xsl file (i need any looping here)
> ==================================================================
> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
> <xsl:template match="/">
> <html>
> <body>
> <xsl:apply-templates/>
> </body>
> </html>
> </xsl:template>
>
> <xsl:template xmlns:xslt="http://www.w3.org/TR/WD-xsl";>
> <xslt:for-each select="//Procedure">
> <xslt:value-of select="@name"/>
> </xslt:for-each>
> </xsl:template>
>
> <xsl:template match="/">
> <xsl:for-each select="//Procedure">
> <xsl:value-of select="@name"/>
> </xsl:for-each>
> </xsl:template>
> </xsl:stylesheet>
>
>


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to