Re: AW: AW: AW: [xep-support] XSLFO: trouble with text-align-last="justify" and linefeed-treatment="preserve"

From: G. Ken Holman <>
Date: Mon Jan 21 2008 - 11:18:45 PST

At 2008-01-21 18:45 +0100, Kirch Fritz wrote:
>May be the nature of the problem lies in the nature of the XML

No, often stylesheet writers are not in control of the XML and have
to deal with what they get. If you can change it, great, but if you
cannot change it, then the stylesheet can deal with it very straightforwardly.

>My XML is:
> <name>a very long text having CRLF characters</name>
> <phonenumber>12345</phonenumber>
> <name>short text</name>
> <phonenumber>12345</phonenumber>
>Some name nodes have text with CarriageReturn+Linefeed characters,
>other name nodes are short and don't have CRLF characters.

Not a XSL-FO issue to solve, it is an XSLT problem that can be easily resolved.

>So, for me as a XSLT/XSLFO newbie, it was the first and simplest
>solution to use a block with linefeed-treatment="preserve" and
>OK. If you consider this as not being a XSLFO problem than it is a
>XSLT problem (at least a problem for me). I understand that I have
>to split the name nodes at CRLF to build separate blocks (without
>justification) as long as there is a CRLF in the name nodes text.
>When I finally have reached a name node text without a CRLF I can
>use a block with justification.
>Do you have at least an example how to tokenize the name node texts
>at CRLF with XSLF 1.0 in order to build my blocks as intended?

An XSLT solution is below ... I hope you find this helpful. I'll
leave the XSL-FO to you to resolve.

. . . . . . . . . . . Ken

T:\ftemp>type fritz.xml
   <name>a very long text
having CRLF
   <name>short text</name>

T:\ftemp>type fritz.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl=""

<xsl:output indent="yes"/>

<xsl:template match="/">

<xsl:template match="Address">
   <xsl:variable name="phone" select="phonenumber"/>
     <xsl:for-each select="tokenize(name,'&#xa;')">
         <xsl:if test="position()=last()">
           <xsl:attribute name="text-align-last">justify</xsl:attribute>
         <xsl:value-of select="."/>
         <xsl:if test="position()=last()">
           <leader leader-pattern="dots"/>
           <xsl:value-of select="$phone"/>

T:\ftemp>xslt2 fritz.xml fritz.xsl con
<?xml version="1.0" encoding="UTF-8"?>
    <block>a very long text </block>
    <block>having CRLF </block>
    <block text-align-last="justify">characters<leader
    <block text-align-last="justify">short text<leader


World-wide corporate, govt. & user group XML, XSL and UBL training
RSS feeds:     publicly-available developer resources and training
G. Ken Holman       
Crane Softwrights Ltd.
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Cancer Awareness Nov'07
Legal business disclaimers:
(*) To unsubscribe, send a message with words 'unsubscribe xep-support'
in the body of the message to from the address
you are subscribed from.
(*) By using the Service, you expressly agree to these Terms of Service
Received on Mon Jan 21 11:55:41 2008

This archive was generated by hypermail 2.1.8 : Mon Jan 21 2008 - 11:55:42 PST