I am creating an xsl-fo stylesheet for rtf. One of the problems I have is converting multiple units of measure in an xsl-fo document to twips (rtf unit).
One particular piece of code displays the width of the columns:
<xsl:value-of select="sum(preceding-sibling:
:fo:table-column/@column-width) + @column-width"/>
... the problem being the value /@column-widthcan be from 1in(1 inch) to 20px(20 pixels), so when I make the sum, it will not be executed.
I need to somehow convert @column-widthto twip equivelant:
1pt = 19.95 twips, 1px = 15 twips, 1pc = 240 twips, 1in = 1440 twips, 1cm = 567 twips, 1mm = 56.7 twips, 1em = 240 twips
Maybe I can write a method that can perform the conversion, but I am convinced that there is some way to use the function translate()to make it much more efficient.
Please note that my xsl is not so good, so an example of how to achieve this will be appreciated
EDIT
I managed to find something that I want, but have no idea how to call this template from the above calculation:
<xsl:template match="@*" mode="convert-to-twips">
<xsl:variable name="scaling-factor">
<xsl:choose>
<xsl:when test="contains (., 'pt')">19.95</xsl:when>
<xsl:when test="contains (., 'px')">15</xsl:when>
<xsl:when test="contains (., 'pc')">240</xsl:when>
<xsl:when test="contains (., 'in')">1440</xsl:when>
<xsl:when test="contains (., 'cm')">567</xsl:when>
<xsl:when test="contains (., 'mm')">56.7</xsl:when>
<xsl:when test="contains (., 'em')">240</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="numeric-value"
select="translate (., '-0123456789.ptxcinme', '-0123456789.')"/>
<xsl:value-of select="$numeric-value * $scaling-factor"/>
</xsl:template>