You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Michael French <mf...@zycor.lgc.com> on 2000/03/22 17:15:28 UTC

RE: 2 xslt transformations RE: One XML -> 2 XSLs


> -----Original Message-----
> From: Ulrich Mayring [mailto:ulim@denic.de]
> Sent: Tuesday, March 21, 2000 9:30 AM
> To: cocoon-users@xml.apache.org
> Subject: Re: 2 xslt transformations
> 
> john@micromuse.com wrote:
> > 
> > Is it possible to run an xml file through 2 different 
> > xsl transformations using 2 xsl stylesheets?
> > 
> > So that the xml generated by the first transformation 
> > then gets changed again by the application of the 
> > second stylesheet.
> 
> The easiest thing is to import or include the second stylesheet in the
> first.
> 
> Otherwise, look at the XSP samples supplied with cocoon. The first
> stylesheet is an XSP stylesheet and that calls an XSL stylesheet, when
> it's done.

This example is extremely strange and interesting 
(and confusing first time you look at it !). 
It performs the XSLT first, then the XSP expansion, 
then a final presentation XSLT.

The first XSL is a pure XSL which introduces the XSP tags into 
the main Cocoon pipeline. This is important, because if you 
try to put XSP first to generate the stylesheet, it will be 
in a different request, and so not automatically inherit the 
original headers and parameters....

If you do try to have an XSP generated stylesheet, 
you run into two problems:

  <?xml version="1.0"?>
  <?cocoon-process type="xsp"?>
  <?cocoon-format type="text/xml"?>
  <xsp:page 
    language="java" 
    xmlns:xsp="http://www.apache.org/1999/XSP/Core">

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

  </xsp:page>

XSP does not pass through the XSL namespace
on the root element of the document. 
So the output looks like this:

  <xsl:stylesheet 
       version="1.0">
    ...
  </xsl:stylesheet>

Is this a known bug ? 
Maybe there's a switch to allow namespace declarations through ?

The second issue is that to pass parameters to an XSP stylesheet,
you need to make the original page an XSP, and append the query
string to the XSL href. But XSP does not allow <xsp:xxx> markup
inside <xsp:pi>, so this does not work:

  <xsp:pi name="xml-stylesheet">
    type="text/xsl"
    href="http://.../my.xsp?<xsp:expr>request.getQueryString()</xsp:expr>"
  </xsp:pi>

This is mentioned in the XSP docs, but I haven't looked at the XSP
implementation, so I don't know how to fix it - maybe I'll try :)
Probably means making the xsp:pi take mixed content, 
and chain an apply-templates to the internal mark-up.

[RE:  One XML -> 2 XSLs]
Incidentally this would also allow stylesheet selection
through a request parameter 

  <xsp:pi name="xml-stylesheet">
    type="text/xsl"
    href="<xsp:expr>request.getParameter("xsl")</xsp:expr>"
  </xsp:pi>


Mike