[xsl] fo:external-graphic and xml:base

Subject: [xsl] fo:external-graphic and xml:base
From: Jack Bates <ms419@xxxxxxxxxxxxxx>
Date: Sat, 21 Nov 2009 19:24:40 -0800
I'm writing a stylesheet that includes this template,

  <xsl:template match="html:img">
    <fo:external-graphic src="url('{@src}')"/>
  </xsl:template>

- but when I process it I get errors like,

 $ fop -xml index.html -xsl index.xsl index.pdf
 [...]
 16-Nov-2009 11:06:32 AM org.apache.fop.events.LoggingEventListener
processEvent
 SEVERE: Image not found. URI:
/docs/images/thumb/b/bb/UM-2.1.png/500px-UM-2.1.png. (No context info
available)
 [...]

- and the generated PDF is missing some images : (

I think the problem is that the stylesheet uses the document() function
to get HTML pages from the web,

  <xsl:template match="html:a" mode="foo">
    <fo:block>
      <xsl:apply-templates select="document(@href)//html:body"/>
    </fo:block>
  </xsl:template>

- and these pages, e.g. http://ica-atom.org/docs/index.php?title=UM-2.1

- have some relative images,
e.g. /docs/images/thumb/b/bb/UM-2.1.png/500px-UM-2.1.png

The <img> elements are part of the HTML document, and so relative to
http://ica-atom.org/docs/index.php?title=UM-2.1, but I guess the
<external-graphic> elements aren't?

I tried adding an xml:base="" attribute,

  <xsl:template match="html:a" mode="foo">
    <fo:block xml:base="{@href}">
      <xsl:apply-templates select="document(@href)//html:body"/>
    </fo:block>
  </xsl:template>

Here's a simplified, complete example,

http://www.sfu.ca/~jdbates/tmp/fop/200911160/index.html

http://www.sfu.ca/~jdbates/tmp/fop/200911160/index.xsl

- but now when I process this example I get this error,

 $ fop -xml index.html -xsl index.xsl index.pdf
 16-Nov-2009 11:29:57 AM org.apache.fop.cli.Main startFOP
 SEVERE: Exception
 javax.xml.transform.TransformerException:
org.apache.fop.fo.ValidationException: Invalid property encountered on
"fo:block": xml:base (No context info available)
         at
org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:314)
         at org.apache.fop.cli.InputHandler.renderTo(InputHandler.java:146)
         at org.apache.fop.cli.Main.startFOP(Main.java:174)
         at org.apache.fop.cli.Main.main(Main.java:205)
 [...]

How can I automatically convert these HTML pages to a PDF with XSL-FO?

I originally posted this question to the FOP users list,
http://thread.gmane.org/gmane.text.xml.fop.user/29778

Current Thread