Search code examples
pdfxsl-foright-to-left

xsl:template - How to render the page from right to left?


I have xsl:template which is currently being rendered from left to right, and I wish to render it from right to left.

<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fo="http://www.w3.org/1999/XSL/Format"
    xmlns:report="http://caretalks.somecompanyname.com/IET/2007/12"
    xmlns:Parse="com.somecompanyname.caretalks.util.StringParserUtils"
    xmlns:Ext="com.somecompanyname.caretalks.util.XsltUtils"
    exclude-result-prefixes="fo">


    <xsl:template match="report:memberEngagementReport">
        <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fox="http://xmlgraphics.apache.org/fop/extensions">
          <fo:layout-master-set>
            <fo:simple-page-master master-name="simpleA" page-height="11in"
                    page-width="8.5in" margin-top="0.5cm" margin-bottom="0.5cm"
                    margin-right="0.5cm" margin-left="0.5cm"
                    writing-mode="{$writingMode}">
                <fo:region-body margin-top="1cm" margin-bottom="2.6cm"
                        margin-right="1.5cm" margin-left="1.5cm"/>
                <fo:region-before extent="0.5cm"/>
                <fo:region-after extent="2.0cm"/>
            </fo:simple-page-master>
          </fo:layout-master-set>

    .
    .
    .
    .
    </xsl:template>
</xsl:stylesheet>

I've searched the web for possible solutions and I couldn't find what I need.

What can I do in order to render it right to left ?

I'm also looking for approach to render it for both sides (LTR / RTL) and maintain one original XSL file.


Solution

  • writing-mode is inherited, so set writing-mode="rl" on fo:root for it to apply to the entire document. See https://www.w3.org/TR/xsl11/#writing-mode.

    You seem to be using FOP, so if you want the content of different regions to have different writing modes, you can't use from-page-master-region() to get the writing mode from the page region. However, since you have a variable for the writing mode, you can set writing-mode on each fo:flow or fo:static-content.