I have written a good SQL Formatter https://manticore-projects.com/JSQLFormatter/index.html
I only will need to add xsl-fo output which is easy.
All the best
On 20 Sept 2022 06:01, Dave The Dane <xmlgraphics.d...@apconsult.de> wrote:
Would ANTLR & their Grammars for Java, SQL, etc. make sense for this?
All the best,
On 19/09/2022 10:07, Andreas Reichel wrote:
Klaus and Team,
thank you for your feedback.I have actually figured out something working nicely:
1) based on Pygments2) use the XSLFO Pygments formatter (can be installed from PIP, the code is fairly simple and straight forward)3) from your XML document containing the Code Block:a) iterate through all code blocksb) call Pygments with the XSLFO Formatter and format the block into a temporary XML file (your FO styled codeblock)c) when this succeeded, add to the Code Block node a childnode with the absolute path to this temporary XML file4) amend your XSL file and for each code-block use the XSL:COPY-OF directive to insert the FO formatted content of the temporary XML file into the final PDF directly. (Apply a XSL:CHOOSE, when child exists then XSL:COPY-OF otherwise XSL:VALUE.)5) clean up all the temporary files from step 3)
Caveats:a) you need to call Python Pygmentize from Java using ProcessBuilder/Process (and react to failures)b) Pygments understanding of the code is limited and the highlighting can be questionable especially for SQL. However, I will use my own SQL Formatter to properly format complex SQL in FO