Re: [xep-support] Support of special types of spaces

From: Jirka Kosek <jirka@kosek.cz>
Date: Thu Oct 20 2005 - 01:55:58 PDT

Broberg, Mats wrote:

> fact that one even needs to discuss it is beyond my imagination. How it
> is solved technically is of less importance to the typesetter, but the
> fixed spaces need to be easily entered, correctly processed and properly
> output at the desired width. Period.

Indeed. You can use Unicode characters to specify these fine tuned
spacing and add following XSLT code into transformation to get proper
spacing in output.

<xsl:template match="text()">
   <xsl:call-template name="space.2000.subst">
     <xsl:with-param name="string" select="."/>
   </xsl:call-template>
</xsl:template>

<!-- You can adjust width of spaces by parameters. Empty value means
that space is not converted to fo:leader -->
<xsl:param name="space.enquad.width">0.5em</xsl:param> <!-- U+2000 -->
<xsl:param name="space.emquad.width">1em</xsl:param> <!-- U+2001 -->
<xsl:param name="space.enspace.width">0.5em</xsl:param><!-- U+2002 -->
<xsl:param name="space.emspace.width">1em</xsl:param><!-- U+2003 -->
<xsl:param name="space.3emspace.width">0.33em</xsl:param><!-- U+2004 -->
<xsl:param name="space.4emspace.width">0.25em</xsl:param><!-- U+2005 -->
<xsl:param name="space.6emspace.width">0.16em</xsl:param><!-- U+2006 -->
<xsl:param name="space.figspace.width"></xsl:param><!-- U+2007 -->
<xsl:param name="space.punctspace.width"></xsl:param><!-- U+2008 -->
<xsl:param name="space.thinspace.width">0.2em</xsl:param><!-- U+2009 -->
<xsl:param name="space.hairspace.width">0.1em</xsl:param><!-- U+200A -->

<xsl:template name="space.2000.subst">
   <xsl:param name="string"/>

   <xsl:choose>
     <xsl:when test="contains($string, '&#x2000;') and
$space.enquad.width != ''">
       <xsl:call-template name="space.2001.subst">
        <xsl:with-param name="string" select="substring-before($string,
'&#x2000;')"/>
       </xsl:call-template>
       <fo:leader leader-length="{$space.enquad.width}"/>
       <xsl:call-template name="space.2000.subst">
        <xsl:with-param name="string" select="substring-after($string,
'&#x2000;')"/>
       </xsl:call-template>
     </xsl:when>
     <xsl:otherwise>
       <xsl:call-template name="space.2001.subst">
        <xsl:with-param name="string" select="$string"/>
       </xsl:call-template>
     </xsl:otherwise>
   </xsl:choose>
</xsl:template>

<xsl:template name="space.2001.subst">
   <xsl:param name="string"/>

   <xsl:choose>
     <xsl:when test="contains($string, '&#x2001;') and
$space.emquad.width != ''">
       <xsl:call-template name="space.2002.subst">
        <xsl:with-param name="string" select="substring-before($string,
'&#x2001;')"/>
       </xsl:call-template>
       <fo:leader leader-length="{$space.emquad.width}"/>
       <xsl:call-template name="space.2001.subst">
        <xsl:with-param name="string" select="substring-after($string,
'&#x2001;')"/>
       </xsl:call-template>
     </xsl:when>
     <xsl:otherwise>
       <xsl:call-template name="space.2002.subst">
        <xsl:with-param name="string" select="$string"/>
       </xsl:call-template>
     </xsl:otherwise>
   </xsl:choose>
</xsl:template>

<xsl:template name="space.2002.subst">
   <xsl:param name="string"/>

   <xsl:choose>
     <xsl:when test="contains($string, '&#x2002;') and
$space.enspace.width != ''">
       <xsl:call-template name="space.2003.subst">
        <xsl:with-param name="string" select="substring-before($string,
'&#x2002;')"/>
       </xsl:call-template>
       <fo:leader leader-length="{$space.enspace.width}"/>
       <xsl:call-template name="space.2002.subst">
        <xsl:with-param name="string" select="substring-after($string,
'&#x2002;')"/>
       </xsl:call-template>
     </xsl:when>
     <xsl:otherwise>
       <xsl:call-template name="space.2003.subst">
        <xsl:with-param name="string" select="$string"/>
       </xsl:call-template>
     </xsl:otherwise>
   </xsl:choose>
</xsl:template>

<xsl:template name="space.2003.subst">
   <xsl:param name="string"/>

   <xsl:choose>
     <xsl:when test="contains($string, '&#x2003;') and
$space.emspace.width != ''">
       <xsl:call-template name="space.2004.subst">
        <xsl:with-param name="string" select="substring-before($string,
'&#x2003;')"/>
       </xsl:call-template>
       <fo:leader leader-length="{$space.emspace.width}"/>
       <xsl:call-template name="space.2003.subst">
        <xsl:with-param name="string" select="substring-after($string,
'&#x2003;')"/>
       </xsl:call-template>
     </xsl:when>
     <xsl:otherwise>
       <xsl:call-template name="space.2004.subst">
        <xsl:with-param name="string" select="$string"/>
       </xsl:call-template>
     </xsl:otherwise>
   </xsl:choose>
</xsl:template>

<xsl:template name="space.2004.subst">
   <xsl:param name="string"/>

   <xsl:choose>
     <xsl:when test="contains($string, '&#x2004;') and
$space.3emspace.width != ''">
       <xsl:call-template name="space.2005.subst">
        <xsl:with-param name="string" select="substring-before($string,
'&#x2004;')"/>
       </xsl:call-template>
       <fo:leader leader-length="{$space.3emspace.width}"/>
       <xsl:call-template name="space.2004.subst">
        <xsl:with-param name="string" select="substring-after($string,
'&#x2004;')"/>
       </xsl:call-template>
     </xsl:when>
     <xsl:otherwise>
       <xsl:call-template name="space.2005.subst">
        <xsl:with-param name="string" select="$string"/>
       </xsl:call-template>
     </xsl:otherwise>
   </xsl:choose>
</xsl:template>

<xsl:template name="space.2005.subst">
   <xsl:param name="string"/>

   <xsl:choose>
     <xsl:when test="contains($string, '&#x2005;') and
$space.4emspace.width != ''">
       <xsl:call-template name="space.2006.subst">
        <xsl:with-param name="string" select="substring-before($string,
'&#x2005;')"/>
       </xsl:call-template>
       <fo:leader leader-length="{$space.4emspace.width}"/>
       <xsl:call-template name="space.2005.subst">
        <xsl:with-param name="string" select="substring-after($string,
'&#x2005;')"/>
       </xsl:call-template>
     </xsl:when>
     <xsl:otherwise>
       <xsl:call-template name="space.2006.subst">
        <xsl:with-param name="string" select="$string"/>
       </xsl:call-template>
     </xsl:otherwise>
   </xsl:choose>
</xsl:template>

<xsl:template name="space.2006.subst">
   <xsl:param name="string"/>

   <xsl:choose>
     <xsl:when test="contains($string, '&#x2006;') and
$space.6emspace.width != ''">
       <xsl:call-template name="space.2007.subst">
        <xsl:with-param name="string" select="substring-before($string,
'&#x2006;')"/>
       </xsl:call-template>
       <fo:leader leader-length="{$space.6emspace.width}"/>
       <xsl:call-template name="space.2006.subst">
        <xsl:with-param name="string" select="substring-after($string,
'&#x2006;')"/>
       </xsl:call-template>
     </xsl:when>
     <xsl:otherwise>
       <xsl:call-template name="space.2007.subst">
        <xsl:with-param name="string" select="$string"/>
       </xsl:call-template>
     </xsl:otherwise>
   </xsl:choose>
</xsl:template>

<xsl:template name="space.2007.subst">
   <xsl:param name="string"/>

   <xsl:choose>
     <xsl:when test="contains($string, '&#x2007;') and
$space.figspace.width != ''">
       <xsl:call-template name="space.2008.subst">
        <xsl:with-param name="string" select="substring-before($string,
'&#x2007;')"/>
       </xsl:call-template>
       <fo:leader leader-length="{$space.figspace.width}"/>
       <xsl:call-template name="space.2007.subst">
        <xsl:with-param name="string" select="substring-after($string,
'&#x2007;')"/>
       </xsl:call-template>
     </xsl:when>
     <xsl:otherwise>
       <xsl:call-template name="space.2008.subst">
        <xsl:with-param name="string" select="$string"/>
       </xsl:call-template>
     </xsl:otherwise>
   </xsl:choose>
</xsl:template>

<xsl:template name="space.2008.subst">
   <xsl:param name="string"/>

   <xsl:choose>
     <xsl:when test="contains($string, '&#x2008;') and
$space.punctspace.width != ''">
       <xsl:call-template name="space.2009.subst">
        <xsl:with-param name="string" select="substring-before($string,
'&#x2008;')"/>
       </xsl:call-template>
       <fo:leader leader-length="{$space.punctspace.width}"/>
       <xsl:call-template name="space.2008.subst">
        <xsl:with-param name="string" select="substring-after($string,
'&#x2008;')"/>
       </xsl:call-template>
     </xsl:when>
     <xsl:otherwise>
       <xsl:call-template name="space.2009.subst">
        <xsl:with-param name="string" select="$string"/>
       </xsl:call-template>
     </xsl:otherwise>
   </xsl:choose>
</xsl:template>

<xsl:template name="space.2009.subst">
   <xsl:param name="string"/>

   <xsl:choose>
     <xsl:when test="contains($string, '&#x2009;') and
$space.thinspace.width != ''">
       <xsl:call-template name="space.200A.subst">
        <xsl:with-param name="string" select="substring-before($string,
'&#x2009;')"/>
       </xsl:call-template>
       <fo:leader leader-length="{$space.thinspace.width}"/>
       <xsl:call-template name="space.2009.subst">
        <xsl:with-param name="string" select="substring-after($string,
'&#x2009;')"/>
       </xsl:call-template>
     </xsl:when>
     <xsl:otherwise>
       <xsl:call-template name="space.200A.subst">
        <xsl:with-param name="string" select="$string"/>
       </xsl:call-template>
     </xsl:otherwise>
   </xsl:choose>
</xsl:template>

<xsl:template name="space.200A.subst">
   <xsl:param name="string"/>

   <xsl:choose>
     <xsl:when test="contains($string, '&#x200A;') and
$space.hairspace.width != ''">
       <xsl:value-of select="substring-before($string, '&#x200A;')"/>
       <fo:leader leader-length="{$space.hairspace.width}"/>
       <xsl:call-template name="space.200A.subst">
        <xsl:with-param name="string" select="substring-after($string,
'&#x200A;')"/>
       </xsl:call-template>
     </xsl:when>
     <xsl:otherwise>
       <xsl:value-of select="$string"/>
     </xsl:otherwise>
   </xsl:choose>
</xsl:template>

I will add this code into the DocBook XSL stylesheets, so it will just
works for them.

                                Jirka

-- 
------------------------------------------------------------------
   Jirka Kosek     e-mail: jirka@kosek.cz     http://www.kosek.cz
------------------------------------------------------------------
   Profesionální školení a poradenství v oblasti technologií XML.
      Podívejte se na náš nově spuštěný web http://DocBook.cz
        Podrobný přehled školení http://xmlguru.cz/skoleni/
------------------------------------------------------------------
   Nejbližší termíny školení: DocBook 5.-7.12. * XSL-FO 19.-20.12.
      XSLT 17.-20.10. * XML schémata (včetně RELAX NG) 7.-9.11.
------------------------------------------------------------------

-------------------
(*) To unsubscribe, send a message with words 'unsubscribe xep-support'
in the body of the message to majordomo@renderx.com from the address
you are subscribed from.
(*) By using the Service, you expressly agree to these Terms of Service http://www.renderx.com/terms-of-service.html

Received on Thu Oct 20 02:23:22 2005

This archive was generated by hypermail 2.1.8 : Thu Oct 20 2005 - 02:23:23 PDT