What causes </HEAD> to be sent? Let's assume you have a pipe consisting of a generator, a transformer and a serializer. Normally the XSP creates SAX events for a XML like this:

<page>
<title>test page</title>
<paragraph>A short sentence.</paragraph>
</page>

But in some special cases a redirect shoud happen:

<page>
<redirect url="http://www.new.url.com"/>
</page>

And the transformer can look like:

<xsl:template match="page">
<html>
<head>
<xsl:apply-templates select="title | redirect"/>
</head>
<body>
<xsl:apply-templates select="paragraph"/>
</body>
</html>
</xsl:template>

<xsl:template match="title">
<xsl:copy-of select="."/>
</xsl:template>

<xsl:template match="redirect">
<meta http-equiv="Refresh" content="0; URL={@url}"/>
</xsl:template>

<xsl:template match="paragraph">
...
</xsl:template>

Who should close the <head/> element? The transformer can not send an endElement() until everything inside is processed. Of course you have to process <redirect/> in <head/> independent where it was written in the original XML.

Even if the generated XML is much more complex and the <redirect/> element is created as last beneath thousands of other elements, if you use a stylesheet similar to the above one, which says "process this <redirect/> now, because I want to have it as child of <head/>", the SAX event for endElement() of <head/> can't be sent to the serializer.

I don't want to say something wrong, but let me speak in pictures: A pipe is not a single lane tube, where the first car, which gets in, is the first car, which must get out. A transformer can disturb this perfect organisation. Let it be a car park, where everything can get mixed up: If all the cars come out of the tube and have to wait at the car park until the last car comes also out, because this one must be the first, which gets into the next tube, it will be obviously bad, but not impossible. (If the car park is full, you will have an OutOfMemoryError or a NoMoreDTMIdsException. ;-) Furthermore this shows, how important well structured XML and good stylesheets are. Especially the usage of "//redCars" has to search all cars for red ones.

Does this make it a bit clearer? Everybody can of course improve my "model" ;-) What about structured car transports or child cars?

Regards,

Joerg

Artur Bialecki wrote:
Hi Joerg,

I was under the impression that once generation started
sax events go through tarnsformers and a serializer and
data is sent back to the browser. So if the <redirect url="any"/>
is emitted after the tags that caused </HEAD> to be sent
to the browser this would not work.

Would it?

Artur...


-----Original Message-----
From: Joerg Heinicke [mailto:joerg.heinicke@;gmx.de] Sent: November 8, 2002 7:42 PM
To: [EMAIL PROTECTED]
Subject: Re: Redirect in XSP


Hi Artur,

where is the problem?

Instead of <xsp-response:send-redirect url="any"/> you create a own element like <redirect url="any"/> in the XML. This is processed by a transformer to <meta http-equiv="Refresh" content="0; URL=any"/> and sent to the browser. Even if it's a very poor solution, there shell be no problem with it. I prefer the test while setting up the pipeline.

Regards,

Joerg

Artur Bialecki wrote:

-----Original Message-----
From: Ilya A. Kriveshko [mailto:ilya@;kaon.com] Sent: November 8, 2002 10:41 AM
To: [EMAIL PROTECTED]
Subject: Re: Redirect in XSP


If you want to redirect the browser to a new URL after the
pipeline has been constructed and the generation has (possibly)
started, you can do that by outputting the <META> tag in the
output HTML.

<meta http-equiv="Refresh" content="0; URL=/some/local/url"/>
or
<meta http-equiv="Refresh" content="0; URL=http://some.com/other/url"/>

"0" means no delay.

How would this work if half of my page has already been
sent to the browser including the </HEAD> tag?
Please clarify.


Artur...

---------------------------------------------------------------------
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