XSL-FO - how to dynamically set the page direction?

165 Views Asked by At

I have XSL file which needs to be rendered dynamically by a given Locale.

By this locale we would present the PDF right to left or either left to right.

Currently I have an original XSL file which needs to be used for both sides.

I already added writing-mode="rl" in order to have a POC for that issue, and it's working fine.

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fox="http://xmlgraphics.apache.org/fop/extensions" writing-mode="rl">

I want to know what is the desired API that I need to use from my Java code in order to put this attribute by the given Locale without creating a copy of my XSL

I tried to find over web for an answer and I couldn't find what I need.

1

There are 1 best solutions below

0
On

Your Java code could presumably include a lookup based on the locale to determine the writing mode. The "How to find out locale-dependent text orientation in java?" question has an example from someone who had to roll their own.

Alternatively, you could do the lookup in your XSLT. To get you started, here's an XSLT 2.0 function using three-letter language tags that I wrote a while ago when formatting the translations of the Universal Declaration of Human Rights (UDHR):

<xsl:function name="m:writing-mode" as="xs:string">
  <xsl:param name="lang" />

  <xsl:sequence
      select="if ($lang = ('heb', 'arb', 'pnb', 'skr',
               'ydd', 'pes', 'urd', 'pbu',
               'mly_arab', 'uig_arab',
               'aii', 'div'))
        then 'rl'
        else 'lr'" />
</xsl:function>