Page break in PDF

Here should go questions about transforming XML with XSLT and FOP.
SimonH
Posts: 19
Joined: Thu Mar 29, 2012 4:45 pm

Page break in PDF

Post by SimonH »

I have a few topic groups in a chapter that I would like to start on new page as they belong together rather than just flowing from the previous set of topics.

I was hoping I could do it with the following in the XSLT:

<xsl:attribute-set name="topicgroup">
<xsl:attribute name="break-before">page</xsl:attribute>
</xsl:attribute-set>

However, I then noticed this had no effect and discovered the following was commented out so no processing of topicgroup takes place:

<!-- The following three template matches are based on class attributes
that do not exist. They have been commented out starting with
the DITA-OT 1.5 release, with SourceForge tracker #2882085. -->

<!--<xsl:template match="*[contains(@class, ' topic/topicgroup ')]">
<fo:block xsl:use-attribute-sets="topicgroup" id="{@id}">
<xsl:apply-templates/>
</fo:block>
</xsl:template>-->

I tried uncommenting it but with no luck.

Any idea's how to force the PDF to page-break before a <topicgroup> in the bookmap?
radu_pisoi
Posts: 403
Joined: Thu Aug 21, 2003 11:36 am
Location: Craiova
Contact:

Re: Page break in PDF

Post by radu_pisoi »

Hi,

First of all, please note that my response is based on DITA-OT 1.8.5.

Few words about PDF 2 plugin development
Whenever you develop a PDF2 plugin customization, it is useful to explore the temporary files produced by the DITA-OT PDF2 transformation. These files are usually generated in the temp/pdf folder, near the DITA map that you transform and they are deleted by default at the end of the transformation. You can choose to keep them by setting the clean.temp parameter to no.

For your case, it is important to open and explore the structure of the temp/pdf/stage1a.xml temporary file. This file represents the input of the XSLT stylesheet that generates the XSL-FO file, you can see that by analyzing the PDF transformation log.

Code: Select all

transform.topic2fo.main:
[xslt] Processing D:\workspace\eXml\samples\dita\flowers\temp\pdf\stage1a.xml to D:\workspace\eXml\samples\dita\flowers\temp\pdf\stage2.fo
[xslt] Loading stylesheet D:\workspace\eXml\frameworks\dita\DITA-OT\plugins\org.dita.pdf2\xsl\fo\topic2fo_shell_fop.xsl
[xslt] D:\workspace\eXml\frameworks\dita\DITA-OT\plugins\org.dita.pdf2\xsl\fo\front-matter.xsl:82:40: Warning! A variable with no following sibling instructions has no effect
The stage1a.xml file is obtained by merging all the topics from the DITA map after all DITA features was resolved like conditional processing, reusing, etc. It also contains information about the initial DITA map structure.

You can see the structure of this file in the next screenshot:

Image

1. As the first child of the root, you can find an opentopic:map element that reflects/keeps the structure of the input DITA map.

Code: Select all

 <opentopic:map xmlns:opentopic="http://www.idiominc.com/opentopic"
xmlns:ot-placeholder="http://suite-sol.com/namespaces/ot-placeholder">
<topicref class="- map/topicref " first_topic_id="#unique_1" href="#unique_1" id="unique_1"
ohref="topics/introduction.dita" type="topic" xtrc="topicref:1;4:45"
xtrf="D:\workspace\eXml\samples\dita\flowers\flowers.ditamap">
2. The second part of the document, after the opentopic:map element, contains all the topics from your publication together with their content (title, body). It is processed to produce the main part of the PDF document.

Now, the reason why your template has no effect is that the second part of the stage1.xml file has no entry for the topicgroup element.

The good news is that you can interrogate the opentopic:map structure to see if the current processing topic is child of a topicgroup or not.

To make the connection between the current topic and its corresponding topic from the opentopic:map structure you can use the map-id key defined in the next the frameworks/dita/DITA-OT/plugins/org.dita.pdf2/xsl/fo/commons.xsl stylesheet.

So, a solution for your use case is to add the next attribute-set in your customization:

Code: Select all

<xsl:attribute-set 
name="topic"
use-attribute-sets="base-font">
<xsl:attribute name="break-before">
<xsl:choose>
<xsl:when test="key('map-id', @id)[1]/ancestor::topicgroup">page</xsl:when>
<xsl:otherwise>auto</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:attribute-set>
Radu Pisoi
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
SimonH
Posts: 19
Joined: Thu Mar 29, 2012 4:45 pm

Re: Page break in PDF

Post by SimonH »

I've set the temp folder not to be cleaned so I'm starting to understand more by digging through the files.

I tried the suggested solution but it didn't do anything. I'm trying to debug why not.

Even I set the <xsl:otherwise> statement to page there's still no breaks when it produces the output.
SimonH
Posts: 19
Joined: Thu Mar 29, 2012 4:45 pm

Re: Page break in PDF

Post by SimonH »

Looking at the generated .fo files it appears the "topic" attributes are only applied to the chapter...
radu_pisoi
Posts: 403
Joined: Thu Aug 21, 2003 11:36 am
Location: Craiova
Contact:

Re: Page break in PDF

Post by radu_pisoi »

Hi,

I forgot to say I've tested with a regular DITA map. For a DITA bookmap the temporary file structure and XPath expressions might be little different.
Radu Pisoi
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
SimonH
Posts: 19
Joined: Thu Mar 29, 2012 4:45 pm

Re: Page break in PDF

Post by SimonH »

I've figured that the property is going to have to go in topic.topic.title for it to work in a bookmap. I'm just struggling to modify the XPath expression to work properly in that context.
Post Reply