• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FOP, Error in FO header

 
Jonas Ladenfors
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic