You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Mariusz Nowostawski <ma...@marni.otago.ac.nz> on 2000/08/03 11:46:58 UTC

including html piece

I finally almost made my xinclude working, i.e. when the file ref is wrong
it throws a nice java.io.FileNotFoundException: path/file
however when file ref is correct it gives:

java.lang.NullPointerException
at org.apache.cocoon.processor.xinclude.XIncludeProcessor$XIncludeProcessorWorker.processXIncludeElement(Compiled Code)
at org.apache.cocoon.processor.xinclude.XIncludeProcessor$XIncludeProcessorWorker.process(Compiled Code)
at org.apache.cocoon.processor.xinclude.XIncludeProcessor$XIncludeProcessorWorker.process(Compiled Code)
at org.apache.cocoon.processor.xinclude.XIncludeProcessor$XIncludeProcessorWorker.process(Compiled Code)
at org.apache.cocoon.processor.xinclude.XIncludeProcessor$XIncludeProcessorWorker.process(Compiled Code)
at org.apache.cocoon.processor.xinclude.XIncludeProcessor$XIncludeProcessorWorker.process(Compiled Code)
at org.apache.cocoon.processor.xinclude.XIncludeProcessor$XIncludeProcessorWorker.process(Compiled Code)
at org.apache.cocoon.processor.xinclude.XIncludeProcessor.process(Compiled Code)
at org.apache.cocoon.Engine.handle(Compiled Code)
at org.apache.cocoon.Cocoon.service(Compiled Code)
at javax.servlet.http.HttpServlet.service(Compiled Code)
at org.apache.jserv.JServConnection.run(Compiled Code)
at java.lang.Thread.run(Compiled Code)

Why?  ;o)  

What I want to do, is to reuse a piece of HTML which I repeat all over
again in different generated dynamically pages. I though I can use
xinclude for including piece of HTML, but I suspect I cannot.
What I should do instead? I could use entities if only I knew how to
declare and include them dynamically in HTML page?
Any suggestions?

thanks in advance
Mariusz


Re: Applying a different stylesheet - possible?

Posted by Yngve Svendsen <yn...@clustra.com>.
At 16:04 04.08.00 +0200, Nicola Ken Barozzi wrote:
>----- Original Message -----
>From: "Yngve Svendsen" <yn...@clustra.com>
>To: <co...@xml.apache.org>
>Sent: Friday, August 04, 2000 11:26 AM
>Subject: RE: Applying a different stylesheet - possible?
>
>In case you mmight need it I'm posing my code whith which
>I answered some time ago.
>Use it at your wish :-)

Thanks! I found your posting a few minutes after I got the more cumbersome 
XSP-based solution to work. I switched to your method because it requires 
no modifications to the source document.

I'll make a web page at http://techsite.yngve.com about my experiences with 
this. The learning curve is extremely steep, and I seem to keep hitting one 
almost-FAQ after another as I work on my company's new support site setup. 
I seem to be in reasonably good shape now, though.

Thanks again to everyone who's helped me!


Re: Applying a different stylesheet - possible?

Posted by Nicola Ken Barozzi <ni...@supereva.it>.
----- Original Message ----- 
From: "Yngve Svendsen" <yn...@clustra.com>
To: <co...@xml.apache.org>
Sent: Friday, August 04, 2000 11:26 AM
Subject: RE: Applying a different stylesheet - possible?

In case you mmight need it I'm posing my code whith which
I answered some time ago. 
Use it at your wish :-)

nicola_ken

Nicola Ken Barozzi - AISA Industries S.p.A
http://www.aisaindustries.it/
Via Leonardo da Vinci,2 Ticengo (CR) Italy
Personal homepage at Java Guru:
http://www.jguru.com/jguru/guru/viewchannel.jsp?EID=39153
Personal FAQ at Java Guru:
http://www.jguru.com/jguru/guru/viewfaqs.jsp?EID=39153
Research Activity:
Politecnico di Milano - Dipartimento di Meccanica
Piazza Leonardo da Vinci, n.32 - 20133 Milano (Italy)


----- Original Message ----- 
From: "Nicola Ken Barozzi" <ni...@supereva.it>
To: <co...@xml.apache.org>
Sent: Sunday, July 02, 2000 10:25 AM
Subject: Re: One XML doc, two presentations (HTML & PDF)


> ----- Original Message ----- 
> From: "Rick Tessner" <ri...@dingle.myra.com>
> To: <co...@xml.apache.org>
> Sent: Saturday, July 01, 2000 8:36 PM
> Subject: One XML doc, two presentations (HTML & PDF)
> 
> 
> > Good Morning All!
> 
> Good Morning!
> It's 10:12 here in Italy!
> 
> > I have what I think should be a fairly trivial thing to do, but
> > I seem to be suffering from some sort of brain-block.
> > 
> > Here's what I'm trying to do.  I have two XSL sheets:
> > 
> >   blat-html.xsl : Transforms to HTML
> >   blat-fo.xsl   : Transforms to FO and formats to PDF
> > 
> > Both of these work just wonderfully.  Now, what I'd like to be able
> > to do is to create a
> > 
> >   blat.xsl
> > 
> > which in turn includes either "blat-html.xsl" or "blat-fo.xsl" depending
> > on whether a parameter has been passed along thru the URL referencing an
> > XML document which uses blat.xsl.
> > 
> > For example, an XML document called "helloworld.xml" uses the
> > xml-stylesheet "blat.xsl".  A call to:
> > 
> >   http://mydomain.com/helloworld.xml
> > 
> > would produce HTML.  A call to
> > 
> >   http://mydomain.com/helloworld.xml?print
> > 
> > would produce PDF.
> > 
> > I already have a series of documents based on "blat-html.xsl" and would
> > simply like to change the reference to "blat.xsl" without having to
> > add an "XSP" code to the XML documents themselves.
> > 
> > Any ideas to what the best way to accomplish this would be?
> > 
> 
> Well, I knew I needed it too but now that you need it too I got myself to do it! (crazy sentence!)
> I tried it on my 1.74 cocoon and it works, I just changed the names for you.
> 
> So, in "helloworld.xml" you put
> 
> <?xml-stylesheet href="blat.xsl" type="text/xsl"?>
> <?cocoon-process type="xslt"?>
> 
> Ok, so you know it, just to make things clear. :-)
> 
> Then here is blat.xsl:
> 
> <?xml version="1.0"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
> 
>  <!-- this is internal reference to the "print" in the url -->
>  <xsl:param name="print"/>
> 
>  <xsl:template match="/">
>   <xsl:choose>
>    <!-- when "print" is specified ... -->
>    <xsl:when test="$print">
>     <xsl:processing-instruction name="xml-stylesheet">href="blat-fo.xsl" type="text/xsl"</xsl:processing-instruction>
>     <xsl:processing-instruction name="cocoon-process">type="xslt"</xsl:processing-instruction>
>    </xsl:when>
>    <xsl:otherwise>
>     <xsl:processing-instruction name="xml-stylesheet">href="blat-html.xsl" type="text/xsl"</xsl:processing-instruction>
>     <xsl:processing-instruction name="cocoon-process">type="xslt"</xsl:processing-instruction>
> </xsl:otherwise>
>   </xsl:choose>  
>  
>     <xsl:apply-templates/>
> 
>  </xsl:template>
> 
>  <!-- copy everyting else except processing instructions; be careful if you need them...-->
>   <xsl:template match="@*|*|text">
>     <xsl:copy>
>       <xsl:apply-templates select="@*|*|text"/>
>     </xsl:copy>
>   </xsl:template>
> 
> </xsl:stylesheet>
> 
> Here it is!
> 
> I don't know if it's the best way, but it works. :-)
> 
> Ken
> 
> Nicola Ken Barozzi - AISA Industries S.p.A 
> http://www.aisaindustries.it/
> Via Leonardo da Vinci,2 Ticengo (CR) Italy
> Personal homepage at Java Guru: http://www.jguru.com/jguru/guru/viewchannel.jsp?EID=39153
> Personal FAQ at Java Guru: http://www.jguru.com/jguru/guru/viewfaqs.jsp?EID=39153
> Research Activity: 
> http://robotica.mecc.polimi.it
> Politecnico di Milano - Dipartimento di Meccanica
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: cocoon-users-help@xml.apache.org
> 
> 











RE: Applying a different stylesheet - possible?

Posted by Yngve Svendsen <yn...@clustra.com>.
At 10:48 04.08.00 +0200, you wrote:
>You should read the thread about "creating PIs at runtime" from
>last week! By creating your PIs at runtime you can achieve to have
>a paramter (let's say media) that specifies the stylesheet/contente type!

Thanks a bunch! I obviously didn't spend enough time searching the archives 
last night.

I had a slight hunch that it might be possible to do it this way. If I can 
get it to work, I'll make a little how-to web page about it.


Yngve Svendsen
IS Engineer
Clustra AS, Trondheim, Norway
yngve.svendsen@clustra.com
Cell.: +47 913 915 02


RE: Applying a different stylesheet - possible?

Posted by Torsten Curdt <tc...@dff.st>.
> I am running a Cocoon-based setup with Apache JServ. For the time being, 
> the only purpose it is being used for is applying fairly simple XSL 
> stylesheets to XML docs.
> 
> The setup runs nicely, but I have run into one seemingly insurmountable 
> problem: Cocoon seems to lack the capability for applying a different 
> stylesheet to a document than the one specified in the document 
> itself.

You should read the thread about "creating PIs at runtime" from
last week! By creating your PIs at runtime you can achieve to have
a paramter (let's say media) that specifies the stylesheet/contente type!

Cheers
--
Torsten

Applying a different stylesheet - possible?

Posted by Yngve Svendsen <yn...@clustra.com>.
I am running a Cocoon-based setup with Apache JServ. For the time being, 
the only purpose it is being used for is applying fairly simple XSL 
stylesheets to XML docs.

The setup runs nicely, but I have run into one seemingly insurmountable 
problem: Cocoon seems to lack the capability for applying a different 
stylesheet to a document than the one specified in the document itself. Our 
setup uses a form where users specify what document they need and whether 
the document should be formatted for screen or print. The form data gets 
posted to a simple script which redirects the client to the requested 
document. I know that Cocoon supports different media types, but I see no 
way of modifying the User-Agent header in the client request in order to 
exploit this.

Our former, purely Xalan-based servlet setup had a simple mechanism for 
applying different stylesheets, but Cocoon seems to be unable to do this. 
Has anyone been able to find a workaround for this? I should probably add 
that I know very little Java.

This might be an FAQ, but the only references to this kind of problem I've 
been able to find are almost a year old.

Yngve Svendsen
yngve.svendsen@clustra.com


Re: including html piece

Posted by Donald Ball <ba...@webslingerZ.com>.
On Thu, 3 Aug 2000, sudhi wrote:

> Hi..
> Even I had the same problem. This happens in Windows only as for as I
> know.
> My config is like this
> Windows NT 4
> Apache 1.3.12
> Apache Jserv 1.1.1
> Cocoon 1.7.4
> JDK 1.1.8
> JSDK 2.0
> 
> When I try to include a file using xinclude, i always get this error.
> Where as the same combination of Apache, Jserv Cocoon ,jdk and jsdk
> works fine on Unix. 
> 
> Here is where the problem is.
> 
> I think in XIncludeProcessor.java , line 125 (inside method
> XIncludeProcessorWorker(..) )
> [snip]
> 		base_file = new File((new File(basename)).getParent());
> [snip]
> 
> Will return null on windows . 
> So for me xinclude never worked on windows :-(

try the latest cvs cocoon. xinclude has evolved considerably since 1.7.4
(though it's still problematic)

- donald


Re: including html piece

Posted by sudhi <su...@insage.com>.
Hi..
Even I had the same problem. This happens in Windows only as for as I
know.
My config is like this
Windows NT 4
Apache 1.3.12
Apache Jserv 1.1.1
Cocoon 1.7.4
JDK 1.1.8
JSDK 2.0

When I try to include a file using xinclude, i always get this error.
Where as the same combination of Apache, Jserv Cocoon ,jdk and jsdk
works fine on Unix. 

Here is where the problem is.

I think in XIncludeProcessor.java , line 125 (inside method
XIncludeProcessorWorker(..) )
[snip]
		base_file = new File((new File(basename)).getParent());
[snip]

Will return null on windows . 
So for me xinclude never worked on windows :-(
HTH
Sudhi

Some sort of jsp processor, calling from my servlet engine

Posted by Ben Zeigler <jz...@cncn.com>.
Is there some way to use jsp instead of xsp, Like some sort of jsp processor?  Failing that, is there any way to call
cocoon's functions without using the program as standalone?  What I basically want to do is combine cocoon with Websphere
application server, and combine websphere's excellent jsp with cocoon's XML stuff.  Any information would be helpful.
Thanks.

-Ben Zeigler


Re: including html piece

Posted by Mariusz Nowostawski <ma...@marni.otago.ac.nz>.
Thanks for help, Donald.  

The PI as a second line of the stylesheet was put there by mistake. 
You got my intent right, I guess.

> >    <xinclude:include parse="xml" href="menu.htmlf" /> 
> this is no longer valid - see the latest version of the xinclude working
> draft.

I have changed the inclusion line to (to be sure about namespace
scope I copied it from draft example ;)
<include xmlns:xinclude="http://www.w3.org/1999/XML/xinclude" xinclude:parse="xml" xinclude:href="menu.htmlf" />

Is this syntax right? This renders the HTML output as before, to:

<include xinclude:href="menu.htmlf" xinclude:parse="xml"></include>

I have not changed anything else from my previous post, so the
interested stylesheet bit looks exactly:

----------------------
<?xml version="1.0"?>

<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
    xmlns:xinclude="http://www.w3.org/1999/XML/xinclude" >

<xsl:template match="modules">
<xsl:processing-instruction name="cocoon-format">type="text/html"</xsl:processing-instruction>
<xsl:processing-instruction name="cocoon-process">type="xinclude"</xsl:processing-instruction>

<html>
 <head>
   <LINK href="/stylesheets/secmlA.css" rel="stylesheet" type="text/css"/>
   <title><xsl:text>Resources</xsl:text></title>
 </head>
 <body>

<include xmlns:xinclude="http://www.w3.org/1999/XML/xinclude" xinclude:parse="xml" xinclude:href="menu.htmlf" />

[...]

----------

and the produced output is:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html xmlns:xinclude="http://www.w3.org/1999/XML/xinclude"><head><LINK
href="/stylesheets/secmlA.css" rel="stylesheet" type="text/css">
<title>Resources</title>
</head><body><include xinclude:href="menu.htmlf" xinclude:parse="xml"></include>

[...]

I am using the very current CVS version.


If I am still doing something wrong, I am surely not aware of it, and I am
very sorry for my stupidity - I suspect it might be some very stupid typo
or something, but Cocoon is not complaining, which is the suspicious part.

Thank you once again for help
cheers, Mariusz
`


Re: including html piece

Posted by Donald Ball <ba...@webslingerZ.com>.
On Fri, 4 Aug 2000, Mariusz Nowostawski wrote:

> Sorry, I should have done it before I have originally posted the question 
> - After updating to Cocoon-1.8-dev from CVS the exception which I was
> quoting for Cocoon-1.7.4 is not any more the case, which is good. 
> However, now I think I have exactly the same situation as Ulrich (if I
> recall correctly):
> 
> I have simple XML source which is processed by XSLT and produces HTML
> page.
> 
> the XSL looks like:
> 
> <?xml version="1.0"?>
> <?cocoon-process type="xinclude"?>

cocoon PIs don't belong in stylesheets. you're doing the right thing below
by creating the PI using xsl:processing-instruction - if i understand your
intent anyway.

> <xsl:stylesheet 
>     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
>     xmlns:xinclude="http://www.w3.org/1999/XML/xinclude" >
> 
> <xsl:template match="modules">
> <xsl:processing-instruction name="cocoon-process">type="xinclude"</xsl:processing-instruction>
> <xsl:processing-instruction name="cocoon-format">type="text/html"</xsl:processing-instruction>
> <html>
>  <head>
>    <LINK href="/stylesheets/secmlA.css" rel="stylesheet" type="text/css"/>
>    <title><xsl:text>Resources</xsl:text></title>
>  </head>
>  <body>
>    <xinclude:include parse="xml" href="menu.htmlf" />

this is no longer valid - see the latest version of the xinclude working
draft.

> [...]
> 
>  </body>
> </html></xsl:stylesheet>
> 
> and it produces HTML with:
> 
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
> <html xmlns:xinclude="http://www.w3.org/1999/XML/xinclude">
> <head><LINK href="/stylesheets/secmlA.css" rel="stylesheet" type="text/css">
> <title>Resources</title>
> <body>
>  <xinclude:include href="menu.htmlf" parse="xml"></xinclude:include>
> 
> [...]
> 
> btw, this menu.htmlf is a fragment of proper XHTML, i.e. a single table.
> Why this xinclude instruction is not beeing processed? Am I doing
> something wrong way? Swapping the order of PIs does not help.

i think if you fix your syntax it should work. check out the latest cvs
version and send me the output if my suggestion does _not_ work.

- donald


Re: including html piece

Posted by Mariusz Nowostawski <ma...@marni.otago.ac.nz>.
Sorry, I should have done it before I have originally posted the question 
- After updating to Cocoon-1.8-dev from CVS the exception which I was
quoting for Cocoon-1.7.4 is not any more the case, which is good. 
However, now I think I have exactly the same situation as Ulrich (if I
recall correctly):

I have simple XML source which is processed by XSLT and produces HTML
page.

the XSL looks like:

<?xml version="1.0"?>
<?cocoon-process type="xinclude"?>

<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
    xmlns:xinclude="http://www.w3.org/1999/XML/xinclude" >

<xsl:template match="modules">
<xsl:processing-instruction name="cocoon-process">type="xinclude"</xsl:processing-instruction>
<xsl:processing-instruction name="cocoon-format">type="text/html"</xsl:processing-instruction>
<html>
 <head>
   <LINK href="/stylesheets/secmlA.css" rel="stylesheet" type="text/css"/>
   <title><xsl:text>Resources</xsl:text></title>
 </head>
 <body>
   <xinclude:include parse="xml" href="menu.htmlf" />

[...]

 </body>
</html></xsl:stylesheet>

and it produces HTML with:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html xmlns:xinclude="http://www.w3.org/1999/XML/xinclude">
<head><LINK href="/stylesheets/secmlA.css" rel="stylesheet" type="text/css">
<title>Resources</title>
<body>
 <xinclude:include href="menu.htmlf" parse="xml"></xinclude:include>

[...]

btw, this menu.htmlf is a fragment of proper XHTML, i.e. a single table.
Why this xinclude instruction is not beeing processed? Am I doing
something wrong way? Swapping the order of PIs does not help.

with best regards
Mariusz



On Thu, 3 Aug 2000, Donald Ball wrote:
> On Thu, 3 Aug 2000, Mariusz Nowostawski wrote:
> > I finally almost made my xinclude working, i.e. when the file ref is wrong
> > it throws a nice java.io.FileNotFoundException: path/file
> > however when file ref is correct it gives:
> > 
> > java.lang.NullPointerException
> > [...]
>
> can you send me the including file, the included file, and a stack trace
> of this exception with the JIT disabled (line numbers are your friend)?
> 
> > [...]
> 
> should be able to include it if it's valid XHTML.


Re: including html piece

Posted by Donald Ball <ba...@webslingerZ.com>.
On Thu, 3 Aug 2000, Mariusz Nowostawski wrote:

> I finally almost made my xinclude working, i.e. when the file ref is wrong
> it throws a nice java.io.FileNotFoundException: path/file
> however when file ref is correct it gives:
> 
> java.lang.NullPointerException
> at org.apache.cocoon.processor.xinclude.XIncludeProcessor$XIncludeProcessorWorker.processXIncludeElement(Compiled Code)
> at org.apache.cocoon.processor.xinclude.XIncludeProcessor$XIncludeProcessorWorker.process(Compiled Code)
> at org.apache.cocoon.processor.xinclude.XIncludeProcessor$XIncludeProcessorWorker.process(Compiled Code)
> at org.apache.cocoon.processor.xinclude.XIncludeProcessor$XIncludeProcessorWorker.process(Compiled Code)
> at org.apache.cocoon.processor.xinclude.XIncludeProcessor$XIncludeProcessorWorker.process(Compiled Code)
> at org.apache.cocoon.processor.xinclude.XIncludeProcessor$XIncludeProcessorWorker.process(Compiled Code)
> at org.apache.cocoon.processor.xinclude.XIncludeProcessor$XIncludeProcessorWorker.process(Compiled Code)
> at org.apache.cocoon.processor.xinclude.XIncludeProcessor.process(Compiled Code)
> at org.apache.cocoon.Engine.handle(Compiled Code)
> at org.apache.cocoon.Cocoon.service(Compiled Code)
> at javax.servlet.http.HttpServlet.service(Compiled Code)
> at org.apache.jserv.JServConnection.run(Compiled Code)
> at java.lang.Thread.run(Compiled Code)
> 
> Why?  ;o)  

can you send me the including file, the included file, and a stack trace
of this exception with the JIT disabled (line numbers are your friend)?

> What I want to do, is to reuse a piece of HTML which I repeat all over
> again in different generated dynamically pages. I though I can use
> xinclude for including piece of HTML, but I suspect I cannot.
> What I should do instead? I could use entities if only I knew how to
> declare and include them dynamically in HTML page?

should be able to include it if it's valid XHTML.

- donald