Question

I was trying to test using JavaScript scripts to add content to a template at the time of processing by a PDF render-er, specifically Apache FOP. I know that XSL can call a javascript file that can in turn call

document.write("<p>some text</p>");

which can be displayed easily in a web browser. Is it possible for your javascript function to write something to the document that is more like

document.write("<fo:block>some text</fo:block>");

Such that Apache FOP will be able to process and display that block in the output PDF?

Was it helpful?

Solution

document.write is a method of the document object exposed by browsers in text/html documents to script. XSLT does not have access to that document object and its method, not even with client-side XSLT done in the browser. The only option you have there is to have XSLT generate a HTML result document that then uses script to document.write something. And even that is restricted, for instance Mozilla browsers don't support document.write in the result document of an XSLT transformation, see https://developer.mozilla.org/en/docs/XSL_Transformations_in_Mozilla_FAQ#What_about_document.write.3F.

As for Javascript with Apache FOP, no, I don't think there is any document object available. And I am not sure why you need script to create a fo:block element, with XSLT it suffices to use literal result element e.g.

<xsl:template match="foo">
  <fo:block>some text</fo:block>
</xsl:template>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top