Hi
 
I am new to XML. I am having difficulty accessing the Xalan mailing list and I dont know where else to look. I am sure this topic has been brought up before.
 
Could anyone please help me with the following code. I have parsed a String into  com.sun.xml.tree.XmlDocument;.
 
I am trying to process this document with Xalan version 1.2.2
 
When I process the document the following error occurs:
 
" XSL Error: SAX Exception   Warning: can't output text before document element! Ignoring..."
 
What am I doing wrong? Would I need to serilalize the output to display the result Node as html?
 
This is the code I have been able to write:
 
import org.apache.xalan.xslt.XSLTEngineImpl;
import org.apache.xalan.xslt.XSLTProcessor;
import org.apache.xalan.xslt.XSLTInputSource;
import org.apache.xalan.xslt.XSLTResultTarget;
import org.apache.xalan.xslt.XSLTProcessorFactory;
import org.apache.xalan.xpath.xml.JaxpLiaison;
import org.apache.xalan.xpath.xdom.*;
import org.apache.xalan.xpath.xml.XMLParserLiaisonDefault;
import org.apache.xalan.xpath.xml.JaxpLiaison;
import org.apache.xml.serialize.*;
import com.sun.xml.*;
import com.sun.xml.tree.XmlDocument;
 
 
public class DisplayItemsBean extends Object {
 
  
  public XmlDocument createDocument(String xml){
 
 
 XmlDocument xmlDoc = new XmlDocument();
 
   try
    {
     ByteArrayInputStream in = new ByteArrayInputStream(xml.getBytes());
     xmlDoc = XmlDocument.createXmlDocument (in, false);
 
     }
    catch (SAXParseException e)
     {
    //Handle Exception
      }
     catch (SAXException e)
     {
    //Handle Exception
     }
     catch (java.io.IOException e)
     {
     //Handle Exception
      }
 

  return xmlDoc;
 
  }
 
   public void process(XmlDocument inDoc) throws Exception {
   XmlDocument doc = new XmlDocument();
   Node outputNode  =  (Node)doc;
   XSLTResultTarget rt = new XSLTResultTarget (outputNode);
 
    try{
       XSLTInputSource xsltIn = new XSLTInputSource();
       xsltIn.setSystemId("xsl address");
       XSLTInputSource xmlIn = new XSLTInputSource(inDoc.getDocumentElement());
 
       XSLTProcessor processor = XSLTProcessorFactory.getProcessor(new JaxpLiaison());
 
 
       processor.process(xmlIn,
       xsltIn,
       rt);
 
       }
 
Node output = rt.getNode();

  catch(Exception e){
       System.out.println(e.getMessage());
       }
 }
 
 
 
 
Both  the XML and XSL have been successfully processed before
 
my XML :
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<orderProviderList><startDate>15-Apr-2001</startDate><endDate>25-Apr-2001</endDate><order><order_no>10002</order_no>
<buyer_name>Heyster</buyer_name><order_date>16/04/2001 08:05</order_date><order_total>R0.00</order_total>
</order><order><order_no>10003</order_no><buyer_name>David</buyer_name><order_date>16/04/2001 19:58</order_date>
<order_total>R597.61</order_total></order><order>
 
my XSL:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<output>
<xsl:template match="/">
 <tr>
  <td colspan="4" width="100%" align="center" class="cheading">
  Order Table
  </td>
 </tr>
 <tr bgcolor="#e9e9df">
  <b>
  <td class="text">
   Order No
  </td>
  <td class="text">
   Customer Name
  </td>
  <td class="text">
   Order Date
  </td>
  <td class="text">
   Total
  </td>
  </b>
 </tr>
 <xsl:for-each select="orderProviderList/order">
 <tr>
  <td align="left" valign="top">
   <u/>
    <a>
     <xsl:attribute name="href">
      orderProducts.jsp?orderNo=<xsl:value-of select="order_no"/>&amp;startDate=<xsl:value-of select="//startDate"/>&amp;endDate=<xsl:value-of select="//endDate"/>&amp;cursor=<xsl:value-of select="//cursor"/>
     </xsl:attribute>
      <xsl:value-of select="order_no"/>
    </a>
  </td>
  <td align="left" valign="top" class="text">
   <xsl:value-of select="buyer_name"/>
  </td>
  <td align="left" valign="top" class="text">
   <xsl:value-of select="order_date"/>
  </td>
  <td align="right" valign="top" class="text">
   <xsl:value-of select="order_total"/>
  </td>
 </tr>
 </xsl:for-each>
 </xsl:template>
 </output>
 </xsl:stylesheet>
 
Thanks
 

Reply via email to