HOWTO indent java code in PDF (with example)
Manrico_antonio Sessa <[email protected]>
| Newsgroups | gmane.text.xml.xsl.general |
|---|---|
| Organization | Centro di Calcolo - Dipartimento di Informatica di Pisa - Italy |
| Message-ID | <[email protected]> |
Hi, I'm new in XSL:FO.
I'm programming a tool that tackes a java code file and translates it in XML.
This is my input java code, CiaoMondo.java:
class CiaoMondo extends Object {
public static void main (String[] args) {
System.out.println("Hello, World!!");
}
}
and this is my result in XML, CiaoMondo.xml:
<?xml version="1.0" ?>
<source color="#FFFFFF" size="2" family="Courier New, Courier">
<br/><word color='#00FF00'>class</word> CiaoMondo <word color='#00FF00'>extends</word> Object {
<br/><ht num="1"/><word color='#00FF00'>public</word> <word color='#00FF00'>static</word> <base color='#0000FF'>void</base> main (String[] args) {
<br/><ht num="2"/>System.out.println("Hello, World!!");
<br/><ht num="1"/>}
<br/>}
</source>
where
the tag <ht num=.../> counts tabs to indent the code
and the other tags for sysntax colouring.
The templates that translate XML in HTML, are this:
<xsl:template match="source" mode="build-source">
<table border="1">
<tr><td>
<font>
<xsl:attribute name="color"><xsl:value-of select="@color" /></xsl:attribute>
<xsl:attribute name="size"><xsl:value-of select="@size" /></xsl:attribute>
<xsl:attribute name="face"><xsl:value-of select="@family" /></xsl:attribute>
<xsl:apply-templates select="*|text()" mode="build-source" />
</font>
</td></tr>
</table>
</xsl:template>
<xsl:template match="//word" mode="build-source">
<font>
<xsl:attribute name="color">
<xsl:value-of select="@color" />
</xsl:attribute>
<xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()" mode="build-source" />
</font>
</xsl:template>
<xsl:template match="//base" mode="build-source">
<font>
<xsl:attribute name="color">
<xsl:value-of select="@color" />
</xsl:attribute>
<xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()" mode="build-source" />
</font>
</xsl:template>
<xsl:template match="//specialw" mode="build-source">
<font>
<xsl:attribute name="color">
<xsl:value-of select="@color" />
</xsl:attribute>
<xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()" mode="build-source" />
</font>
</xsl:template>
<xsl:template match="//ht" mode="build-source"><xsl:call-template name="htloop" /></xsl:template>
<xsl:template name="htloop" mode="build-source">
<xsl:param name="count" select="1" />
<xsl:param name="numTabs" select="@num" />
<xsl:if test="$count <= $numTabs">
<xsl:text disable-output-escaping="yes">&#xa0;&#xa0;&#xa0;&#xa0;</xsl:text><xsl:call-template name="htloop">
<xsl:with-param name="count" select="$count+1" />
</xsl:call-template>
</xsl:if>
</xsl:template>
This work fine for me!
But, the problem is now to have the same page in PDF.
Any help would be extremly appriciated!!
Thanks,
MANRICO SESSA