You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Rick Tessner <ri...@dingle.myra.com> on 2000/07/01 20:36:40 UTC

One XML doc, two presentations (HTML & PDF)

Good Morning All!

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?

Thanks and a Happy Canada Day to all the Canadians out there!


-- 
Rick Tessner	rick@myra.com
MYRA Systems Corp. Fone: (250) 381 1335 x125  Phax: (250) 381 1304
                   Cell: (250) 885 9452

"Hmmm.  They have the Internet on computers now."



Re: One XML doc, two presentations (HTML & PDF)

Posted by Nicola Ken Barozzi <ni...@supereva.it>.
----- 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



Producer accessing ServletContext

Posted by Paul Lawton <pa...@wirestation.co.uk>.
I've created my own Producer within Cocoon.

Depending on the file extension - I either display a particular page or try
and forward some details to another page which creates a frameset based up
the url details fed into the Producer.

Is it possible and if so how can I get access to the ServletContext -
specifically - HttpServletResponse from within my Producer?

Paul