Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating a pdf via XSLT inside a web application hosted on a j2ee container
    primarykey
    data
    text
    <p>This is the setup:</p> <p>A web application, hosted on jboss - could be any other container. From the web app, using a browser, users query the backend for various reports. The reports are displayed on the screen. The vendor has provided options to save the report results into csv, xml and html. This is done by use of xsl transformations.</p> <p>When the user clicks on, say, Save to csv, a js script is called that sends the report data on the screen to the xsl and once the transformation is done, the user is prompted to save the generated file (or open it in the whatever app is associated with the file type)</p> <p>Note that all the above is done on the fly. Some of the code behind are closed but the xsls are available for modification.</p> <p>Now, I am required to extend the web app to generate a pdf based on a custom template using the query data being passed via js.</p> <p>I was thinking I can use the html transformation as a basis for converting to pdf. The xsl for html transformation looks like this:</p> <pre><code>&lt;?xml version="1.0"?&gt; </code></pre> <p></p> <pre><code>&lt;xsl:template match="/"&gt; &lt;html&gt; &lt;body topmargin="2" leftmargin="2"&gt; &lt;title&gt; &lt;xsl:value-of select="/responseDetails/window/panes/pane/dataSection/enqResponse/title" /&gt; &lt;/title&gt; &lt;TABLE cellSpacing="0" cellPadding="0"&gt; &lt;table&gt; &lt;xsl:choose&gt; &lt;!-- Process each report page data --&gt; &lt;xsl:when test="/responseDetails/window/panes/pane/dataSection/enqResponse/pageData !=''"&gt; &lt;xsl:for-each select="/responseDetails/window/panes/pane/dataSection/enqResponse/pageData"&gt; &lt;xsl:call-template name="Header"/&gt; &lt;xsl:call-template name="ColumnHeaders"/&gt; &lt;xsl:call-template name="Datam"/&gt; &lt;xsl:call-template name="Footer"/&gt; &lt;/xsl:for-each&gt; &lt;/xsl:when&gt; &lt;!-- Process report data --&gt; &lt;xsl:otherwise&gt; &lt;xsl:call-template name="Header"/&gt; &lt;xsl:call-template name="ColumnHeaders"/&gt; &lt;xsl:call-template name="Datam"/&gt; &lt;xsl:call-template name="Footer"/&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/table&gt; &lt;/TABLE&gt; &lt;/body&gt; &lt;/html&gt; &lt;/xsl:template&gt; &lt;!-- Template for Header which decides to extract header data page by page or whole --&gt; &lt;xsl:template name="Header"&gt; &lt;xsl:choose&gt; &lt;xsl:when test="/responseDetails/window/panes/pane/dataSection/enqResponse/pageData!=''"&gt; &lt;tr&gt; &lt;xsl:for-each select="./header/r"&gt; &lt;xsl:call-template name="Headers"/&gt; &lt;/xsl:for-each&gt; &lt;/tr&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;tr&gt; &lt;xsl:for-each select="/responseDetails/window/panes/pane/dataSection/enqResponse/header/r"&gt; &lt;xsl:call-template name="Headers"/&gt; &lt;/xsl:for-each&gt; &lt;/tr&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:template&gt; &lt;!-- Template for datam which decides to extract data page by page or whole --&gt; &lt;xsl:template name="Datam"&gt; &lt;xsl:choose&gt; &lt;xsl:when test="/responseDetails/window/panes/pane/dataSection/enqResponse/pageData!=''"&gt; &lt;xsl:for-each select="./r"&gt; &lt;xsl:call-template name="Data"/&gt; &lt;/xsl:for-each&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;xsl:for-each select="/responseDetails/window/panes/pane/dataSection/enqResponse/r"&gt; &lt;xsl:call-template name="Data"/&gt; &lt;/xsl:for-each&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:template&gt; &lt;!-- Template for footer which decides to extract footer data page by page or whole --&gt; &lt;xsl:template name="Footer"&gt; &lt;xsl:choose&gt; &lt;xsl:when test="/responseDetails/window/panes/pane/dataSection/enqResponse/pageData!=''"&gt; &lt;xsl:for-each select="./footer"&gt; &lt;xsl:call-template name="Footers"/&gt; &lt;/xsl:for-each&gt; &lt;xsl:text&gt; &lt;/xsl:text&gt; &lt;xsl:text&gt;&amp;#xa;&lt;/xsl:text&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:template&gt; &lt;!-- Template for headers --&gt; &lt;xsl:template name="Headers"&gt; &lt;tr&gt; &lt;xsl:for-each select="c"&gt; &lt;xsl:choose&gt; &lt;xsl:when test="cap != '' "&gt; &lt;td&gt; &lt;b&gt; &lt;font color="#FF8400"&gt; &lt;xsl:value-of select="cap"/&gt; &lt;/font&gt; &lt;/b&gt; &lt;/td&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;xsl:choose&gt; &lt;xsl:when test="class!=''"&gt; &lt;td&gt; &lt;b&gt; &lt;font color="#FF8400"&gt; &lt;xsl:value-of select="cap" /&gt; &lt;/font&gt; &lt;/b&gt; &lt;/td&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;td&gt; &lt;b&gt; &lt;font color="#FF8400"&gt; &lt;xsl:value-of select="." /&gt; &lt;/font&gt; &lt;/b&gt; &lt;/td&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:for-each&gt; &lt;/tr&gt; &lt;/xsl:template&gt; &lt;!-- Template for column headers --&gt; &lt;xsl:template name="ColumnHeaders"&gt; &lt;tr&gt; &lt;xsl:for-each select="/responseDetails/window/panes/pane/dataSection/enqResponse/cols"&gt; &lt;xsl:for-each select="c"&gt; &lt;td&gt; &lt;b&gt; &lt;font color="#FF8400"&gt; &lt;xsl:value-of select="." /&gt; &lt;/font&gt; &lt;/b&gt; &lt;/td&gt; &lt;/xsl:for-each&gt; &lt;/xsl:for-each&gt; &lt;/tr&gt; &lt;/xsl:template&gt; &lt;!-- Template for data --&gt; &lt;xsl:template name="Data"&gt; &lt;xsl:choose&gt; &lt;xsl:when test="position() mod 2 = 0"&gt; &lt;td&gt; &lt;tr&gt; &lt;xsl:for-each select="c"&gt; &lt;td bgColor="white"&gt; &lt;xsl:value-of select="cap" /&gt; &lt;/td&gt; &lt;/xsl:for-each&gt; &lt;/tr&gt; &lt;/td&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;td&gt; &lt;tr&gt; &lt;xsl:for-each select="c"&gt; &lt;td bgColor="#eeeeee"&gt; &lt;xsl:value-of select="cap" /&gt; &lt;/td&gt; &lt;/xsl:for-each&gt; &lt;/tr&gt; &lt;/td&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:template&gt; &lt;!-- Template for footers --&gt; &lt;xsl:template name="Footers"&gt; &lt;tr&gt; &lt;xsl:for-each select="r"&gt; &lt;tr&gt; &lt;xsl:for-each select="c"&gt; &lt;xsl:choose&gt; &lt;xsl:when test="cap != '' "&gt; &lt;td&gt; &lt;b&gt; &lt;font color="#FF8400"&gt; &lt;xsl:value-of select="cap"/&gt; &lt;/font&gt; &lt;/b&gt; &lt;/td&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;td&gt; &lt;b&gt; &lt;font color="#FF8400"&gt; &lt;xsl:value-of select="." /&gt; &lt;/font&gt; &lt;/b&gt; &lt;/td&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:for-each&gt; &lt;/tr&gt; &lt;/xsl:for-each&gt; &lt;/tr&gt; &lt;/xsl:template&gt; </code></pre> <p></p> <p>No physical files are involved in this.</p> <p>My question is, how can I extend the xsl above to print the resulting html into pdf? At this point, I have to admit I dont even know how to access the resulting data from code since I am a total newbie in xslt AND I dont know how to debug xsl at runtime.</p> <p>If this is possible, then I figure I could pass the resulting data to <a href="https://stackoverflow.com/questions/5051747/converting-xml-html-table-to-pdf-via-xsl-fo">iText</a> or <a href="http://xmlgraphics.apache.org/fop/" rel="nofollow noreferrer">Apache FOP processor</a> </p> <p>Either way, there should be NO physical files created on the server side. The output should be sent to user for opening or saving.</p> <p>I have come across many other tools and converters like <a href="https://code.google.com/p/xdocreport/" rel="nofollow noreferrer">XDocReport</a>, JODConverter, docx4j, etc.</p> <p>If only I can figure out how to put it all together within the existing framework! </p> <p>There is still the issue of using the custom templates (Probably created using word) but that will be phase 2. I just want to print to pdf first</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload