cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nicola Ken Barozzi" <>
Subject Re: One XML doc, two presentations (HTML & PDF)
Date Sun, 02 Jul 2000 08:25:33 GMT
----- Original Message ----- 
From: "Rick Tessner" <>
To: <>
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:
> would produce HTML.  A call to
> 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="" version="1.0">

 <!-- this is internal reference to the "print" in the url -->
 <xsl:param name="print"/>

 <xsl:template match="/">
   <!-- 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: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>


 <!-- copy everyting else except processing instructions; be careful if you need them...-->
  <xsl:template match="@*|*|text">
      <xsl:apply-templates select="@*|*|text"/>


Here it is!

I don't know if it's the best way, but it works. :-)


Nicola Ken Barozzi - AISA Industries S.p.A
Via Leonardo da Vinci,2 Ticengo (CR) Italy
Personal homepage at Java Guru:
Personal FAQ at Java Guru:
Research Activity:
Politecnico di Milano - Dipartimento di Meccanica

View raw message