-1

From xml data source; have to render mix characters/strings which may exceed the available view port; below are the two sample data source which can flow in the xml:

Sample 1:

<NoticeDetails>
<![CDATA[Owner of this area is camping world technical institute don't park your car here; adhear the notice on the board.]]>
</NoticeDetails>

Sample 2:

<NoticeDetails>
<!CDATA[Owner_Of_This_Are_Is_Camping_world_Technical_Institute_Don't_Park_Your_Car_Here_Adhear_The_Notice_On_The_Board.]]>
</NoticeDetails>

Note: This xml is not a complete xml this is just to give the fundamental idea how element looks like.

Now if we see the first sample which is a sentence but second sample is a long string having many characters (no space is there in between). So if we not apply any explicit treatment fop do apply auto wrapping based upon non zero width spaces coming in the sentence. But fop is not applying auto wrapping for sample 2;

Rendering sample one:

enter image description here

Rendering sample two:

enter image description here

So in order to fix this we are applying auto wrapping treatment below is the code snippet:

 <xsl:call-template name="disperseZeroSpace">
 <xsl:with-param name="str" select="NoticeDetails"/>
</xsl:call-template>

<xsl:template name="disperseZeroSpace">
<xsl:param name="str"/>

  <xsl:variable name="spacechars">
        &#x9;&#xA;
        &#x2000;&#x2001;&#x2002;&#x2003;&#x2004;&#x2005;
        &#x2006;&#x2007;&#x2008;&#x2009;&#x200A;&#x200B;
   </xsl:variable>


    <xsl:if test="string-length($str) &gt; 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>&#x200B;</xsl:text>
        </xsl:if>

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

Here I am expecting above code to apply zero width space treatment if that is not a non-zero width space in the sentence

With this sample 1 xml is getting rendered like below:

enter image description here

but I am expecting this to appear like below:

enter image description here

Sample 2 is coming as expected:

enter image description here

Seems like the 0 width treatment is not able to identify the non zero width space and it is applying 0 width space irrespective of that; so what is the Unicode for normal space? Or what would be the solution here?

lfurini
  • 3,729
  • 4
  • 30
  • 48
Rito Sarkar
  • 35
  • 1
  • 8
  • Related, not duplicate: https://stackoverflow.com/q/4350788/4453460 (that's where the `disperseZeroSpace` template comes from). – lfurini Sep 01 '23 at 12:36
  • 1
    The template you are calling inserts a zero-width space between every couple of characters that are not spaces, so between the "t" and "e" in "technical" also. – lfurini Sep 01 '23 at 12:39

0 Answers0