Loading ...
Sorry, an error occurred while loading the content.

Re: [XSL-FO] Re: forcing line breaks

Expand Messages
  • dvd@renderx.com
    ... Zero-width space IS a native FO solution. Zero-width space is a Unicode character. An FO formatter is expected to be able to break lines on zero-width
    Message 1 of 19 , Dec 5, 2001
    • 0 Attachment
      >
      >
      > Thank you for the good tip, David. It's too late in our dev cycle to
      > consider using a different renderer, and I'm getting the impression
      > that there's no native FO solution.
      >
      > Anybody have other ideas? Or am I just up the creek w/o a paddle?

      Zero-width space IS a native FO solution. Zero-width space is a Unicode
      character. An FO formatter is expected to be able to break lines on
      zero-width spaces.

      It is a deficiency of a formatter not to handle zero-width spaces
      properly.

      David Tolpin
      RenderX
    • barrett808
      Well, that just shows you how little I know about XSL...Is there some convenient way to transform a text element to one with zero-width spaces interspersed?
      Message 2 of 19 , Dec 5, 2001
      • 0 Attachment
        Well, that just shows you how little I know about XSL...Is there some
        convenient way to transform a text element to one with zero-width
        spaces interspersed? Seems that would be a nifty transformation to
        have in our toolkit.


        --- In XSL-FO@y..., dvd@r... wrote:
        > >
        > >
        > > Thank you for the good tip, David. It's too late in our dev cycle
        to
        > > consider using a different renderer, and I'm getting the
        impression
        > > that there's no native FO solution.
        > >
        > > Anybody have other ideas? Or am I just up the creek w/o a paddle?
        >
        > Zero-width space IS a native FO solution. Zero-width space is a
        Unicode
        > character. An FO formatter is expected to be able to break lines on
        > zero-width spaces.
        >
        > It is a deficiency of a formatter not to handle zero-width spaces
        > properly.
        >
        > David Tolpin
        > RenderX
      • Nikolai Grigoriev
        Hi, ...
        Message 3 of 19 , Dec 6, 2001
        • 0 Attachment
          Hi,

          > Well, that just shows you how little I know about XSL...Is there some
          > convenient way to transform a text element to one with zero-width
          > spaces interspersed? Seems that would be a nifty transformation to
          > have in our toolkit.

          <xsl:template match="text()" mode="insert-zero-spaces">
          <xsl:call-template name="intersperse-with-zero-spaces">
          <xsl:with-param name="str" select="."/>
          </xsl:call-template>
          </xsl:template>

          <xsl:template name="intersperse-with-zero-spaces">
          <xsl:param name="str"/>
          <xsl:variable name="spacechars">

                
               ​
          </xsl:variable>

          <xsl:if test="string-length($str) > 1">
          <xsl:variable name="c1" select="substring($str, 1, 1)/>
          <xsl:variable name="c2" select="substring($str, 2, 1)/>

          <xsl:value-of select="$c1"/>
          <!-- Insert a zero-width space between any two non-space characters -->
          <xsl:if test="not(contains($spacechars, $c1) or contains($spacechars,
          $c2))">
          <xsl:text>​</xsl:text>
          </xsl:if>

          <xsl:call-template name="intersperse-with-zero-spaces">
          <xsl:with-param name="str" select="substring($str, 2)"/>
          </xsl:call-template>
          </xsl:if>
          </xsl:call-template>

          Regards,

          Nikolai Grigoriev
          RenderX
        • barrett808
          Thank you, Nikolai. This looks promising, but I m having problems making it work. Here s the code (slightly adapted) I m using, and it basically just spits out
          Message 4 of 19 , Dec 6, 2001
          • 0 Attachment
            Thank you, Nikolai. This looks promising, but I'm having problems
            making it work. Here's the code (slightly adapted) I'm using, and it
            basically just spits out the text content of the elements with a
            bunch of white space between them.

            <?xml version="1.0" encoding="UTF-16"?>
            <xsl:stylesheet version="1.0"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:fo="http://www.w3.org/1999/XSL/Format">
            <!-- This template sprinkles zero-width space characters in a
            text element -->
            <xsl:template match="text()" mode="insert-zero-spaces">
            <xsl:call-template name="intersperse-with-zero-
            spaces">
            <xsl:with-param name="str" select="."/>
            </xsl:call-template>
            </xsl:template>
            <xsl:template name="intersperse-with-zero-spaces">
            <xsl:param name="str"/>
            <xsl:variable name="spacechars">

                  
                 ​
            </xsl:variable>
            <xsl:if test="string-length($str) > 1">
            <xsl:variable name="c1" select="substring
            ($str, 1, 1)"/>
            <xsl:variable name="c2" select="substring
            ($str, 2, 1)"/>
            <xsl:value-of select="$c1"/>
            <!-- Insert a zero-width space between any
            two non-space characters -->
            <!-- <xsl:if test="not(contains($spacechars,
            $c1) or contains($spacechars,
            $c2))"> -->
            <!-- <xsl:text>​</xsl:text> -->
            <xsl:text>F</xsl:text>
            <!-- </xsl:if> -->
            <xsl:call-template name="intersperse-with-
            zero-spaces">
            <xsl:with-param name="str"
            select="substring($str, 2)"/>
            </xsl:call-template>
            </xsl:if>
            </xsl:template>
            </xsl:stylesheet>


            --- In XSL-FO@y..., "Nikolai Grigoriev" <grig@r...> wrote:
            > Hi,
            >
            > > Well, that just shows you how little I know about XSL...Is there
            some
            > > convenient way to transform a text element to one with zero-width
            > > spaces interspersed? Seems that would be a nifty transformation to
            > > have in our toolkit.
            >
            > <xsl:template match="text()" mode="insert-zero-spaces">
            > <xsl:call-template name="intersperse-with-zero-spaces">
            > <xsl:with-param name="str" select="."/>
            > </xsl:call-template>
            > </xsl:template>
            >
            > <xsl:template name="intersperse-with-zero-spaces">
            > <xsl:param name="str"/>
            > <xsl:variable name="spacechars">
            >
            >       
            >      ​
            > </xsl:variable>
            >
            > <xsl:if test="string-length($str) > 1">
            > <xsl:variable name="c1" select="substring($str, 1, 1)/>
            > <xsl:variable name="c2" select="substring($str, 2, 1)/>
            >
            > <xsl:value-of select="$c1"/>
            > <!-- Insert a zero-width space between any two non-space
            characters -->
            > <xsl:if test="not(contains($spacechars, $c1) or contains
            ($spacechars,
            > $c2))">
            > <xsl:text>​</xsl:text>
            > </xsl:if>
            >
            > <xsl:call-template name="intersperse-with-zero-spaces">
            > <xsl:with-param name="str" select="substring($str, 2)"/>
            > </xsl:call-template>
            > </xsl:if>
            > </xsl:call-template>
            >
            > Regards,
            >
            > Nikolai Grigoriev
            > RenderX
          • barrett808
            er, here s the actual code (minus spuriously commented out lines):
            Message 5 of 19 , Dec 6, 2001
            • 0 Attachment
              er, here's the actual code (minus spuriously commented out lines):

              <?xml version="1.0" encoding="UTF-16"?>
              <xsl:stylesheet version="1.0"
              xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
              xmlns:fo="http://www.w3.org/1999/XSL/Format">
              <!-- This template sprinkles zero-width space characters in a
              text element -->
              <xsl:template match="text()" mode="insert-zero-spaces">
              <xsl:call-template name="intersperse-with-zero-
              spaces">
              <xsl:with-param name="str" select="."/>
              </xsl:call-template>
              </xsl:template>
              <xsl:template name="intersperse-with-zero-spaces">
              <xsl:param name="str"/>
              <xsl:variable name="spacechars">

                    
                   ​
              </xsl:variable>
              <xsl:if test="string-length($str) > 1">
              <xsl:variable name="c1" select="substring
              ($str, 1, 1)"/>
              <xsl:variable name="c2" select="substring
              ($str, 2, 1)"/>
              <xsl:value-of select="$c1"/>
              <!-- Insert a zero-width space between any
              two non-space characters -->
              <xsl:if test="not(contains($spacechars, $c1)
              or contains($spacechars,
              $c2))">
              <xsl:text>​</xsl:text>
              <xsl:text>F</xsl:text>
              </xsl:if>
              <xsl:call-template name="intersperse-with-
              zero-spaces">
              <xsl:with-param name="str"
              select="substring($str, 2)"/>
              </xsl:call-template>
              </xsl:if>
              </xsl:template>
              </xsl:stylesheet>
            • barrett808
              Ah, progress: taking out the mode= insert-zero-spaces attribute from the first template gets me strings with embedded nonprintable characters, which is a lot
              Message 6 of 19 , Dec 6, 2001
              • 0 Attachment
                Ah, progress: taking out the mode="insert-zero-spaces" attribute from
                the first template gets me strings with embedded nonprintable
                characters, which is a lot closer. More to follow...

                --- In XSL-FO@y..., "barrett808" <blackbox@b...> wrote:
                > Thank you, Nikolai. This looks promising, but I'm having problems
                > making it work. Here's the code (slightly adapted) I'm using, and
                it
                > basically just spits out the text content of the elements with a
                > bunch of white space between them.
                >
                > <?xml version="1.0" encoding="UTF-16"?>
                > <xsl:stylesheet version="1.0"
                > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                > xmlns:fo="http://www.w3.org/1999/XSL/Format">
                > <!-- This template sprinkles zero-width space characters in a
                > text element -->
                > <xsl:template match="text()" mode="insert-zero-spaces">
                > <xsl:call-template name="intersperse-with-zero-
                > spaces">
                > <xsl:with-param name="str" select="."/>
                > </xsl:call-template>
                > </xsl:template>
                > <xsl:template name="intersperse-with-zero-spaces">
                > <xsl:param name="str"/>
                > <xsl:variable name="spacechars">
                >
                >       
                >      ​
                > </xsl:variable>
                > <xsl:if test="string-length($str) > 1">
                > <xsl:variable name="c1" select="substring
                > ($str, 1, 1)"/>
                > <xsl:variable name="c2" select="substring
                > ($str, 2, 1)"/>
                > <xsl:value-of select="$c1"/>
                > <!-- Insert a zero-width space between any
                > two non-space characters -->
                > <!-- <xsl:if test="not(contains($spacechars,
                > $c1) or contains($spacechars,
                > $c2))"> -->
                > <!-- <xsl:text>​</xsl:text> -->
                > <xsl:text>F</xsl:text>
                > <!-- </xsl:if> -->
                > <xsl:call-template name="intersperse-with-
                > zero-spaces">
                > <xsl:with-param name="str"
                > select="substring($str, 2)"/>
                > </xsl:call-template>
                > </xsl:if>
                > </xsl:template>
                > </xsl:stylesheet>
                >
                >
                > --- In XSL-FO@y..., "Nikolai Grigoriev" <grig@r...> wrote:
                > > Hi,
                > >
                > > > Well, that just shows you how little I know about XSL...Is
                there
                > some
                > > > convenient way to transform a text element to one with zero-
                width
                > > > spaces interspersed? Seems that would be a nifty transformation
                to
                > > > have in our toolkit.
                > >
                > > <xsl:template match="text()" mode="insert-zero-spaces">
                > > <xsl:call-template name="intersperse-with-zero-spaces">
                > > <xsl:with-param name="str" select="."/>
                > > </xsl:call-template>
                > > </xsl:template>
                > >
                > > <xsl:template name="intersperse-with-zero-spaces">
                > > <xsl:param name="str"/>
                > > <xsl:variable name="spacechars">
                > >
                > >       
                > >      ​
                > > </xsl:variable>
                > >
                > > <xsl:if test="string-length($str) > 1">
                > > <xsl:variable name="c1" select="substring($str, 1, 1)/>
                > > <xsl:variable name="c2" select="substring($str, 2, 1)/>
                > >
                > > <xsl:value-of select="$c1"/>
                > > <!-- Insert a zero-width space between any two non-space
                > characters -->
                > > <xsl:if test="not(contains($spacechars, $c1) or contains
                > ($spacechars,
                > > $c2))">
                > > <xsl:text>​</xsl:text>
                > > </xsl:if>
                > >
                > > <xsl:call-template name="intersperse-with-zero-spaces">
                > > <xsl:with-param name="str" select="substring($str,
                2)"/>
                > > </xsl:call-template>
                > > </xsl:if>
                > > </xsl:call-template>
                > >
                > > Regards,
                > >
                > > Nikolai Grigoriev
                > > RenderX
              • barrett808
                Okay, finally got it work exactly as I want it to, thanks Nikolai! Unfortunately, my FO renderer (XSL Formatter by Antenna House) doesn t seem to like these
                Message 7 of 19 , Dec 6, 2001
                • 0 Attachment
                  Okay, finally got it work exactly as I want it to, thanks Nikolai!
                  Unfortunately, my FO renderer (XSL Formatter by Antenna House)
                  doesn't seem to like these zero-width spaces. My name strings come
                  out as "L? a? s? t? N? a? m? e"

                  D'oh.


                  --- In XSL-FO@y..., "barrett808" <blackbox@b...> wrote:
                  > Ah, progress: taking out the mode="insert-zero-spaces" attribute
                  from
                  > the first template gets me strings with embedded nonprintable
                  > characters, which is a lot closer. More to follow...
                  >
                  > --- In XSL-FO@y..., "barrett808" <blackbox@b...> wrote:
                  > > Thank you, Nikolai. This looks promising, but I'm having problems
                  > > making it work. Here's the code (slightly adapted) I'm using, and
                  > it
                  > > basically just spits out the text content of the elements with a
                  > > bunch of white space between them.
                  > >
                  > > <?xml version="1.0" encoding="UTF-16"?>
                  > > <xsl:stylesheet version="1.0"
                  > > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  > > xmlns:fo="http://www.w3.org/1999/XSL/Format">
                  > > <!-- This template sprinkles zero-width space characters in a
                  > > text element -->
                  > > <xsl:template match="text()" mode="insert-zero-spaces">
                  > > <xsl:call-template name="intersperse-with-zero-
                  > > spaces">
                  > > <xsl:with-param name="str" select="."/>
                  > > </xsl:call-template>
                  > > </xsl:template>
                  > > <xsl:template name="intersperse-with-zero-spaces">
                  > > <xsl:param name="str"/>
                  > > <xsl:variable name="spacechars">
                  > >
                  > >       
                  > >      ​
                  > > </xsl:variable>
                  > > <xsl:if test="string-length($str) > 1">
                  > > <xsl:variable name="c1" select="substring
                  > > ($str, 1, 1)"/>
                  > > <xsl:variable name="c2" select="substring
                  > > ($str, 2, 1)"/>
                  > > <xsl:value-of select="$c1"/>
                  > > <!-- Insert a zero-width space between any
                  > > two non-space characters -->
                  > > <!-- <xsl:if test="not(contains($spacechars,
                  > > $c1) or contains($spacechars,
                  > > $c2))"> -->
                  > > <!-- <xsl:text>​</xsl:text> -->
                  > > <xsl:text>F</xsl:text>
                  > > <!-- </xsl:if> -->
                  > > <xsl:call-template name="intersperse-with-
                  > > zero-spaces">
                  > > <xsl:with-param name="str"
                  > > select="substring($str, 2)"/>
                  > > </xsl:call-template>
                  > > </xsl:if>
                  > > </xsl:template>
                  > > </xsl:stylesheet>
                  > >
                  > >
                  > > --- In XSL-FO@y..., "Nikolai Grigoriev" <grig@r...> wrote:
                  > > > Hi,
                  > > >
                  > > > > Well, that just shows you how little I know about XSL...Is
                  > there
                  > > some
                  > > > > convenient way to transform a text element to one with zero-
                  > width
                  > > > > spaces interspersed? Seems that would be a nifty
                  transformation
                  > to
                  > > > > have in our toolkit.
                  > > >
                  > > > <xsl:template match="text()" mode="insert-zero-spaces">
                  > > > <xsl:call-template name="intersperse-with-zero-spaces">
                  > > > <xsl:with-param name="str" select="."/>
                  > > > </xsl:call-template>
                  > > > </xsl:template>
                  > > >
                  > > > <xsl:template name="intersperse-with-zero-spaces">
                  > > > <xsl:param name="str"/>
                  > > > <xsl:variable name="spacechars">
                  > > >
                  > > >       
                  > > >      ​
                  > > > </xsl:variable>
                  > > >
                  > > > <xsl:if test="string-length($str) > 1">
                  > > > <xsl:variable name="c1" select="substring($str, 1, 1)/>
                  > > > <xsl:variable name="c2" select="substring($str, 2, 1)/>
                  > > >
                  > > > <xsl:value-of select="$c1"/>
                  > > > <!-- Insert a zero-width space between any two non-
                  space
                  > > characters -->
                  > > > <xsl:if test="not(contains($spacechars, $c1) or
                  contains
                  > > ($spacechars,
                  > > > $c2))">
                  > > > <xsl:text>​</xsl:text>
                  > > > </xsl:if>
                  > > >
                  > > > <xsl:call-template name="intersperse-with-zero-spaces">
                  > > > <xsl:with-param name="str" select="substring($str,
                  > 2)"/>
                  > > > </xsl:call-template>
                  > > > </xsl:if>
                  > > > </xsl:call-template>
                  > > >
                  > > > Regards,
                  > > >
                  > > > Nikolai Grigoriev
                  > > > RenderX
                • Nikolai Grigoriev
                  ... Hmm. For me, it worked in Saxon, XT, and Xalan after correcting several evident misprints. Below is the full text of my testing stylesheet. My guess: you
                  Message 8 of 19 , Dec 6, 2001
                  • 0 Attachment
                    > Thank you, Nikolai. This looks promising, but I'm having problems
                    > making it work. Here's the code (slightly adapted) I'm using, and it
                    > basically just spits out the text content of the elements with a
                    > bunch of white space between them.

                    Hmm. For me, it worked in Saxon, XT, and Xalan after correcting several
                    evident misprints. Below is the full text of my testing stylesheet.

                    My guess: you have result indenting turned on. You need to insert

                    <xsl:output method="xml" indent="no"/>

                    at the top of your stylesheet, to limit XSLT processor's freedom
                    to rearrange white space.

                    Regards,
                    Nikolai

                    P.S. Here's what I used for test. It's identity transformation,
                    plus the template that I posted originally.

                    <xsl:stylesheet version="1.0"
                    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
                    <xsl:output method="xml" indent="no"/>

                    <!-- Everything but test nodes: identity transformation -->
                    <xsl:template match="/|*|@*|comment()|processing-instruction()">
                    <xsl:copy>
                    <xsl:apply-templates
                    select="*|@*|text()|comment()|processing-instruction()"/>
                    </xsl:copy>
                    </xsl:template>


                    <!-- Text nodes: intercalate with zwsp's -->
                    <xsl:template match="text()">
                    <xsl:call-template name="intersperse-with-zero-spaces">
                    <xsl:with-param name="str" select="."/>
                    </xsl:call-template>
                    </xsl:template>

                    <!-- Actual intercalation: recursive -->
                    <xsl:template name="intersperse-with-zero-spaces">
                    <xsl:param name="str"/>
                    <xsl:variable name="spacechars">

                          
                         ​
                    </xsl:variable>

                    <xsl:if test="string-length($str) > 0">
                    <xsl:variable name="c1"
                    select="substring($str, 1, 1)"/>
                    <xsl:variable name="c2"
                    select="substring($str, 2, 1)"/>

                    <xsl:value-of select="$c1"/>
                    <xsl:if test="$c2 != '' and
                    not(contains($spacechars, $c1) or
                    contains($spacechars, $c2))">
                    <xsl:text>​</xsl:text>
                    </xsl:if>

                    <xsl:call-template name="intersperse-with-zero-spaces">
                    <xsl:with-param name="str" select="substring($str, 2)"/>
                    </xsl:call-template>
                    </xsl:if>
                    </xsl:template>

                    </xsl:stylesheet>
                  • Nikolai Grigoriev
                    Hi, ... Two things: 1) my original post contained an error that still persists in your stylesheet: the last character in each text node will be stripped. For
                    Message 9 of 19 , Dec 6, 2001
                    • 0 Attachment
                      Hi,

                      > Ah, progress: taking out the mode="insert-zero-spaces" attribute from
                      > the first template gets me strings with embedded nonprintable
                      > characters, which is a lot closer. More to follow...

                      Two things:

                      1) my original post contained an error that still persists in your stylesheet:
                      the last character in each text node will be stripped. For fix, see my previous
                      mail;

                      2) I put it in a separate mode because I thought it should be applicable to
                      text only inside table cells. It is convenient to switch modes in these cases.

                      Regards,
                      Nikolai
                    • barrett808
                      I have Nikolai s code working just right for my purpose, and after some hacking on my instance document, I can get XEP to render it. XEP complains about
                      Message 10 of 19 , Dec 7, 2001
                      • 0 Attachment
                        I have Nikolai's code working just right for my purpose, and after
                        some hacking on my instance document, I can get XEP to render it. XEP
                        complains about xml:space, and spuriously complains about fo:page-
                        sequence needing master-name to be declared (it is), also doesn't
                        handle UTF-16 encoding. (Apache FOP complains about many basic FO
                        attributes being not-yet-implemented and produces completely screwed-
                        up output; XSL Formatter doesn't seem to understand zero-width
                        characters at all).

                        But after hacking my document to make XEP happy, what comes out is
                        suboptimal: it appears the zero-width space characters (Unicode 200B)
                        are being rendered as regular spaces. Same with the hair-width char
                        (200A).

                        So it appears I don't have a real solution. :(
                      • dvd@renderx.com
                        ... This is a difference between the obsolete XSL FO C(andidate)R and the current XSL FO Recommendation. In the Candidate fo:page-sequence had attributed named
                        Message 11 of 19 , Dec 8, 2001
                        • 0 Attachment
                          >
                          >
                          > I have Nikolai's code working just right for my purpose, and after
                          > some hacking on my instance document, I can get XEP to render it. XEP
                          > complains about xml:space, and spuriously complains about fo:page-
                          > sequence needing master-name to be declared (it is), also doesn't

                          This is a difference between the obsolete XSL FO C(andidate)R and
                          the current XSL FO Recommendation. In the Candidate fo:page-sequence
                          had attributed named 'master-name'. In the final Recommendation it
                          was renamed to 'master-reference'. The phrase 'master-name needs to be
                          declared for' means that it is not declared in the DTD the xml is being
                          validated against, as opposite to be DEFINED in the xml (xsl fo file)
                          itself.

                          The diagnostics means that master-name is NOT DECLARED In the DTD and
                          thus is not allowed in your XSL FO. Upgrade your stylesheets and
                          you'll get rid off the message.

                          > handle UTF-16 encoding.

                          This is not an issue with XEP. Any SAX XML parser may be plugged into,
                          thus just choose one that supports encodings you need.

                          > But after hacking my document to make XEP happy, what comes out is
                          > suboptimal: it appears the zero-width space characters (Unicode 200B)
                          > are being rendered as regular spaces. Same with the hair-width char
                          > (200A).

                          200A and 200b are rendered differently. 200b is just removed from the
                          output. 200b is used internally to mark places where line breaks are appropriate,
                          and if it looked like a space that would be obvious. It is not rendered.

                          David Tolpin
                        Your message has been successfully submitted and would be delivered to recipients shortly.