[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] FO: Alphabetical index layout problem with justified last line


Subject: Re: [xsl] FO: Alphabetical index layout problem with justified last line
From: "Michael Friedman sumarimike@xxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 3 Jun 2015 15:20:36 -0000

Hi Michael,
For this kind of styling, I've worked with several options before and there's
not a "best case" for all. You are correct, I believe, that there's often a
balance needed to get the right kind of display and that's really a design
choice. You may need to keep the keyword line and reference line totally
separate if the body of your keywords are generally lengthy, for example. If
the formatting doesn't need to be pretty, then use a table or list to enforce
strict wrapping and leader lengths.
I am going to assume you are generating your index using keys so that you have
access to the position() each number entry is in. If you are not using keys,
at least look at the fo:block and fo:inline combination to keep things on the
same line. Speaking abstractly, something like this might work:
The context is an indexterm match.
<fo:block font-weight="normal"><xsl:value-of select="."/> <!-- your index term
--><fo:inline><xsl:for-each select="$refs"> <!-- your key, with all the terms,
used in your case to refer to the page number --><xsl:if
test="position()=1"><fo:leader leader-pattern="dots"
leader-pattern-width="3pt"/></xsl:if><!-- A template to determine the location
of the reference, format it if necessary, and create the fo:basic-link
--><xsl:call-template name="index_number"><xsl:with-param name="term"
select="'primary'"/></xsl:call-template><xsl:if test="position() !=
last()"><xsl:text>,
</xsl:text></xsl:if></xsl:for-each></fo:inline></fo:block>
You create an fo:block for each keyword, and then use an fo:inline leader for
the first number reference. All other number references get the separating ","
except for the last. This design, for the work I do, balances term / keyword
length with a small or large number of citations and generally short
keywords.
In this , you end up with:| keyword of short length .......... 42 |or| keyword
of embarrassingly large || length and numbers ....... 42, 44  |or| keyword
........ 42, 44, 46, 48, 99 |
You will have trouble when the two balance awkwardly, or you have a very long
set of numbers to process:| keyword medium .... 42, 44, 46, |
|                                              48, 99  |
You could then use xpath to do some more number evaluations on the position().
For example, you could count the terms in your number references (10, for
example), and check the position() when emitting and try to break them across
lines to balance them out. You can also set minimum and maximum lengths on the
leader. The block lets you control things like hanging-indents and margins to
better format your output.
Hopefully this helps, some, at least abstractly.
Kind regards,Michael Friedman
> From: xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx
> Date: Wed, 3 Jun 2015 14:32:51 +0000
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] FO: Alphabetical index layout problem with justified last
line
>
> Hello experts,
>
> We are challenged with a layout for an alphabetical index that uses leader
dots and forces page numbers to the right border of the current column, like
this:
>
> | keyword .......... 23 |


Current Thread
Keywords