To resolve this issue, I just replaced all spaces with a special character say ~
in XML strings and then in xslt I used above template with just little modification (using if
instead of when
, which I don't know why when
didn't work) and I was done. Now in pdf all my strings contains white spaces where I need them. May be below code is an amateur one but for time being it has worked for me.
<xsl:template name="add-spaces">
<xsl:param name="text" select="COMMENTS" />
<xsl:if test="$text != ''">
<xsl:variable name="letter" select="substring($text, 1, 1)" />
<xsl:if test="$letter = '~'">
<xsl:text> </xsl:text>
</xsl:if>
<xsl:if test="$letter != '~'">
<fo:inline>
<xsl:value-of select="$letter" />
</fo:inline>
</xsl:if>
<xsl:call-template name="add-spaces">
<xsl:with-param name="text"
select="substring-after($text, $letter)" />
</xsl:call-template>
</xsl:if>
</xsl:template>
<!-- Above is template and its call where I displayed strings is-->
<xsl:call-template
name="add-spaces">
<xsl:with-param
name="text"
select="COMMENTS" />
</xsl:call-template>