xsl-list
[Top] [All Lists]

Re: [xsl] Text output line width setting technique

2009-04-08 05:48:33
Hi All,
I have found a solution for the same.
<xsl:template name="wrap-string">
    <xsl:param name="str" />
    <xsl:param name="wrap-col" />
    <xsl:param name="break-mark" />
    <xsl:param name="pos" select="0" />
    <xsl:choose>
        <xsl:when test="contains( $str, ' ' )">
            <xsl:variable name="before" select="substring-before(
$str, ' ' )" />
            <xsl:variable name="pos-now" select="$pos + string-length(
$before )" />

            <xsl:choose>
                <xsl:when test="$pos = 0" />
                <xsl:when test="floor( $pos div $wrap-col ) != floor(
$pos-now div $wrap-col )">
                    <xsl:copy-of select="$break-mark" />
                </xsl:when>
                <xsl:otherwise>
                    <xsl:text> </xsl:text>
                </xsl:otherwise>
            </xsl:choose>

            <xsl:value-of select="$before" />

            <xsl:call-template name="wrap-string">
                <xsl:with-param name="str" select="substring-after(
$str, ' ' )" />
                <xsl:with-param name="wrap-col" select="$wrap-col" />
                <xsl:with-param name="break-mark" select="$break-mark" />
                <xsl:with-param name="pos" select="$pos-now" />
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:if test="$pos &gt; 0"><xsl:text> </xsl:text></xsl:if>
            <xsl:value-of select="$str" />
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
and it can be invoked by calling
     <xsl:call-template name="wrap-string">
        <xsl:with-param name="str" select="normalize-space(.)"/>
        <xsl:with-param name="wrap-col" select="80"/>
        <xsl:with-param name="break-mark" select="'&#9;&#10;&#13;'"/>
      </xsl:call-template>
I hope it might help one like me.


On Wed, Apr 8, 2009 at 10:39 AM, Michael Ludwig <mlu(_at_)as-guides(_dot_)com> 
wrote:
Senthilukvelaan schrieb:

I use XSLT 1.0.
is there any way to text hard wrapping by line size in XSLT1.0.

It is possible doing it by hand. But honestly, I wouldn't attempt it,
too much tedium.

I'd consider postprocessing the transformation output using Perl
and the excellent Text::Autoformat module by Damian Conway.

http://search.cpan.org/perldoc/Text::Autoformat

Michael Ludwig

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>