Aha.  For future reference, you probably should have
made it clear from the beginning that you were a)
using javascript xsp, and b) trying to do this
specific thing with retrieving external pages out of
your control.  

That said, you are probably in uncharted waters - but
interesting ones.  The first thing I'd try is make
sure that this ability doesn't already exist by some
miracle in JTidy or another html parser.  I'd suggest
trying the following (but you have to promise to let
me know whether it works or not).

What about tricking the client side javascript into
evaluating the document.write and document.writeln? 
For instance, set up a javascript object called
"document" which initializes an empty text holder and
exposes a write() and writeln() method to append to
that variable.  Then, use eval() on each line taken
out of your script tags.  So,

function write(string) {this.text += string;}
function writeln(string) {this.text += (string +
'\n')};
function doc() {
this.text="";
this.write = write;
this.writeln = writeln;
}

then when you encounter a script section do something
like:
<xsp:logic>
var document = new doc();
eval('document.writeln...);
eval('document.write...);
</xsp:logic>
<xsp:expr>document.text</xsp:expr>

where you take each string to eval out of the incoming
script section, probably in a for loop.  any other
variables and operations it uses to prepare values
should work the same as normal.  You'll have trouble
with escaping quotes, and extracting the strings but
it may be possible.

Other than that, I'm out of ideas.  You may not be
able to do this at all in a way that is worth the
effort.

Geoff

--- Anna Afonchenko <[EMAIL PROTECTED]> wrote:
> I am not using document.write.
> What I am trying to do is load some arbitrary file
> from the net (not my
> file, just any file, so I don't have control on
> what's written inside) and
> if this file contains script tag (which is written,
> for example, in
> Javascript), I want to extract the HTML tree
> fragment that is generated by
> this (Java)script.
> I use xsp to include the given file, that's all,
> then I use xsl to extract
> the data inside the script tags. But what I get is
> again the script code,
> e.g.
> document.write("<center>Hello</center>");
> 
> What I'm asking is whether it's possible to extract
> the HTML that the script
> is writing - in this case it's just to get the value
> of the document.write
> method, but it can be something more complicated.
> I don't know if this can be done at all, in
> Cocoon/XSP/XSL.
> If somebody will have any idea how to do it, I will
> be very thankful.
> Sorry if this is too messy, I am new to this list
> and to cocoon at all.
> Thank you for all the help.
> 
> Anna
> ----- Original Message -----
> From: "Geoff Howard" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Sunday, November 24, 2002 4:54 PM
> Subject: Re: JavaScript problems in XSP
> 
> 
> 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]>
> 
> 
>
---------------------------------------------------------------------
> 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