Dotted underline in XSL-FO

Viewed 86

I would like to have dotted underline words using XSL-FO.

I am able to underline the words using a template but not make the line dotted.

Here is the template that I am using:

<xsl:template match="db:link">
    <fo:inline font-family="AvenirNextLTPro-It" text-decoration="underline">
        <fo:basic-link internal-destination="{@idref}"> 
            <xsl:apply-templates/>
        </fo:basic-link>
    </fo:inline>            
</xsl:template>

And this is how I apply it on my words:

<link idref="policy">Policy</link>

Is there a parameter to make dotted underlines in XSL-FO?

3 Answers

The values supported for text-decoration do not include anything for dotted lines:

none | 
  [ [ underline | no-underline] || 
    [ overline | no-overline ] ||
    [ line-through | no-line-through ] || 
    [ blink | no-blink ] ] |
inherit

You may be able to get close to the desired affect via border-bottom-style:

<fo:inline font-family="AvenirNextLTPro-It" border-bottom-style="dotted">

Side note: Be sure to account for namespaces properly – your template is matching db:link yet the example you show is link. Depending on the default namespaces in play and the definition of the db namespace prefix, you may have a matching issue to address too.

Like this:

    <fo:block>
       <fo:inline>I do not have anything. </fo:inline>
       <fo:inline border-bottom="0.5pt dotted black">Oh look! dotted underline! </fo:inline>
        <fo:inline>No extensions required.</fo:inline>
        <fo:inline border-bottom="0.5pt dotted black">And should work with any formatter! </fo:inline>
    </fo:block>

Resulting in:

enter image description here

Tested with FOP, RenderX and AHF without any extensions.

Solid and dotted underlines, with and without background color, using 'axf:text-line-style' and 'border-bottom'

With axf:text-line-style, the styled underline is in the same position as the normal solid underline, rather than being shifted to after the after-edge of the fo:inline (although you can change the position of the underline with axf:text-underline-position if you want). axf:text-line-style styles an underline (or strikethrough line or overline) using any of the extended border styles that AH Formatter supports.

<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
     xmlns:axf="http://www.antennahouse.com/names/XSL/Extensions"
     xml:lang="en">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="spm" size="A5">
      <fo:region-body margin="10mm" />
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="spm">
    <fo:flow flow-name="xsl-region-body">
      <fo:table>
    <fo:table-column column-width="50%" />
    <fo:table-column column-width="50%" />
    <fo:table-header>
      <fo:table-row>
        <fo:table-cell padding="0.5em">
          <fo:block font-weight="bold" font-family="monospace">axf:text-line-style</fo:block>
        </fo:table-cell>
        <fo:table-cell padding="0.5em">
          <fo:block font-weight="bold" font-family="monospace">border-bottom</fo:block>
        </fo:table-cell>
      </fo:table-row>
    </fo:table-header>
    <fo:table-body>
      <fo:table-row>
        <fo:table-cell padding="0.5em">
          <fo:block>
        <fo:inline text-decoration="underline">Solid underline</fo:inline>
          </fo:block>
        </fo:table-cell>
        <fo:table-cell padding="0.5em">
          <fo:block>
            <fo:inline border-bottom="0.5pt solid black">Solid underline</fo:inline>
          </fo:block>
        </fo:table-cell>
      </fo:table-row>
      <fo:table-row>
        <fo:table-cell padding="0.5em">
          <fo:block>
        <fo:inline axf:text-line-style="dotted" text-decoration="underline">Dotted underline</fo:inline>
          </fo:block>
        </fo:table-cell>
        <fo:table-cell padding="0.5em">
          <fo:block>
            <fo:inline border-bottom="0.5pt dotted black">Dotted underline</fo:inline>
          </fo:block>
        </fo:table-cell>
      </fo:table-row>
      <fo:table-row>
        <fo:table-cell padding="0.5em">
          <fo:block>
        <fo:inline axf:text-line-style="dotted" text-decoration="underline" background-color="yellow">Dotted underline</fo:inline>
          </fo:block>
        </fo:table-cell>
        <fo:table-cell padding="0.5em">
          <fo:block>
            <fo:inline border-bottom="0.5pt dotted black" background-color="yellow">Dotted underline</fo:inline>
          </fo:block>
        </fo:table-cell>
      </fo:table-row>
    </fo:table-body>
      </fo:table>
    </fo:flow>
  </fo:page-sequence>
</fo:root>
Related