Maybe it's an easy question and hope someone can help me.
Currently, I have used my PDF to begin every chapter on an odd page. by using the code
<xsl: attribute-set name = "__ force__page__count">
in my commons-attr.xsl file
The result is that there are always an even number of pages in my PDF.
But how do I get it now that if my PDF has an odd number of pages that this action is not added on the last page I thought doing like the code below will not help
<xsl:attribute-set name="__force__page__count">
<xsl:attribute name="force-page-count">
<xsl:choose>
<xsl:when test="(position() = last())">
<xsl:value-of select="'no-force'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'even'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:attribute-set>
I suspect your problems start with <xsl:when test="name(/*) = 'bookmap' != last()">
. You're testing whether the name of a node is unequal to last().
You need something like <xsl:when test="(position() != last()) and (name(/*) = 'bookmap')">
Or position() != last()
may be sufficient, I'd expect this attribute set to be called only at the start of a chapter/page-sequence, so your bookmap
test may not be necessary. I'm not familiar with the framework you're using.
Of course, whether this works, depends on the structure of the XML. If your XML has one node for each chapter, and the attribute-set is called when processing this chapter node, then it should work.
If the attribute-set is called from somewhere else, or the structure is different, the position() test wont give the expected result.
And you currently have a test that tries to match every chapter except the last one, so if the test works, your 'otherwise' will only be called for the last chapter. A better way to structure the xsl:choose
is to put the exceptions in the xsl:when statement:
<xsl:when test="position() = last()"> -match only the last chapter here-
<xsl:value-of select="'no-force'"/>
and for the xsl:otherwise
:
<xsl:value-of select="'even'"/>
In XSL-FO, the page count is controlled by the force-page-count attribute. One of the possible values is no-force
, this has the effect you want: no pages are added.
The value 'odd' forces the page-sequence to have an odd number of pages (and will add empty pages to achieve this).