[xep-support] Hyphenation at /

Jirka Kosek jirka at kosek.cz
Fri Apr 9 05:05:14 PDT 2004


Nikolai Grigoriev wrote:

> You are not supposed to do it manually: stylesheets or other preprocessors
> should be able to cope with the task. Our initial assumption was that 
> a user can implement a line breaking algorighm of whatever complexity
> by writing a separate preprocessor that would insert zero-width spaces 
> and soft hyphens to control the formatter. Now it seems that the interface
> is too low-level, and requires too much effort to leverage. 

Just for the case that someone is intersted. I implemented exatly this 
yesterday. The following customization layer for DocBook XSL stylesheets 
allows line-breaking at /, \ and . (dot) when they are emitted as 
monospaced text by stylesheet (this includes e.g. filenames, classnames, 
function names and other similar markup).

<?xml version="1.0" encoding="windows-1250"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 xmlns:fo="http://www.w3.org/1999/XSL/Format"
                 xmlns:exsl="http://exslt.org/common"
                 extension-element-prefixes="exsl"
                 exclude-result-prefixes="exsl"
                 version="1.0">

<xsl:import 
href="http://docbook.sourceforge.net/release/xsl/current/fo/docbook.xsl"/>

<xsl:template name="inline.monoseq">
   <xsl:param name="content">
     <xsl:apply-templates/>
   </xsl:param>
   <fo:inline xsl:use-attribute-sets="monospace.properties">
     <xsl:if test="@dir">
       <xsl:attribute name="direction">
         <xsl:choose>
           <xsl:when test="@dir = 'ltr' or @dir = 'lro'">ltr</xsl:when>
           <xsl:otherwise>rtl</xsl:otherwise>
         </xsl:choose>
       </xsl:attribute>
     </xsl:if>
     <xsl:apply-templates select="exsl:node-set($content)" 
mode="hyphenatize"/>
   </fo:inline>
</xsl:template>

<xsl:template match="text()" mode="hyphenatize" priority="2">
   <xsl:call-template name="string.subst">
     <xsl:with-param name="string">
       <xsl:call-template name="string.subst">
         <xsl:with-param name="string">
           <xsl:call-template name="string.subst">
             <xsl:with-param name="string" select="."/>
             <xsl:with-param name="target" select="'.'"/>
             <xsl:with-param name="replacement" select="'.&#x200B;'"/>
           </xsl:call-template>
         </xsl:with-param>
         <xsl:with-param name="target" select="'\'"/>
         <xsl:with-param name="replacement" select="'\&#x200B;'"/>
       </xsl:call-template>
     </xsl:with-param>
     <xsl:with-param name="target" select="'/'"/>
     <xsl:with-param name="replacement" select="'/&#x200B;'"/>
   </xsl:call-template>
</xsl:template>

<xsl:template match="node()|@*" mode="hyphenatize">
   <xsl:copy>
     <xsl:apply-templates select="node()|@*" mode="hyphenatize"/>
   </xsl:copy>
</xsl:template>

</xsl:stylesheet>

HTH,

						Jirka

-- 
------------------------------------------------------------------
   Jirka Kosek     e-mail: jirka at kosek.cz     http://www.kosek.cz
------------------------------------------------------------------
   Profesionální školení a poradenství v oblasti technologií XML.
         XML a Java 13.-14.4.            XSL-FO 20.4.
         DocBook 18.-19.5.               XSLT 24.-26.5.
------------------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3158 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.renderx.com/pipermail/xep-support/attachments/20040409/1ce8e113/attachment-0001.bin>


More information about the Xep-support mailing list