[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: substring manipulation to wrap text in an SVG <rec

Subject: Re: substring manipulation to wrap text in an SVG <rect>
From: Jörg Heinicke <joerg.heinicke@xxxxxx>
Date: Mon, 17 Sep 2001 23:36:23 +0200
svg text wrap
I wrote a stylesheet for text-wrapping a few weeks ago. It must be adapted a
liitle bit, but it could be a help I think. Important is the template named
"word-wrap".

This is a stylesheet for transforming a Docbook-glossary to a text-file.
Also there is a indenting implemented. So it's maybe interesting for other
people too. For the SVG-text you can simplify it.

Regards,

Joerg


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

    <xsl:template match="chapter">
        <xsl:apply-templates select="glossary"/>
    </xsl:template>

    <xsl:template match="glossary">

<xsl:text>##################################################################
##############
</xsl:text>
        <xsl:apply-templates select="title"/>
        <xsl:text>
############################################################################
####

</xsl:text>
        <xsl:apply-templates select="glossdiv|glosslist|glossentry"/>
    </xsl:template>

    <xsl:template match="glossdiv">

<xsl:text>==================================================================
==============
</xsl:text>
        <xsl:apply-templates select="title"/>
        <xsl:text>
</xsl:text>
        <xsl:apply-templates select="para"/>

<xsl:text>==================================================================
==============

</xsl:text>
        <xsl:apply-templates select="glosslist|glossentry"/>
    </xsl:template>

    <xsl:template match="glosslist">
        <xsl:apply-templates select="glossentry"/>
    </xsl:template>

    <xsl:template match="glossentry">
        <xsl:apply-templates select="glossterm|glossdef"/>
    </xsl:template>

    <xsl:template match="glossterm">
        <xsl:for-each select="ancestor::*[not(name()='chapter' or
name()='glossary')]">
            <xsl:text>   </xsl:text>
        </xsl:for-each>
        <xsl:value-of select="normalize-space(.)"/>
        <xsl:text>
</xsl:text>
    </xsl:template>

    <xsl:template match="glossdef">
        <xsl:apply-templates select="para|glosslist"/>
    </xsl:template>

    <xsl:template match="title">
        <xsl:value-of select="normalize-space(.)"/>
    </xsl:template>

    <xsl:template match="para">
        <xsl:call-template name="word-wrap">
            <xsl:with-param name="indent">
                <xsl:for-each select="ancestor::*[not(name()='chapter' or
name()='glossary')]">
                    <xsl:text>   </xsl:text>
                </xsl:for-each>
            </xsl:with-param>
            <xsl:with-param name="tobewrapped" select="normalize-space(.)"/>
        </xsl:call-template>
        <xsl:text>

</xsl:text>
    </xsl:template>

    <xsl:template match="*">
        <xsl:value-of select="text()"/>
    </xsl:template>

    <xsl:template name="word-wrap">
        <xsl:param name="tobewrapped"/>
        <xsl:param name="size" select="0"/>
        <xsl:param name="indent"/>
        <xsl:variable name="maxlength" select="80"/>
        <xsl:choose>
            <xsl:when test="contains($tobewrapped,' ')">
                <xsl:variable name="word"
select="substring-before($tobewrapped,' ')"/>
                <xsl:variable name="length" select="string-length($word)"/>
                <xsl:choose>
                    <xsl:when test="$size=0">
                        <xsl:value-of select="$indent"/>
                        <xsl:value-of select="$word"/>
                        <xsl:call-template name="word-wrap">
                            <xsl:with-param name="tobewrapped"
select="substring-after($tobewrapped,' ')"/>
                            <xsl:with-param name="size"
select="string-length(concat($indent,$word))"/>
                            <xsl:with-param name="indent" select="$indent"/>
                        </xsl:call-template>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:choose>
                            <xsl:when test="($size + $length + 1) >
$maxlength">
                                <xsl:text>
</xsl:text>
                                <xsl:value-of select="$indent"/>
                                <xsl:value-of select="$word"/>
                                <xsl:call-template name="word-wrap">
                                    <xsl:with-param name="tobewrapped"
select="substring-after($tobewrapped,' ')"/>
                                    <xsl:with-param name="size"
select="string-length(concat($indent,$word))"/>
                                    <xsl:with-param name="indent"
select="$indent"/>
                                </xsl:call-template>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="concat(' ',$word)"/>
                                <xsl:call-template name="word-wrap">
                                    <xsl:with-param name="tobewrapped"
select="substring-after($tobewrapped,' ')"/>
                                    <xsl:with-param name="size"
select="$size + 1 + string-length($word)"/>
                                    <xsl:with-param name="indent"
select="$indent"/>
                                </xsl:call-template>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
                <xsl:choose>
                    <xsl:when test="$size=0">
                        <xsl:value-of select="$indent"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:choose>
                            <xsl:when test="$size +
string-length($tobewrapped) > $maxlength">
                                <xsl:text>
</xsl:text>
                                <xsl:value-of select="$indent"/>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:text> </xsl:text>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:otherwise>
                </xsl:choose>
                <xsl:value-of select="$tobewrapped"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.