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

From: G. Ken Holman <gkholman@CraneSoftwrights.com>
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:
>
><AddressList>
><Address>
> <name>a very long text having CRLF characters</name>
> <phonenumber>12345</phonenumber>
></Address>
><Address>
> <name>short text</name>
> <phonenumber>12345</phonenumber>
></Address>
></AddressList>
>
>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
>text-align-last=justify".
>
>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
<AddressList>
<Address>
   <name>a very long text
having CRLF
characters</name>
   <phonenumber>12345</phonenumber>
</Address>
<Address>
   <name>short text</name>
   <phonenumber>12345</phonenumber>
</Address>
</AddressList>

T:\ftemp>type fritz.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 version="2.0">

<xsl:output indent="yes"/>

<xsl:template match="/">
   <xsl:apply-templates/>
</xsl:template>

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

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

T:\ftemp>

--
World-wide corporate, govt. & user group XML, XSL and UBL training
RSS feeds:     publicly-available developer resources and training
G. Ken Holman                 mailto:gkholman@CraneSoftwrights.com
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/f/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/f/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal
-------------------
(*) To unsubscribe, send a message with words 'unsubscribe xep-support'
in the body of the message to majordomo@renderx.com from the address
you are subscribed from.
(*) By using the Service, you expressly agree to these Terms of Service http://www.renderx.com/terms-of-service.html
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