Transforming docbook to pdf - image question

Here should go questions about transforming XML with XSLT and FOP.
jwillans
Posts: 4
Joined: Fri Sep 23, 2005 11:42 am

Transforming docbook to pdf - image question

Post by jwillans »

Hi Everyone,

We're evaluating oxygen with a view to using it to manage the transformation of our docbook documentation to various forms.

We're trying to convert a large document to pdf, the following is representative of how our document is structured:

Code: Select all

<book>
<part> <-- PART1 -->
<chapter/> <-- CHAPTER P1-1 -->
</part>
<part> <-- PART2 -->
<chapter/> <!-- CHAPTER P2-1 -->
</part>
</book>
Structurally part1 and part2 are in different files. Chapter P1-1 is in the same file as part1, but chapter P2-1 is in its own file. xi:include are used to bring these all together. In terms of the file system this looks something like:

Code: Select all

Part1
+ Part1.xml
+ Images
Part2
+ Part2.xml
+ ChapterP2-1
+ ChapterP2-1.xml
+ Images
When we convert this using oxygen, the images for Chapter P1-1 are all included, however this is not the case for Chapter P2-1. Images are referenced using relative paths in all cases:

<imagedata fileref="Images/animage.jpg" />

Is there a solution to this?

Many thanks.

James
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi James,

Oxygen uses the latest Xerces 2.7.1 for XInclude processing and we got a similar report a few days ago. The problem is that Xerces does not handle properly the xml:base attribute and thus the paths for images get wrong values. We provided a workaround for this as described below.

Instead of passing the initial document through your DocBook XSL stylesheet you need to configure the transformation scenario to use first the fixXMLBase.xsl file below and then your DocBook XSL stylesheet. This is easy as oXygen transformation scenarios support multiple stylesheets. Follow the procedure below for instance to configure such a scenario.

1. Use the Configure Transformation Scenario action to open the transformation scenarios dialog
2. Choose your DocBook to PDF scenario
3. Use the duplicate button to create a copy of that
4. Copy to clipboard the current value for XSL URL
5. Use the Additional XSLT stylesheets button to show the additional XSLT stylesheets dialog
6. Choose Add and paste the URL you copied earlier
7. Choose Ok to close the additional XSLT stylesheets dialog
8. Edit the XSL URL field to point to the fixXMLBase.xsl stylesheet
9. Choose Ok to close the dialog
10. Use this scenario to transform DocBook to PDF

fixXMLBase.xsl

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<!-- default copy template, plus passing over a base parameter -->
<xsl:template match="node() | @*">
<xsl:param name="base" select="''"/>
<xsl:copy>
<xsl:apply-templates select="node() | @*">
<xsl:with-param name="base" select="$base"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<!-- handle elements containing xml:base -->
<xsl:template match="*[@xml:base]">
<xsl:param name="base" select="''"/>
<xsl:copy>
<xsl:apply-templates select="@*[not(self::xml:base)]"/>
<xsl:attribute name="xml:base">
<xsl:choose>
<xsl:when test="$base='' or not(contains(@xml:base, $base))">
<xsl:value-of select="@xml:base"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring-after(@xml:base, $base)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:apply-templates select="node()">
<xsl:with-param name="base">
<xsl:call-template name="getBase">
<xsl:with-param name="base" select="@xml:base"/>
</xsl:call-template>
</xsl:with-param>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<!-- extracts the folder from an xml:base value -->
<xsl:template name="getBase">
<xsl:param name="base" select="''"/>
<xsl:if test="contains($base, '/')">
<xsl:value-of select="substring-before($base, '/')"/>
<xsl:text>/</xsl:text>
<xsl:call-template name="getBase">
<xsl:with-param name="base" select="substring-after($base, '/')"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Best Regards,
George
jwillans
Posts: 4
Joined: Fri Sep 23, 2005 11:42 am

Post by jwillans »

Thanks for your reply George. I've followed your instructions, but I am now getting an error code 2: Root element must be root, not book. Any further thoughts?

James
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi James,

That is strange, it seems the output contains fo:bloc as root element instead of fo:root. Can you test the scenario with the sample/docbook/sampleXInclude.xml? I just tested with that and it works ok.

Best Regards,
George
jwillans
Posts: 4
Joined: Fri Sep 23, 2005 11:42 am

Post by jwillans »

Thanks again for your reply George, but it still fails on sampleXInclude.xml. For good measure I've gone through your instructions again but with no success.

James
george wrote:Hi James,

That is strange, it seems the output contains fo:bloc as root element instead of fo:root. Can you test the scenario with the sample/docbook/sampleXInclude.xml? I just tested with that and it works ok.

Best Regards,
George
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi James,

See the following demo:
http://www.oxygenxml.com/update/george/ ... lbase.html

Best Regards,
George
jwillans
Posts: 4
Joined: Fri Sep 23, 2005 11:42 am

Post by jwillans »

Hi George,

Many thanks for that, I really appreciate your effort. Unfortunately I cannot get it to work. I have watched your demo many times, I have gone through the process several times comparing each step with your demo. I have even tried reinstalling oxygen in case a preference had been inadvertently set which influences the transformation (but oxygen seems to preserve preference between installation). Is there any information that I can give you which might aid in the resolution of this issue?

Thanks again,

James
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi James,

To reset oXygen to its initial state rename the Application Data/com.oxygenxml and/or (in case you used also previous versions of oXygen) com.oxygenxml folder from your user home directory.
To debug the process you need to get the transformation step by step:
1. Transform the XML with the fixXMLBase.xsl
2. Transform the result of step 1 with the docbook.xsl stylesheet
3. Transform the result of step 2 with the FOP

If you still have problems send us the documents you obtain at each step at support at oxygenxml dot com so we can compare them with what we get.

Also, check if the DocBook PDF works for you and also make sure that you enabled the XInclude processing from Options->Preferences dialog - XML / XMP Parser Options.

Best Regards,
George
Post Reply