Reputation: 884
I need to grab a couple of images and put them into pdf generated via Apache FOP. Outside of eXist, I have no problems. With eXist, the template does not work properly, there is no image in the output—maybe there is a problem with paths.
The structure of “files” is:
project/data/file.xml
project/data/img/*pictures.jpg
Testing sources:
<figure>
<graphic url="img/tealover.jpg"/>
</figure>
<figure>
<graphic url="./img/tealover.jpg"/>
</figure>
<figure>
<graphic url="/db/apps/karolinum-apps/data/img/tealover.jpg"/>
</figure>
Template:
<xsl:template match="tei:figure/tei:graphic">
<fo:block>
<fo:external-graphic src="{@url}" xsl:use-attribute-sets="images"/>
</fo:block>
<xsl:apply-templates/>
</xsl:template>
Where could be the problem? Am I missing some setting of eXist? When collecting images during ePub production, there is no problem with this.
UPDATE
XSL-FO output:
<fo:block>
<fo:external-graphic width="50%" content-height="100%" content-width="scale-to-fit" scaling="uniform" src="img/tealover.jpg"/>
</fo:block>
<fo:block>
<fo:external-graphic width="50%" content-height="100%" content-width="scale-to-fit" scaling="uniform" src="./img/tealover.jpg"/>
</fo:block>
<fo:block>
<fo:external-graphic width="50%" content-height="100%" content-width="scale-to-fit" scaling="uniform" src="/db/apps/karolinum-apps/data/img/tealover.jpg"/>
</fo:block>
Upvotes: 0
Views: 164
Reputation: 884
It seems this does the trick:
<xsl:template match="tei:figure/tei:graphic">
<fo:block>
<fo:external-graphic src="url('{resolve-uri(@url, base-uri(.))}')" xsl:use-attribute-sets="images"/>
</fo:block>
<xsl:apply-templates/>
</xsl:template>
UPDATE
Interesting! At first it worked like a charm. Later, I slightly rearranged the project’s structure (but the environment near the document is practically the same) and now it does not work. It logs:
exerr:ERROR Exception while transforming node: Base URI {} is not an absolute URI [at line 11, column 19] In function:
fop:render-pdf(node()*) [12:5:/db/apps/karolinum-apps/modules/create-pdf.xqm]
but the problem, apparently, is in this line of code.
Even if I try <xsl:value-of select="resolve-uri(@url, base-uri(.))"/>
, it complains
exerr:ERROR Exception while transforming node: Base URI {} is not an absolute URI [at line 16, column 9]
Can’t understand such tiny details at the moment.
Upvotes: 0
Reputation: 3517
The XSL-FO processor has no idea how to retrieve the images from those URL's as it has no knowledge where to resolve those paths against.
You should instead use absolute URLs that the XSL-FO processor can dereference, so for example if your image is stored in eXist at this path:
/db/apps/karolinum-apps/data/img/tealover.jpg
You should instead use the URL:
http://localhost:8080/exist/rest/db/apps/karolinum-apps/data/img/tealover.jpg
.
I am assuming that eXist is running on localhost
port 8080
, if not then just adjust the URL above to reflect your setup.
Upvotes: 1