Custom line-break requirement

View: New views
4 Messages — Rating Filter:   Alert me  

Custom line-break requirement

by JohnVirgo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I've got an interesting problem that I've been struggling to find an answer to.

I need to produce some text in the form of an address block, which only line breaks on ',' characters not on ' ' characters.

I.e. Currently I get:
1234 Thingy drive, New York, New
York, Some county, AC 0DE

Where I want address elements to stay together:
1234 Thingy drive, New York,
New York, Some county,
AC 0DE

I've tried several techniques to no avail:
keep-together attribute doesn't seem to have a way to override the logic to do this.
Inserted a white printable char for each space, still gets treated as a place to break.
Can't reliably calculate line width of manual breaking with a variable width font by char count.

Any ideas?

Thanks, JV

Re: Custom line-break requirement

by Jeremias Maerki-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


You can replace all occurences of <space> with <nbspace> but leave all
occurences of <comma><space> as is.

<nbspace> = non-breaking space =  

HTH

On 21.02.2008 09:49:01 JohnVirgo wrote:

>
>
> I've got an interesting problem that I've been struggling to find an answer
> to.
>
> I need to produce some text in the form of an address block, which only line
> breaks on ',' characters not on ' ' characters.
>
> I.e. Currently I get:
> 1234 Thingy drive, New York, New
> York, Some county, AC 0DE
>
> Where I want address elements to stay together:
> 1234 Thingy drive, New York,
> New York, Some county,
> AC 0DE
>
> I've tried several techniques to no avail:
> keep-together attribute doesn't seem to have a way to override the logic to
> do this.
> Inserted a white printable char for each space, still gets treated as a
> place to break.
> Can't reliably calculate line width of manual breaking with a variable width
> font by char count.
>
> Any ideas?
>
> Thanks, JV
> --
> View this message in context: http://www.nabble.com/Custom-line-break-requirement-tp15606844p15606844.html
> Sent from the w3.org - www-xsl-fo mailing list archive at Nabble.com.
>




Jeremias Maerki



RE: Custom line-break requirement

by JohnVirgo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi,

I tried your suggestion, however I'm still seeing the issue. I've
attached a sample code block to show you what I'm doing (wrongly I
assume :P )

<!-- Replace all white space characters with a non-breaking space to
prevent line breaking -->
        <xsl:template name="space_2_white">
                <xsl:param name="remaining-address" select="''" />
                <xsl:param name="prev-char" select="0" />
                <xsl:choose>
                        <xsl:when test="not($remaining-address)" />
                        <!-- Exit on null string -->

                        <xsl:when test="substring($remaining-address, 1,
1) = ' '">
                                <!-- if the preceding character was a
comma, use a normal space -->
                                <xsl:value-of
select="substring($remaining-address, 1, 1)" />
                                <!-- if the preceding character was not
a comma, use a non-breaking space -->
                                <xsl:if test="$prev-char !=
','"> </xsl:if>

                                <xsl:call-template name="space_2_white">
                                        <xsl:with-param
name="remaining-address" select="substring($remaining-address, 2)" />
                                </xsl:call-template>
                        </xsl:when>

                        <xsl:otherwise>
                                <!-- Insert the next char, and recur -->
                                <xsl:value-of
select="substring($remaining-address, 1, 1)" />
                                <xsl:call-template name="space_2_white">
                                        <xsl:with-param
name="remaining-address" select="substring($remaining-address, 2)" />
                                        <xsl:with-param name="prev-char"
select="substring($remaining-address, 1, 1)" />
                                </xsl:call-template>
                        </xsl:otherwise>
                </xsl:choose>
        </xsl:template>

JV

-----Original Message-----
From: www-xsl-fo-request@... [mailto:www-xsl-fo-request@...] On
Behalf Of Jeremias Maerki
Sent: 21 February 2008 09:11
To: www-xsl-fo@...
Subject: Re: Custom line-break requirement


You can replace all occurences of <space> with <nbspace> but leave all
occurences of <comma><space> as is.

<nbspace> = non-breaking space =  

HTH

On 21.02.2008 09:49:01 JohnVirgo wrote:

>
>
> I've got an interesting problem that I've been struggling to find an
> answer to.
>
> I need to produce some text in the form of an address block, which
> only line breaks on ',' characters not on ' ' characters.
>
> I.e. Currently I get:
> 1234 Thingy drive, New York, New
> York, Some county, AC 0DE
>
> Where I want address elements to stay together:
> 1234 Thingy drive, New York,
> New York, Some county,
> AC 0DE
>
> I've tried several techniques to no avail:
> keep-together attribute doesn't seem to have a way to override the
> logic to do this.
> Inserted a white printable char for each space, still gets treated as
> a place to break.
> Can't reliably calculate line width of manual breaking with a variable

> width font by char count.
>
> Any ideas?
>
> Thanks, JV
> --
> View this message in context:
> http://www.nabble.com/Custom-line-break-requirement-tp15606844p1560684
> 4.html Sent from the w3.org - www-xsl-fo mailing list archive at
> Nabble.com.
>




Jeremias Maerki




Re: Custom line-break requirement

by Jeremias Maerki-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Small mistake in your XSLT code: for a space, the space PLUS a nbspace
was inserted. That way, the break possibility remains.


Should be:
      <xsl:when test="substring($remaining-address, 1, 1) = ' '">
        <xsl:choose>
          <xsl:when test="$prev-char != ','">
            <!-- if the preceding character was not
              a comma, use a non-breaking space -->
            <xsl:text> </xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <!-- if the preceding character was a
              comma, use a normal space -->
            <xsl:value-of select="substring($remaining-address, 1, 1)" />
          </xsl:otherwise>
        </xsl:choose>
       
       
        <xsl:call-template name="space_2_white">
          <xsl:with-param name="remaining-address" select="substring($remaining-address, 2)" />
        </xsl:call-template>
      </xsl:when>


On 21.02.2008 12:18:12 John Virgo wrote:

>
> Hi,
>
> I tried your suggestion, however I'm still seeing the issue. I've
> attached a sample code block to show you what I'm doing (wrongly I
> assume :P )
>
> <!-- Replace all white space characters with a non-breaking space to
> prevent line breaking -->
> <xsl:template name="space_2_white">
> <xsl:param name="remaining-address" select="''" />
> <xsl:param name="prev-char" select="0" />
> <xsl:choose>
> <xsl:when test="not($remaining-address)" />
> <!-- Exit on null string -->
>
> <xsl:when test="substring($remaining-address, 1,
> 1) = ' '">
> <!-- if the preceding character was a
> comma, use a normal space -->
> <xsl:value-of
> select="substring($remaining-address, 1, 1)" />
> <!-- if the preceding character was not
> a comma, use a non-breaking space -->
> <xsl:if test="$prev-char !=
> ','"> </xsl:if>
>
> <xsl:call-template name="space_2_white">
> <xsl:with-param
> name="remaining-address" select="substring($remaining-address, 2)" />
> </xsl:call-template>
> </xsl:when>
>
> <xsl:otherwise>
> <!-- Insert the next char, and recur -->
> <xsl:value-of
> select="substring($remaining-address, 1, 1)" />
> <xsl:call-template name="space_2_white">
> <xsl:with-param
> name="remaining-address" select="substring($remaining-address, 2)" />
> <xsl:with-param name="prev-char"
> select="substring($remaining-address, 1, 1)" />
> </xsl:call-template>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:template>
>
> JV
>
> -----Original Message-----
> From: www-xsl-fo-request@... [mailto:www-xsl-fo-request@...] On
> Behalf Of Jeremias Maerki
> Sent: 21 February 2008 09:11
> To: www-xsl-fo@...
> Subject: Re: Custom line-break requirement
>
>
> You can replace all occurences of <space> with <nbspace> but leave all
> occurences of <comma><space> as is.
>
> <nbspace> = non-breaking space =  
>
> HTH
>
> On 21.02.2008 09:49:01 JohnVirgo wrote:
> >
> >
> > I've got an interesting problem that I've been struggling to find an
> > answer to.
> >
> > I need to produce some text in the form of an address block, which
> > only line breaks on ',' characters not on ' ' characters.
> >
> > I.e. Currently I get:
> > 1234 Thingy drive, New York, New
> > York, Some county, AC 0DE
> >
> > Where I want address elements to stay together:
> > 1234 Thingy drive, New York,
> > New York, Some county,
> > AC 0DE
> >
> > I've tried several techniques to no avail:
> > keep-together attribute doesn't seem to have a way to override the
> > logic to do this.
> > Inserted a white printable char for each space, still gets treated as
> > a place to break.
> > Can't reliably calculate line width of manual breaking with a variable
>
> > width font by char count.
> >
> > Any ideas?
> >
> > Thanks, JV
> > --
> > View this message in context:
> > http://www.nabble.com/Custom-line-break-requirement-tp15606844p1560684
> > 4.html Sent from the w3.org - www-xsl-fo mailing list archive at
> > Nabble.com.
> >
>
>
>
>
> Jeremias Maerki
>
>
>





Jeremias Märki
_________________________________________________________
Jeremias Märki, Software-Development and Consulting
Contact Information: http://www.jeremias-maerki.ch/contact.html
Blog: http://www.jeremias-maerki.ch/blog/