Well thanks Craig.  That might be good news, indeed. Are you positive
the value of the param isn't defaulted when you're generating IF, not
pdf. They sure don't kick in for me, but I'm not using the "mimic"
stuff. Is that the crux of the issue?

On 12/12/2011 09:48 PM, Craig Ringer wrote:
> On 12/13/2011 12:43 PM, Rob Sargent wrote:
>> I'm using fop-1.0 compile a year or so ago.  Perhaps I just need to
>> download the trunk?  Certainly happy to do that given a glimmer of hope
>> that it will solve my problem.
>>
>> I think I've hit a catch-22 when generating IF
>> (application/X-fop-areatree) output. To generate this format I believe
>> one is forced to use "factory.newTransformer.transform(xsltSource)" as
>> opposed to the no-arg constructor.  And once one has done that one
>> cannot use transformer.setParameter(key, value).
>
> What?
>
> Why not?
>
>> This makes using<xsl:param>  in the IF-generating style-sheet neigh
>> impossible. Or I'm off my rocker (again).
>
> It's certainly possible to set XSLT params. Here's some code almost
> verbatim from what I'm working on. It makes references to a `conf'
> object which holds pre-configured XSLT transformer factories etc, but
> you're probably just going to allocate the factory directory.
>
>
>             FopFactory fopFactory = conf.getFopFactory();
>
>             // Create a user agent (a fop processor, really) to do the
> work.
>             FOUserAgent userAgent = fopFactory.newFOUserAgent();
>
>             //Create an instance of the target renderer so the
> XMLRenderer can use its font setup
>             Renderer targetRenderer =
> userAgent.getRendererFactory().createRenderer(
>                     userAgent, outMimeType);
>
>             //Create the XMLRenderer to create the area tree XML
>             XMLRenderer xmlRenderer = new XMLRenderer();
>             xmlRenderer.setUserAgent(userAgent);
>             // TODO, probably only in fop svn:
>             // use setTransformerHandler to output directly to W3C DOM
> insead of
>             // serializing to file.
>
>             //Tell the XMLRenderer to mimic the target renderer
>             xmlRenderer.mimicRenderer(targetRenderer);
>
>             //Make sure the prepared XMLRenderer is used
>             userAgent.setRendererOverride(xmlRenderer);
>             userAgent.setURIResolver(uriResolver);
>
>             // Construct fop (the MIME type here is unimportant due to
> the override
>             // on the user agent)
>             Fop fop = fopFactory.newFop(null, userAgent, atOutStream);
>
>             // Setup XSLT
>             TransformerFactory transformerFactory =
> conf.getTransformerFactory();
>             Transformer transformer =
> transformerFactory.newTransformer( xsltSource );
>             transformer.setParameter("classadSection", classadSection);
>
>             // Resulting SAX events (the generated FO) must be piped
> through to FOP
>             Result res = new SAXResult(fop.getDefaultHandler());
>
>             File f = File.createTempFile("xslfo", ".xml");
>             FileOutputStream fos = new FileOutputStream(f);
>             Result res2 = new StreamResult(fos);
>             transformer.transform( xmlInStream, res2 );
>             fos.close();
>>
>>
>>              Transformer transformer = null;
>>              TransformerFactory factory =
>> TransformerFactory.newInstance();
>>
>>              if (xsltSource == null) {
>>                  // Not generating IF
>>                  transformer = factory.newTransformer();
>>              }
>>              else {
>>                  // Generating IF, xsltSource is
>>                  transformer = factory.newTransformer(xsltSource);
>>              }
>>              if (xsltParameterMap != null) {
>>                  // The values in the map are not applied when making IF
>>                  // I suspect because the stylesheet has already been
>> read
>>                  applyXsltParameterMap(transformer); //Iterates on map:
>> transformer.setParameter(k,v)
>>              }
>>              transformer.transform(src, result);
>>              resultBytes = out.toByteArray();
>>
>> Where xsltSource is constructed via
>>
>>              xslUrl = new URL("jar:file://" + getBundlePath() +
>>                                "/lib/book-printing-core.jar!/" +
>> xsltFilename); //<== something.xsl
>>              inputstream = xslUrl.openStream();
>>              BufferedInputStream bis = new
>> BufferedInputStream(inputstream);
>>
>>              xsltSource = new StreamSource(bis);
>>
>> If I don't use the second form of the constructor (with stylesheet) I do
>> not get the IF.  Indeed it's an error condition because the transformer
>> expect fo not xsl as the source.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to