This is the mail archive of the
docbook-apps@lists.oasis-open.org
mailing list .
Re: Including mediaobjects
- To: docbook-apps at lists dot oasis-open dot org
- Subject: Re: DOCBOOK-APPS: Including mediaobjects
- From: Elliotte Rusty Harold <elharo at metalab dot unc dot edu>
- Date: Wed, 04 Jul 2001 16:51:00 -0400
- References: <5.1.0.14.0.20010704223605.009fabe0@pop.gmx.net>
>Hello,
>
>... trying for a while to include some graphics in my xml-docbook I'm currently running Xalan2.1, FOP-0.19.0 and the 1.40 XSL-Stylesheets by Norman Walsh against the attached file. My box is running Win98.
>
>Has anybody a hint (or) HOW-TO include any images in my PDF's?
>
>Where are they actually included? Does it FOP? Does it the XSLT-parser already?
>Where have the paths to be relative to? Which syntax will I have to use for the file's path (or URL?)?
>Is it simply a OS misbehaviour?
>
FOP has a bug involving the handling of media objects. In brief, it expects a raw URL like image.gif in the src attribute of fo:external-graphic rather than url(image.gif). If you add the following templates to your driver stylesheet it should fix the problem:
<xsl:template name="process.image">
<!-- When this template is called, the current node should be -->
<!-- a graphic, inlinegraphic, imagedata, or videodata. All -->
<!-- those elements have the same set of attributes, so we can -->
<!-- handle them all in one place. -->
<xsl:variable name="input-filename">
<xsl:choose>
<xsl:when test="@entityref">
<xsl:value-of select="unparsed-entity-uri(@entityref)"/>
</xsl:when>
<xsl:when test="@fileref">
<!-- FIXME: is this right? What if @fileref is a relative -->
<!-- URI? What if @fileref contains backslashes? -->
<xsl:text>file:</xsl:text>
<xsl:value-of select="@fileref"/>
</xsl:when>
<xsl:otherwise>
<xsl:message>
<xsl:text>Expected @entityref or @fileref on </xsl:text>
<xsl:value-of select="name(.)"/>
</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="fileext">
<xsl:call-template name="filename-extension">
<xsl:with-param name="filename" select="$input-filename"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="filename">
<xsl:choose>
<xsl:when test="$fileext != ''">
<xsl:value-of select="$input-filename"/>
</xsl:when>
<xsl:when test="$graphic.default.extension != ''">
<xsl:value-of select="$input-filename"/>
<xsl:text>.</xsl:text>
<xsl:value-of select="$graphic.default.extension"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$input-filename"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="scale">
<xsl:choose>
<xsl:when test="@scale"><xsl:value-of select="@scale"/>%</xsl:when>
<xsl:otherwise>auto</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="width">
<xsl:choose>
<xsl:when test="@width">
<xsl:call-template name="length-spec">
<xsl:with-param name="length" select="@width"/>
<xsl:with-param name="default.units" select="$default.units"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>auto</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="height">
<xsl:choose>
<xsl:when test="@depth">
<xsl:call-template name="length-spec">
<xsl:with-param name="length" select="@depth"/>
<xsl:with-param name="default.units" select="$default.units"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>auto</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- Scaling seems to require calculating an absolute width and height
from a scale factor and the intrinsic width and height (possibly
with contributions from the specified width and height). I'm not
sure how to specify that... -->
<xsl:choose>
<xsl:when test="$passivetex.extensions != 0
or $fop.extensions != 0
or $arbortext.extensions != 0">
<fo:external-graphic src="{$filename}"
content-width="{$width}"
content-height="{$height}"
width="auto"
height="auto"/>
</xsl:when>
<xsl:otherwise>
<fo:external-graphic src="{$filename}"
content-width="{$width}"
content-height="{$height}"
width="auto"
height="auto"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
--
+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo@metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
| The XML Bible, 2nd Edition (Hungry Minds, 2001) |
| http://www.ibiblio.org/xml/books/bible2/ |
| http://www.amazon.com/exec/obidos/ISBN=0764547607/cafeaulaitA/ |
+----------------------------------+---------------------------------+
| Read Cafe au Lait for Java News: http://www.cafeaulait.org/ |
| Read Cafe con Leche for XML News: http://www.ibiblio.org/xml/ |
+----------------------------------+---------------------------------+