Page 1 of 1

Formatting omitted from XSL-FO transformation

Posted: Mon Sep 10, 2007 7:14 pm
by Zearin
I'm attempting to learn XSL-FO by starting completely minimalist: just one simple-page-master, and just one page-sequence. The source file is Docbook 5 CR5.

So, my XSL file begins like this:

Code: Select all

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

<!--
defines templates describing high-level page layout only
-->
<fo:layout-master-set>
<fo:simple-page-master master-name="default">
<fo:region-body />
</fo:simple-page-master>
</fo:layout-master-set>



<!--
references page layouts defined in /fo:layout-master-set and
adds specifics
-->
<fo:page-sequence master-reference="default">
<fo:flow flow-name="xsl-region-body">
<xsl:apply-templates />
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
Stop me here if there any problems with just that little bit.

Then, I'm adding a few basic XSL template to provide the rest. Practically everything is inside an fo:block for now to reduce visual noise when I look at this weird FO code. :)

So, the transformation happens, but NONE of my formatting attributes are applied. The following template will output the text content, but not the formatting:

Code: Select all


<xsl:template match="book/title">
<fo:block
space-before="1in"
space-after="1in"
color="#FFAA33"
font-size="1in"
font-family="Skia, 'Myriad Web', Myriad, 'Century Gothic', Arial, sans-serif">
<xsl:apply-templates />
</fo:block>
</xsl:template>

Absolutely none of those attributes appear to have any effect on the output PDF whatsoever. The output is pretty much a bunch of fo:blocks of unstyled text stretching a couple of pages, and that's it. I mean, I expected a pretty dull output from my very spartan stylesheet, but I would have expected at least some simple formatting attributes to at least make the titles stand out from the content. This is not the case.

This irritates the hell out of me since I'm extremely comfortable with CSS, and it appeared that these are almost direct maps of CSS properties. In the middle of all this weird FO code, these formatting attributes were the one thing I found something of a familiar face in...and they aren't working!

Grr.

Does anybody know why this is?

Nope.

Posted: Mon Sep 10, 2007 9:49 pm
by Zearin
So, I changed the transformation setup so that instead of outputting a PDF, it outputs an FO file and opens it in the editor so that I can see what's going on.

It appears that no attributes are making it into the resulting FO document whatsoever. Furthermore, everything is in <fo:block> elements.

While I was expecting most of the output to be <fo:block>s, I did write a few other simple templates. I'm not sure why they are not getting called. I was under the impression that a template with match="*" has lower priority than anything more specific (which AFAIK is pretty much everything)....

What's going on?

Bump

Posted: Fri Sep 14, 2007 2:47 pm
by Zearin
Does anybody know what's happening with this faulty transformation?

Posted: Sat Sep 15, 2007 10:09 am
by george
Hi,

It is hard to guess what may happen... Please post a complete cut down example to allow us to reproduce the behavior.

You mention that the input is DocBook 5, that means the elements are all in the DocBook 5 namespace. Note that name tests in XSLT 1.0 will match no namespace elements if they are not qualified with a prefix, that means

bool/title will match book in no namespace and title in no namespace while your input document defines them in the DocBook 5 namespace. You need something like

<xsl:template xmlns:db="http://docbook.org/ns/docbook" match="db:book/db:title">
...

Best Regards,
George

Hmmm…

Posted: Tue Sep 18, 2007 9:29 pm
by Zearin
So, in my DocBook file, the DocBook schema was set as the default namespace.

Do I absolutely have to assign it to a namespace in the stylesheet? Is it not possible for me to specify that any elements without a namespace belong to X, Y, or Z ns?

Posted: Tue Sep 18, 2007 9:50 pm
by george
In XSLT/XPath 1.0 name tests without a prefix will always match elements from no namespace. In XSLT/XPath 2.0 you can specify the XPath default namespace, for instance inside a stylesheet you can use the xpath-default-namespace attribute, see
http://www.w3.org/TR/xslt20/#unprefixed-qnames

Best Regards,
George

THREE CHEERS!

Posted: Tue Sep 18, 2007 9:55 pm
by Zearin
YOU DID IT! :D :D :D

Thank you SO much. I've been stuck on this item for about two weeks! And best of all it's a ridiculously easy fix.

Thank you so much! May you find happiness in life! :D


-- Z