This is the mail archive of the docbook-apps@lists.oasis-open.org mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Re: A good tag for representing a very long URL


I thought of a way to get around the limitation that renderer's don't
support zero-width spaces. Use a space with a font-size of zero:

		<fo:character 
		  character=" "
		  font-size="0pt" 
		  treat-as-word-space="true"/>

The code to import into your customization layer is pasted at the bottom
of this message (I think it also makes the hot text blue). It still
smells too much like a hack to include in the standard xsls. The spaces
really are there, so if you cut-and-paste a url, the url is useless
(e.g. o a s i s . o r g ), but the text in the pdf is hot anyway and the
url is only there because a pdf could be printed. It would be tempting
to use the trick for other elements that contain stuff that can't be
hyphenated but should wrap (e.g. code), but there you might have users
frustrated that they can't cut and paste your code samples.

Note the actual xsl that does the interspersing is Julien Letessier's
(and I think he was working from something Nikolai Grigoriev posted on
the xsl-fo list). I also changed it so that it doesn't start
interspersing spaces till after the 15th character (so you don't end up
with "h[linebreak]ttp://..." I suppose it could be made so that spaces
aren't interspersed in the last few characters of the url either. 

David

> -----Original Message-----
> From: Norman Walsh [mailto:ndw@nwalsh.com]
> Sent: Sunday, January 27, 2002 1:04 PM
> To: docbook-apps
> Subject: DOCBOOK-APPS: Re: A good tag for representing a very long URL
> 
> 
> / David Cramer <dcramer@broadjump.com> was heard to say:
> | Also take a look at this post:
> |
> | 
> http://lists.oasis-open.org/archives/docbook-apps/200201/msg00267.html
> 
> This post suggests zero-width spaces instead of discretionary hyphens.
> (Actually, it uses hair-width spaces instead of zero-width spaces,
> which I think is a bug, but nevermind).
> 
> Unfortunately, using zero-width spaces doesn't work in XEP, 
> FOP, or PassiveTeX.
> Using discretionary hyphens works in XEP and PassiveTeX, but 
> not in FOP
> 
> So I think I'll stick with discretionary hyphens for the 
> moment and leave
> an option to turn it off if desired.
> 
>                                         Be seeing you,
                                           norm

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                xmlns:fo="http://www.w3.org/1999/XSL/Format";
                version='1.0'>

    <!-- colored links with invisible spaces interspersed so that long
urls will wrap -->
    <xsl:template match="ulink">
        <fo:basic-link external-destination="{@url}"
                xsl:use-attribute-sets="xref.properties"
                color="#0000AA">
            <xsl:choose>
                <xsl:when test="count(child::node())=0">
                    <xsl:value-of select="@url" />
                </xsl:when>
                <xsl:otherwise>
                    <xsl:apply-templates />
                </xsl:otherwise>
            </xsl:choose>
        </fo:basic-link>
        <xsl:if test="count(child::node()) != 0">
            <fo:inline hyphenate="true">
                <xsl:text> (</xsl:text>
                <xsl:value-of select="substring(@url,0,15)"/>
                <xsl:call-template name="intersperse-with-zero-spaces">
                    <xsl:with-param name="str"
select="substring(@url,15)"/>
                </xsl:call-template>
                <xsl:text>)</xsl:text>
            </fo:inline>
        </xsl:if>
    </xsl:template>

    <!-- Actual space intercalation: recursive -->
    <xsl:template name="intersperse-with-zero-spaces">
        <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))">
		<fo:character 
		  character=" "
		  font-size="0pt" 
		  treat-as-word-space="true"/>
            </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>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]