You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by ab...@quadrante.com on 2001/02/11 12:49:01 UTC

How can I get both a HTML and a PDF output from the same XML source file?

I thoroughly read the FAQ (in particular the "How do I chain stylesheets" 
item) and I tried hard to get both a (X)HTML and a PDF output from the
same XML source file by applying two different XSL-T stylesheets.

The first stylesheet is a regular XML->(X)HTML converter and it works fine.

The second stylesheet tries to create a XSL-FO file from the XML source
and post-process it with the Cocoon XSL:FO engine. This second XSL-T
stylesheet does not work. I'm able to get a valid PDF file sent to my
internet browser (MS IE 5.5 on Windows 98) but this PDF file is presented 
in the browser window as it was a ASCII text file. Acrobat Reader is not
invoked by the browser.

As long as I can understand, this happens because of the lacking of the
<?xml version="1.0"?> element in the XSL:FO output produced by my XSL-T
stylesheet. Unfortunatley, I cannot insert this element in my output
using the "xsl:processing-instruction" because the XSL engine complains
about an illegal operation ('processing-instruction cannot be "xml"'). I
did not understand how to use the second technique mentioned in the "my
processing instruction disapper..." of the FAQ, that is by using an
"apply-templates" element that matches processing instructions, so I did
not try it.

Does anybody know how to get both HTML and PDF output from the same XML
file by applying two different stylesheets?

Does anybody have a working example of a single XML file converted into
both HTML and PDF using different stylesheets?

Many thanks in advance

---------------------
Alessandro Bottoni
Web Architect
Quadrante SRL - Italy
http://www.quadrante.com
office: abottoni@quadrante.com
personal: alessandro.bottoni@libero.it



Re: How can I get both a HTML and a PDF output from the same XML source file?

Posted by Oliver Gries <gr...@java-concepts.com>.
Hi,

if you can use a parameter to specify the output format, then following 
style should work (you have to refer to it in your xml file, of course).

At leats I use it in this way:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:param name="out"/>
<xsl:param name="lang"/>

<xsl:template match="/">
  <xsl:processing-instruction 
name="cocoon-process">type="xslt"</xsl:processing-instruction>
   <xsl:choose>
   <xsl:when test="$out='html'">
         <xsl:processing-instruction 
name="xml-stylesheet">href="styles/style_html.xsl" 
type="text/xsl"</xsl:processing-instruction>
   </xsl:when>
   <xsl:when test="$out='pdf'">
         <xsl:processing-instruction 
name="xml-stylesheet">href="styles/style_fo.xsl" 
type="text/xsl"</xsl:processing-instruction>
   </xsl:when>
   <xsl:when test="$out='xml'">
         <xsl:processing-instruction 
name="xml-stylesheet">href="../styles/style_xml.xsl" 
type="text/xsl"</xsl:processing-instruction>
   </xsl:when>
   </xsl:choose>

<xsl:copy-of select="*root node of your xml source file*"/>

</xsl:template>
  
</xsl:stylesheet>

Hope this helps.
Olli


abottoni@quadrante.com wrote:

> I thoroughly read the FAQ (in particular the "How do I chain stylesheets" 
> item) and I tried hard to get both a (X)HTML and a PDF output from the
> same XML source file by applying two different XSL-T stylesheets.
> 
> The first stylesheet is a regular XML->(X)HTML converter and it works fine.
> 
> The second stylesheet tries to create a XSL-FO file from the XML source
> and post-process it with the Cocoon XSL:FO engine. This second XSL-T
> stylesheet does not work. I'm able to get a valid PDF file sent to my
> internet browser (MS IE 5.5 on Windows 98) but this PDF file is presented 
> in the browser window as it was a ASCII text file. Acrobat Reader is not
> invoked by the browser.
> 
> As long as I can understand, this happens because of the lacking of the
> <?xml version="1.0"?> element in the XSL:FO output produced by my XSL-T
> stylesheet. Unfortunatley, I cannot insert this element in my output
> using the "xsl:processing-instruction" because the XSL engine complains
> about an illegal operation ('processing-instruction cannot be "xml"'). I
> did not understand how to use the second technique mentioned in the "my
> processing instruction disapper..." of the FAQ, that is by using an
> "apply-templates" element that matches processing instructions, so I did
> not try it.
> 
> Does anybody know how to get both HTML and PDF output from the same XML
> file by applying two different stylesheets?
> 
> Does anybody have a working example of a single XML file converted into
> both HTML and PDF using different stylesheets?
> 
> Many thanks in advance
> 
> ---------------------
> Alessandro Bottoni
> Web Architect
> Quadrante SRL - Italy
> http://www.quadrante.com
> office: abottoni@quadrante.com
> personal: alessandro.bottoni@libero.it
> 
> 
> 
> ---------------------------------------------------------------------
> Please check that your question has not already been answered in the
> FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
> 
> To unsubscribe, e-mail: <co...@xml.apache.org>
> For additional commands, e-mail: <co...@xml.apache.org>
> 


RE: How can I get both a HTML and a PDF output from the same XML source file?

Posted by John Menke <jo...@eagleinfosystems.com>.
I use the following code at the top of my XML files.  It checks the query
string for a value and picks the correct Stylesheet.

<?xml version="1.0"?>
<!-- edited with XML Spy v3.5 (http://www.xmlspy.com) by john menke (eagle
information systems) -->
<?cocoon-process type="xsp"?>
<?cocoon-process type="xslt"?>
<xsp:page language="java" xmlns:xsp="http://www.apache.org/1999/XSP/Core">
	<page title="My Page">
		<xsp:logic>

	String[] param = request.getParameterValues("dummy");
	String stylesheet;
	if (param != null) {
		stylesheet = "pdf.xsl";
	} else {
		stylesheet = "html.xsl";
	}


</xsp:logic>
		<xsp:pi target="xml-stylesheet">
                href="<xsp:expr>stylesheet</xsp:expr>"
                type="text/xsl"
</xsp:pi>


> -----Original Message-----
> From: abottoni@quadrante.com [mailto:abottoni@quadrante.com]
> Sent: Sunday, February 11, 2001 6:49 AM
> To: cocoon-users@xml.apache.org
> Subject: How can I get both a HTML and a PDF output from the same XML
> source file?
>
>
> I thoroughly read the FAQ (in particular the "How do I chain stylesheets"
> item) and I tried hard to get both a (X)HTML and a PDF output from the
> same XML source file by applying two different XSL-T stylesheets.
>
> The first stylesheet is a regular XML->(X)HTML converter and it
> works fine.
>
> The second stylesheet tries to create a XSL-FO file from the XML source
> and post-process it with the Cocoon XSL:FO engine. This second XSL-T
> stylesheet does not work. I'm able to get a valid PDF file sent to my
> internet browser (MS IE 5.5 on Windows 98) but this PDF file is presented
> in the browser window as it was a ASCII text file. Acrobat Reader is not
> invoked by the browser.
>
> As long as I can understand, this happens because of the lacking of the
> <?xml version="1.0"?> element in the XSL:FO output produced by my XSL-T
> stylesheet. Unfortunatley, I cannot insert this element in my output
> using the "xsl:processing-instruction" because the XSL engine complains
> about an illegal operation ('processing-instruction cannot be "xml"'). I
> did not understand how to use the second technique mentioned in the "my
> processing instruction disapper..." of the FAQ, that is by using an
> "apply-templates" element that matches processing instructions, so I did
> not try it.
>
> Does anybody know how to get both HTML and PDF output from the same XML
> file by applying two different stylesheets?
>
> Does anybody have a working example of a single XML file converted into
> both HTML and PDF using different stylesheets?
>
> Many thanks in advance
>
> ---------------------
> Alessandro Bottoni
> Web Architect
> Quadrante SRL - Italy
> http://www.quadrante.com
> office: abottoni@quadrante.com
> personal: alessandro.bottoni@libero.it
>
>
>
> ---------------------------------------------------------------------
> Please check that your question has not already been answered in the
> FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
>
> To unsubscribe, e-mail: <co...@xml.apache.org>
> For additional commands, e-mail: <co...@xml.apache.org>
>