"Content not allowed in prolog"--what prolog???

Here should go questions about transforming XML with XSLT and FOP.
Zearin
Posts: 107
Joined: Mon Jul 30, 2007 11:31 pm
Location: College Park, MD, United States

"Content not allowed in prolog"--what prolog???

Post by Zearin »

I keep getting this "Content not allowed in prolog" error when attempting to transform a Docbook XML file into a PDF (using FO). I don't know what prolog it's talking about, but it's becoming extremely frustrating, especially when it hasn't been this difficult to decipher errors when transforming to HTML.

My Docbook XML file is as follows:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="xsl-fo.xsl"?>
<book xmlns="http://docbook.org/ns/docbook"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xi="http://www.w3.org/2001/XInclude"
xsi:schemaLocation="http://docbook.org/ns/docbook file:/my/local/path/to/docbook.xsd">

<title><acronym>College Success Preparation</acronym> Program Booklet</title>

<xi:include href="program_background.xml" />

<xi:include href="statement_from_director.xml" />

<xi:include href="student_bios.xml" />

<xi:include href="photo_gallery.xml" />

<xi:include href="reflections_student_contributions.xml" />

<xi:include href="staff_bios.xml" />

</book>
I admit I'm new to toying around with Docbook, but I've checked for well-formedness and validity without errors. I'm using the XML Schema for Docbook CR5.

My XSL stylesheet is as follows:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
version="2.0">


<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

<fo:layout-master-set>
<fo:simple-page-master master-name="default" page-width="8.5in" page-height="11in">
<fo:region-body />
<fo:region-before />
<fo:region-after />
</fo:simple-page-master>

<fo:simple-page-master master-name="biographies">
<fo:region-body />
<fo:region-before />
<fo:region-after />
</fo:simple-page-master>
</fo:layout-master-set>

<fo:page-sequence master-reference="default">
<fo:flow flow-name="xsl-region-body" />
<fo:flow flow-name="xsl-region-before">
<fo:block font-size="1in">
<xsl:value-of select="title" />
</fo:block>
</fo:flow>
<fo:flow flow-name="xsl-region-after" />
</fo:page-sequence>
</fo:root>
</xsl:template>


<xsl:template match="simplelist">
<fo:block>
<xsl:apply-templates />
</fo:block>
</xsl:template>

<xsl:template match="member/person">
<fo:block background-color="#666666">
<xsl:apply-templates />
</fo:block>
</xsl:template>

<xsl:template match="member/person/personname">
<fo:block
font-family="'Bauhaus 93', 'Myriad Web', Myraid, 'Century Gothic', Arial, sans-serf"
font-weight="bold"
text-align="right">
<xsl:value-of select="firstname" />
<xsl:text> </xsl:text>
<xsl:value-of select="surname" />
</fo:block>
</xsl:template>

<xsl:template match="member/person/address">
<fo:block>
<fo:inline separator=", ">
<xsl:value-of select="city" />
<xsl:value-of select="state" />
</fo:inline>
<xsl:value-of select="country" />
</fo:block>
</xsl:template>

<xsl:template match="member/person/affiliation" />

<xsl:template match="member/person/personblurb" />

</xsl:stylesheet>
Obviously it's pretty sparse right now, but I was trying to get just this small bit done before I moved onto anything more complex. But, so far, I've had no luck, not even with this small bit.

I've tried with all XSL processors I can think of but I lean towards Saxon8 because I'm blindly leading towards the idea of XSLT 2.0 == better than 1.0. As a side thing it would be nice to know if (and why) this is untrue if I'm incorrect in this notion.

But most importantly, I would love to get the XSL-FO transform working.
-- Zearin
jkmyoung
Posts: 89
Joined: Mon Mar 06, 2006 10:13 pm

Post by jkmyoung »

This is a pretty common problem.
Some text editors or applications add a "Byte Order Mark" at the beginning of the xml file. eg: Windows Notepad.
One possible solution is to use a different encoding such as UTF-16 or iso-8859-1
Zearin
Posts: 107
Joined: Mon Jul 30, 2007 11:31 pm
Location: College Park, MD, United States

Hmmm....

Post by Zearin »

Thanks for the quick reply!

Is the BOM problem with the XML file or the XSL?

Also, doesn't oXygen have a built-in way of dealing with this? It does a fantastic job of taking the gruntwork out of a lot of other things, but there doesn't seem to be an easy way change encoding (or BOMs) on already-existing files…
-- Zearin
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Hmmm....

Post by sorin_ristache »

Zearin wrote:Is the BOM problem with the XML file or the XSL?
I think the problem is with the parser that FOP uses to parse the XSL-FO file and which is not the oXygen built-in parser. The built-in parser should recognize the BOM marker correctly.
Zearin wrote:there doesn't seem to be an easy way change encoding (or BOMs) on already-existing files
The option BOM handling available in Options -> Preferences -> Global controls BOM writing when oXygen saves a file on disk. What is the value of this option on your computer? Try the Don't Write value. If you still get the error Content not allowed in prolog send us XML and XSL files in a zip archive for reproducing it.


Regards,
Sorin
Zearin
Posts: 107
Joined: Mon Jul 30, 2007 11:31 pm
Location: College Park, MD, United States

BOM is useful exaclty…where?

Post by Zearin »

Hey,

I opened all files in TextWrangler (a Mac-based fantastic text editor, completely free, and the "lite" version of the well-known BBEdit). TextWrangler has an extremely handy everpresent encoding option at the bottom of the window. It always lists the current encoding, and you can click on it to change the edited file to another encoding via a dropdown-menu interface.

It also has options for UTF-8 and UTF-16, and provides both a BOM and no-BOM option for each.

So after opening all files in TextWrangler, they were apparently all UTF-8 no-BOM--exactly what I wanted. This puzzled me, but after I tried the transformation again in Oxygen, it worked. (Well technically it didn't, but that was because of my novice XSL code, not because of the BOM "Content not allowed in prolog" error.)

I don't know what was wrong before, but it appears to be okay now for FO transformations. Now I just have to figure out FO's way bizarre structure. :)

Anywho, I was wondering--are there any practical applications of the BOM? It seems every single time I read about the BOM, it's about how it screws something up. Seems like it causes more harm than good, even as an "option" that can be turned off, since all accounts I've read about BOMs talk about how they somehow snuck into a document against the author's wishes.
-- Zearin
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: BOM is useful exaclty…where?

Post by sorin_ristache »

Zearin wrote:I was wondering--are there any practical applications of the BOM?
The BOM was introduced initially for defining the byte order and encoding of plain text files but it was adopted also for XML documents where it seems to create a lot of problems with the default settings of document editing tools.


Regards,
Sorin
Zearin
Posts: 107
Joined: Mon Jul 30, 2007 11:31 pm
Location: College Park, MD, United States

So, kill it in XML?

Post by Zearin »

Thanks to everyone for their excellent help. This forum is invaluable!

Answers gratefully noted; but they lead me to new questions:
  1. does this mean it is safe to kill all BOMs in all XML documents?
  2. Also, in Oxygen→Preferences→Global , there is a BOM handling preference, with options as follows: "keep", "write", and "don't write". This is slightly confusing, because "keep" seems to be an instruction for handling existing documents, whereas the others imply what Oxygen should do when creating a new document. Could you clarify?
-- Zearin
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: So, kill it in XML?

Post by sorin_ristache »

Zearin wrote:
  1. does this mean it is safe to kill all BOMs in all XML documents?
It depends on the other applications which use the documents edited in oXygen. If they ignore the BOM then you can remove the BOM from all the documents.
Zearin wrote:
  1. Also, in Oxygen→Preferences→Global , there is a BOM handling preference, with options as follows: "keep", "write", and "don't write".
The value "keep" does not modify the BOM of the document: if the document does not have a BOM before it is opened in oXygen then oXygen does not add a BOM when saving the document, if the document has a BOM then oXygen preserves it when saving the document.

The value "write" means that a BOM is written when the document is saved and it does not matter if the document had a BOM before it was opened in oXygen. Also it does not matter if it is a new file or an existing one.

The value "don't write" works like "write" with the difference that the BOM is not written when the document is saved.


Regards,
Sorin
Post Reply