You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Holger Floerke <fl...@doctronic.de> on 2002/03/28 12:13:08 UTC

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 floerke@doctronic.de         information publishing + retrieval
phone +49 2222 9292 90             http://www.doctronic.de


Re: Extension function write(...) (Xalan-C)

Posted by Holger Floerke <fl...@doctronic.de>.
>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.
Sorry, I was too fast writing to the List. The solution is to call 
startDocument() and endDocument() from the FormatterListener...

--8<-- snip --8<--
     oListener.startDocument();

     FormatterTreeWalker oWalker(oListener);
     oWalker.traverse(rootNode);

     oListener.endDocument();
--8<-- snip --8<--

Anybody interested in this function?

HolgeR

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