You must call startDocument() and endDocument() on FormatterListener's, or
else the results are undefined.  In the case of FormatterToXML(), the
buffer will not be flushed.  Of course, the results for FormatterToHTML are
far more annoying!  ;-)

Dave



|---------+--------------------------->
|         |           Holger Floerke  |
|         |           <floerke@doctron|
|         |           ic.de>          |
|         |                           |
|         |           03/28/2002 03:13|
|         |           AM              |
|         |           Please respond  |
|         |           to xalan-dev    |
|         |                           |
|---------+--------------------------->
  
>---------------------------------------------------------------------------------------------------------------------------|
  |                                                                                    
                                       |
  |        To:      [EMAIL PROTECTED]                                           
                                       |
  |        cc:      (bcc: David N Bertoni/Cambridge/IBM)                               
                                       |
  |        Subject: Extension function write(...) (Xalan-C)                            
                                       |
  
>---------------------------------------------------------------------------------------------------------------------------|



Because there is no extension element "xalan:Redirect" in Xalan-C and there

are no extension elements at all, I tried to build a "write"-function. You
schould be able to spool the content you which to write in a variable and
call the function with the variable an a filename.

<xsl:variable name="content">
    <A>
    </A>
</xsl:variable>
<xsl:value-of select="foo:write($content,'test')"/>

The function is implemented as you see below. There are two problems.
1) If I use the "FormatterToHTML", the application crashes
2) If I use the "FormatterToXML", the output is cached and written in
"1024" byte chunks. So the file is shortened and broken.

Does anybody know why?

HolgeR



XObjectPtr
FunctionWrite::execute(
                         XPathExecutionContext&  executionContext,
                         XalanNode*                              /* context
*/,
                         const XObjectPtr                arg1,
       const XObjectPtr    arg2,
                         const Locator*                  /* locator */)
const
{
         assert(arg1.null() == false && arg2.null() == false);

   const ResultTreeFragBase&     rtree1 = arg1->rtree();

   // we need a single Root-Node
   XalanNode* rootNode = rtree1.getNodesetRoot();

   if (rootNode != NULL)
   {
     XalanFileOutputStream oOutStream(arg2->str(),8192);
     XalanOutputStreamPrintWriter oWriter(oOutStream,true);
     FormatterToHTML oListener(
       oWriter,
       XalanDOMString("iso-8859-1")
       );
     FormatterTreeWalker oWalker(oListener);
     oWalker.traverse(rootNode);

     oWriter.flush();
     oOutStream.flush();
   }
   else
   {
         return executionContext.getXObjectFactory().createBoolean(false);
   }

         return executionContext.getXObjectFactory().createBoolean(true);
}



--
holger floerke                     d  o  c  t  r  o  n  i  c
email [EMAIL PROTECTED]         information publishing + retrieval
phone +49 2222 9292 90             http://www.doctronic.de






Reply via email to