OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

docbook-apps message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]


Subject: Re: [docbook-apps] Aligning numbers in table cells with xsl


Thanks Bob for the tip about translate. I finally worked it out - coding as follows:

<xsl:template name="table.cell.block.properties">   
   
<xsl:variable name="stringanglesymbol">
     
<xsl:choose>
       
<xsl:when test="contains(., '&lt;')">
         
<xsl:value-of select="(translate(., '&lt;', ''))" />
       
</xsl:when>
       
<xsl:when test="contains(., '&gt;')">
         
<xsl:value-of select="(translate(., '&gt;', ''))" />
       
</xsl:when>
     
</xsl:choose>     
   
</xsl:variable>
   
   
<!--margin and indent for portrait format tables-->   
   
<xsl:choose>
     
<xsl:when test="(ancestor-or-self::d:table/@tabstyle = 'numbers' or
        ancestor-or-self::d:table/@tabstyle = 'numberstripe') and not(ancestor::d:thead or
        ancestor::d:tfoot) and preceding-sibling::d:entry and ((string(number($stringanglesymbol)) != 'NaN') or (string(number(.)) != 'NaN'))">
       
<xsl:attribute name="text-align">right</xsl:attribute> <!--text alignment
        for numbers in cells-->
       
   
<!--specify right margin as a percentage of cell width (default: 30)-->
        
<xsl:attribute name="margin-right">
         
<xsl:choose>
           
<xsl:when test="self::d:entry/d:footnote"> <!--reduce the right margin if
            there is a footnote in the cell-->
             
<xsl:value-of select="$cellfootnoteindent"/>
           
</xsl:when>
           
<xsl:otherwise>
             
<xsl:value-of select="$cellnumberindent"/>
           
</xsl:otherwise>
         
</xsl:choose>
         
<xsl:text>%</xsl:text>
       
</xsl:attribute>     
      
</xsl:when>
     
<xsl:otherwise/>
   
</xsl:choose>
 
</xsl:template>



On 26-05-12 5:59 AM, Bob Stayton wrote:
One way to handle those characters is to use the translate() function to remove them before doing the test.  If the third argument of translate() is empty, then the matching characters in the second argument disappear, and all other characters are left untouched.  Something like:
 
string(number(translate(., '&lt;&gt;', '')))
 
 
Bob Stayton
Sagehill Enterprises
bobs@sagehill.net
 
 
----- Original Message -----
From: Xmplar
Sent: Thursday, May 24, 2012 7:38 PM
Subject: Re: [docbook-apps] Aligning numbers in table cells with xsl

I managed to (almost) fix the problem by adding a test for NaN to the string variable:

<xsl:if test="(ancestor-or-self::d:table/@tabstyle = 'numbers' or
      ancestor-or-self::d:table/@tabstyle = 'numberstripe') and not(ancestor::d:thead or
      ancestor::d:tfoot) and preceding-sibling::d:entry and (string(number(.) != 'NaN'))">

This however will not select any cells that have a number and a non-numeric string (such as greater than or less than signs: <1, or >20) - my test treats those cells as a string and not as a number. I now need to find how to convert &lt; and &gt; to a number so that the test selects cells with a number and a lt or gt sign.

On 24-05-12 4:24 PM, Bob Stayton wrote:
<xsl:if test="(ancestor-or-self::d:table/@tabstyle = 'numbers' or
      ancestor-or-self::d:table/@tabstyle = 'numberstripe') and not(ancestor::d:thead or
      ancestor::d:tfoot) and preceding-sibling::d:entry and string(number(.))">

--
Dave Gardiner
Xmplar
info@xmplar.biz
http://xmplar.biz
Mob. 0416 833 993

--
Dave Gardiner



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]