You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by "Dionysios G. Synodinos" <ds...@noc.ntua.gr> on 2001/10/25 16:55:32 UTC

Xalan and FOP for non-English XML (iso-8859-7)

I'm trying to use xalan-j_2_2_D11 to transform an XML document, which
holds text in the Greek language (ISO-8859-7), both to HTML and PDF
(Fop-0.20.1).


When I run the code for HTML, the Greek characters are escaped to strings
beginning with ampersand, which is handled fine by the IE 6 on my PC, but
of course it's not possible to edit the HTML code afterwards by had.

When I run the code for PDF, the fo file produced doesn't display the
Greek characters correctly when opened with a simple text editor, and the
PDF produced by it is still doesn't display Greek.

What am I doing wrong?

foo.xml code
------------
<?xml version="1.0" encoding="ISO-8859-7"?>
<foo>
	<txt>
		GREEK_TEXT
	</txt>
</foo>

foo-html.xsl
------------
<?xml version="1.0" encoding="ISO-8859-7"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="ISO-8859-7"/>
   <xsl:template match="/">
   	<html><head><title>foo page</title></head><body><table>
			<xsl:apply-templates/>
   	</table></body></html>
   </xsl:template>
   <xsl:template match="txt">
   	<tr><td><h1><xsl:apply-templates/></h1></td></tr>
   </xsl:template>
</xsl:stylesheet>

foo-fo.xsl
----------
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output encoding="ISO-8859-7"/>
  <xsl:template match="/">
    <xsl:apply-templates select="foo"/>
  </xsl:template>
  <xsl:template match="foo">
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
      <fo:layout-master-set>
        <fo:simple-page-master
          page-master-name="main"
          margin-top="75pt"
          margin-bottom="75pt"
          margin-left="75pt"
          margin-right="75pt">
          <fo:region-body margin-bottom="75pt"/>
        </fo:simple-page-master>
      </fo:layout-master-set>
      <fo:page-sequence>
        <fo:sequence-specification>
          <fo:sequence-specifier-alternating
            page-master-first="main"
            page-master-odd="main"
            page-master-even="main"/>
        </fo:sequence-specification>
        <fo:flow>
          <xsl:apply-templates select="txt"/>
        </fo:flow>
      </fo:page-sequence>
    </fo:root>
  </xsl:template>
  <xsl:template match="txt">
    <fo:block 
      font-size="24pt" line-height="27pt" 
      text-align-last="start" 
      space-before.optimum="24pt">
      <xsl:apply-templates/>
    </fo:block>
  </xsl:template>
</xsl:stylesheet>

Java code for XML->HTML (foo.xml + foo-html.xsl)
------------------------------------------------
tFactory = TransformerFactory.newInstance();
transformer = tFactory.newTransformer(new StreamSource(foo-html.xsl));
transformer.transform(new StreamSource(foo.xml), new StreamResult(new
FileOutputStream(foo.html)));

Java code for XML->PDF (foo.xml + foo-pdf.xsl)
------------------------------------------------
// First produce and serialize foo.fo
tFactory = TransformerFactory.newInstance();
transformer = tFactory.newTransformer(new StreamSource(foo-pdf.xsl));
transformer.transform(new StreamSource(foo.xml), new StreamResult(new
FileOutputStream(foo.fo)));
// foo.fo serialized
(public static final int RENDER_PDF = 1;)
InputSource fopfile = new InputSource("foo.fo");
String version = org.apache.fop.apps.Version.getVersion() ;
System.setProperty("org.xml.sax.driver","org.apache.xerces.parsers.SAXParser");
XMLReader parser = null;
parser = XMLReaderFactory.createXMLReader();
Driver driver = new Driver(
	new InputSource ("$PATH/foo.fo"),
  new FileOutputStream("$PATH/foo.pdf"));
driver.setRenderer(RENDER_PDF);
driver.run();