wood burning stoves 2.0*
The moose likes Other JSE/JEE APIs and the fly likes FOP, Error in FO header Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "FOP, Error in FO header" Watch "FOP, Error in FO header" New topic
Author

FOP, Error in FO header

Jonas Ladenfors
Greenhorn

Joined: Jun 28, 2004
Posts: 7
I am trying to generate a FO file from a XSL and a XML file. After fiddling around I have finally gotten some output but the FO header is messed up.

I would like the header to look like this
<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

But now it looks like this
<?xml version = '1.0'?>
<fo:root>

I use this to generate the FO file

xmlF = new File(xmlFile);
DOMParser parser = new DOMParser();
parser.parse(xmlFile);
org.w3c.dom.Document domDoc = parser.getDocument();
doc = new DOMBuilder().build(domDoc);

File xslF = new File(xslFile);
ByteArrayOutputStream outStream = new ByteArrayOutputStream();

TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new StreamSource(xslF));
transformer.transform(new StreamSource(xmlF), new StreamResult(outStream));

The outstream is now "pretty" ok but lacks the header I showed earlier.
Does anyone have any clue on why my FO header lacks the xmlns tag?

Take care
/Jonas

[ March 09, 2005: Message edited by: Jonas Ladenfors ]
[ March 09, 2005: Message edited by: Jonas Ladenfors ]
Horatio Westock
Ranch Hand

Joined: Feb 23, 2005
Posts: 221
Have you tried a test transformation using a standalone processor, just to check that everything is OK with your xsl file?

I suspect this is two problems. Firstly, specifying the encoding in your xsl utput tag, and secondly something to do with the way you have declared the namespaces in your stylesheet.

I can't tell you more without knowing more about your project, so if you post a distilled down version of your xsl (just the stylesheet element and any configuration-type children), that would really help.

The other thing I noticed, is that all that DOM stuff you have declared seems to be redundant?!
Jonas Ladenfors
Greenhorn

Joined: Jun 28, 2004
Posts: 7
I am no XSL guru so I have used a stylesheet from from the apache FOP documentation package. Does this look correct to you?


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="fo">
<xsl utput method="xml" version="1.0" omit-xml-declaration="no" indent="yes"/>
<!-- ========================= -->
<!-- root element: projectteam -->
<!-- ========================= -->
<xsl:template match="projectteam">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
Horatio Westock
Ranch Hand

Joined: Feb 23, 2005
Posts: 221
Hmmm, everything looks ok. I checked one of mine, and it is basically the same.

I'm not sure if you need the 'exclude-result-prefixes' attribute, especially since your fo is going to be an intermediate document. You could try removing that.
Jonas Ladenfors
Greenhorn

Joined: Jun 28, 2004
Posts: 7
Great it that did it , I changed the XSL file to

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl utput method="xml" version="1.0" omit-xml-declaration="no" indent="yes"/>
<!-- ========================= -->
<!-- root element: projectteam -->
<!-- ========================= -->
<xsl:template match="projectteam">

I tried to figure out what the "exclude-result-prefixes" option did and found this description, didnt tell me anything

A namespace URI is designated as an excluded namespace by using an exclude-result-prefixes attribute on an xsl:stylesheet element or an xsl:exclude-result-prefixes attribute on a literal result element.

Anyway thanks for helping me out
/Jonas

[ March 10, 2005: Message edited by: Jonas Ladenfors ]
[ March 10, 2005: Message edited by: Jonas Ladenfors ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: FOP, Error in FO header
 
Similar Threads
Whitespace Exception
Question Mark's appearing in MS word document Generated using XML, XSL FO and jFor
XML Parsing
Problem with XML to CSV transformation using JDOM api
display a tag information from xslt file.