You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by yahooschrott <ya...@masutti.ch> on 2004/01/18 13:53:02 UTC

using an xsl:fo in a transformer parameter

Hi

I'm trying to pass an "already prepared" fo: snippet (i.e. a valid
<fo:table> section) to the transformation as a parameter but it seems to
be ignored. this is what I do:

  (...)
  String fOTableSnipped = "<fo:table> .... </fo:table>"; // this is
prepared elsewhere

  StreamSource renderer = new StreamSource( rendererXSL );
  Transformer transformer=
TransformerFactory.newInstance().newTransformer( renderer );
  transformer.setParameter( "external_section", foTableSnippet );
  (...)
  _transformer.transform(new StreamSource(new CharArrayReader(sourceXML)),
new SAXResult(_driver.getContentHandler()));
  (...)

in the XSL I use the variable in the following way:
<xsl:value-of select="$external_section" disable-output-escaping="yes"/>

For simple Strings and other parameters, this works fine, however when I
want to pass an already prepared fo, it never makes it into the output
(PDF, AWT). I would have expected this to work since I use
disable-output-escaping, but apparently it does not.

When I run the XSL transformation only (transform an XML into a XSL:FO),
it looks perfectly okay, the <fo:table> is where it is supposed to be. I
haven't tried but I assume a 2-step transformation (first to XSL:FO, then
call FOP on that intermediate result) would work; but that isn't really
what I want.

Any hints?
Kind regards,
- ollie

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org


Re: using an xsl:fo in a transformer parameter

Posted by Jeremias Maerki <de...@greenmail.ch>.
That's because you pass in the snippet as a String. During the XSLT
stage the snippet will always remain text only. So when you do XSLT +
FOP in one run, the output from the XSLT stage is passed to FOP via SAX
events. And now, because your snippet is a String it gets passed to FOP
as character data instead of as SAX elements plus data. FOP subsequently
doesn't recognize your snippet as XML or XSL-FO. If you do the XSLT
first and serialize the result, the generated XSL-FO is parsed again and
therefore converted to proper SAX events.

What you need to do is to provide the snippet as a DOM fragment. That
should fix your problem. During XSLT stage the DOM fragment will be
converted to SAX events.

On 18.01.2004 13:53:02 yahooschrott wrote:
> Hi
> 
> I'm trying to pass an "already prepared" fo: snippet (i.e. a valid
> <fo:table> section) to the transformation as a parameter but it seems to
> be ignored. this is what I do:
> 
>   (...)
>   String fOTableSnipped = "<fo:table> .... </fo:table>"; // this is
> prepared elsewhere
> 
>   StreamSource renderer = new StreamSource( rendererXSL );
>   Transformer transformer=
> TransformerFactory.newInstance().newTransformer( renderer );
>   transformer.setParameter( "external_section", foTableSnippet );
>   (...)
>   _transformer.transform(new StreamSource(new CharArrayReader(sourceXML)),
> new SAXResult(_driver.getContentHandler()));
>   (...)
> 
> in the XSL I use the variable in the following way:
> <xsl:value-of select="$external_section" disable-output-escaping="yes"/>
> 
> For simple Strings and other parameters, this works fine, however when I
> want to pass an already prepared fo, it never makes it into the output
> (PDF, AWT). I would have expected this to work since I use
> disable-output-escaping, but apparently it does not.
> 
> When I run the XSL transformation only (transform an XML into a XSL:FO),
> it looks perfectly okay, the <fo:table> is where it is supposed to be. I
> haven't tried but I assume a 2-step transformation (first to XSL:FO, then
> call FOP on that intermediate result) would work; but that isn't really
> what I want.


Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org