Why are you using document.write?  document of course
is a reference to the client side document object
which doesn't exist server side at all.  

The problem with your example is that you don't need
javascript (or xsp for that matter) to do any of that.
 Obviously you want to move beyond that though.  It's
also unclear whether you want that fragment to be
included in the sax stream, or whether you want that
output escaped and displayed as is on screen (i think
the first).  

I'm not sure you can (using javascript in xsp) easily
take an xml fragment in string form and generate sax
events from it.   It doesn't matter though because you
probably really don't need to.  What you should
probably do is start with (note the ... implies that
you probably have other page structure but you don't
need to for this example)

<xsp:page language="javascript"
xmlns:xsp="http://apache.org/xsp";>
...
<center>
    <font size="+3">
        This HTML-document has been created with the
help of JavaScript!
    </font>
</center>
...
</xsp:page>

And then use <xsp:logic> <xsp:expr> <xsp:attribute>
<xsp:element> etc to make whatever parts dynamic.

For example, a next step might be : 

<xsp:page language="javascript"
xmlns:xsp="http://apache.org/xsp";>
...
<xsp:logic>
message = "This HTML-document has been created with
the
help of JavaScript!";
</xsp:logic>
<center>
    <font size="+3">
        <xsp:expr>message</xsp:expr>
    </font>
</center>
...
</xsp:page>  

and then, 

<xsp:page language="javascript"
xmlns:xsp="http://apache.org/xsp";>
...
<xsp:logic>
message = "This HTML-document has been created with
the
help of JavaScript!";
displayMessage = true;
</xsp:logic>
...
<xsp:logic>
if (displayMessage) {
  <center>
      <font size="+3">
          <xsp:expr>message</xsp:expr>
      </font>
  </center>
}
</xsp:logic>
...
</xsp:page>  


The best place I know of to read up on the xsp sytax
is
http://outerthought.net/wiki/Wiki.jsp?page=XSPSyntax
as the official docs don't catalog the available tags
IIRC.

If you don't mind me saying so, I'd also suggest that
you read up some more on the basic ideas behind the
cocoon sax pipeline concept and what generators do as
it seems you may have some of the concepts muddled. 
XSP is only a tool for automatically creating a
generator - a compiled java class no matter what
language you script your xsp in.

Best of luck,
Geoff Howard

--- Anna Afonchenko <[EMAIL PROTECTED]> wrote:
> Thank you Ryan. Now what I get when I run the
> pipeline, what I see is the
> result of running the javascript. But what I really
> need is the "source" of
> this javascript, e.g. if the javascript code was:
> document.write("<center><font size=+3>");
> document.write("This HTML-document has been created
> ");
> document.write("with the help of JavaScript!");
> document.write("</font></center>");
> 
> I want to get as a result the xhtml tree fragment
> that is created, e.g. I
> want to get back:
> <center>
>     <font size=+3>
>         This HTML-document has been created with the
> help of JavaScript!
>     </font>
> </center>
> 
> e.g. I want to see the actual HTML code that was
> used in javascript to
> create the given page, and not the result of
> executing it.
> 
> Is it doable in Cocoon/XSP?
> Thank you very much for your help.
> 
> Anna
> 
> ----- Original Message -----
> From: "Ryan Agler" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, November 21, 2002 4:26 PM
> Subject: RE: JavaScript problems in XSP
> 
> 
> Hi Anna,
> Client-side (in your web browser) JavaScript is a
> completely different
> beast than server-side (on your web server)
> JavaScript.  In server-side
> JavaScript, there are no windows, DHTML, or much any
> other properties or
> methods you would use to manipulate a browser for
> dynamic content.
> 
> To use Cocoon to achieve your task, the first step
> would to define
> "given-file.html" in your sitemap, and make sure its
> serialized in
> well-formed XHTML.  Then you could use the Cinclude
> transformer to
> import given-file.html, kind of like this
> (myfile.xsp):
> 
> <?xml version="1.0"?>
> <xsp:page language="java"
> xmlns:xsp=http://apache.org/xsp>
>   <page
>
xmlns:cinclude="http://apache.org/cocoon/include/1.0";>
>     <p>
>       <cinclude:include
> src="cocoon:/given-file.html" />
>     </p>
>   </page>
> </xsp:page>
> 
> and in your sitemap.xmap:
> 
> <map:match pattern="given-file.html">
>   <map:generate type="serverpages"
> src="docs/given-file.xsp" />
>   <map:transform src="stylesheets/given-file.xsl" />
>   <map:serialize type="xhtml"/>
> </map:match>
> 
> <map:match pattern="myfile.xsl">
>   <map:generate type="serverpages"
> src="docs/myfile.xsp" />
>   <map:transform type="cinclude"/>
>   <map:transform src="stylesheets/myfile.xsl" />
>   <map:serialize />
> </map:match>
> 
> HTH
> 
> +Ryan
> 
> -----Original Message-----
> From: Anna Afonchenko [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, November 21, 2002 7:43 AM
> To: [EMAIL PROTECTED]
> Subject: Javascript problems in XSP
> 
> Hi All.
> This is my first post, so don't be angry with me if
> I do something
> wrong.
> I am using XSP on Cocoon 2.0.3, and I want to do the
> following:
> given a name of the html file that contains
> javascript, I want to get
> the result of this javascript and
> put it inside some element in XSP. But when I write
> the following code
> in XSP using javascript:
> <p>
> <xsp:logic>
> var js = window.open("given-file.html");
> var result = js.document.body.innerHTML;
> </xsp:logic>
> <xsp:expr>result</xsp:expr>
> </p>
> 
> nothing happens (even doesn't give any error).
> If I am using this code inside an html file's script
> tag, it works fine.
> If I am trying some simple Javascript functions in
> XSP (e.g. Date()), it
> works.
> Maybe there is some problem with opening files in
> XSP?
> 
> Can somebody please tell me what am I doing wrong
> and how can I get the
> result of javascript code executed in some given
> file?
> 
> Thank you very much in advance.
> 
> Anna
> 
>
---------------------------------------------------------------------
> Please check that your question  has not already
> been answered in the
> FAQ before posting.    
> <http://xml.apache.org/cocoon/faq/index.html>
> 
> To unsubscribe, e-mail:    
> <[EMAIL PROTECTED]>
> For additional commands, e-mail:  
> <[EMAIL PROTECTED]>
> 
> 
>
---------------------------------------------------------------------
> Please check that your question  has not already
> been answered in the
> FAQ before posting.    
> <http://xml.apache.org/cocoon/faq/index.html>
> 
> To unsubscribe, e-mail:    
> <[EMAIL PROTECTED]>
> For additional commands, e-mail:  
> <[EMAIL PROTECTED]>
> 


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus – Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <[EMAIL PROTECTED]>
For additional commands, e-mail:   <[EMAIL PROTECTED]>

Reply via email to