cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nicola Ken Barozzi" <nicola...@supereva.it>
Subject Re: One XML doc, two presentations (HTML & PDF)
Date Sun, 02 Jul 2000 08:25:33 GMT
----- Original Message ----- 
From: "Rick Tessner" <rick@dingle.myra.com>
To: <cocoon-users@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



Mime
View raw message