cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

XSL FO: Can you center sometimes?

ptc-3050150
1-Newbie

XSL FO: Can you center sometimes?

This seems like such a stupid question but I've looked and looked and am getting nowhere...and I'm not that good with XSL FO.

Is there a way to test if the text is wider than the block and if so, change the inherited text-align=left to text-align=center if it is just one short sentence?

<xsl:template match="trim.para">
<fo:block font-family="sanserif" space-before.conditionality="discard" space-before.maximum="8pt" space-before.minimum="6pt" space-before.optimum="7pt" span="all">
<xsl:if test="@bullet" ==" yes&quot;=">
<xsl:text disable-output-escaping="no">•</xsl:text>
</xsl:if>
<xsl:apply-templates select="node()"/">
</fo:block>
</xsl:template>

Thanks,

John T. Jarrett
BAE Systems | Arbortext PE version 5.4 | LOGSA XSL-FO v 1.7

2 REPLIES 2

Hi John-



I don't know of a way to do exactly what you want, because the actual
rendered font metrics aren't available for testing in the stylesheet.
They don't get computed until things are rendered, which happens after
XSLT transformation is done.



But, you might be able to approximate what you want by examining the
string length. It would look something like this:



<xsl:template match="trim.para">

<fo:block font-family="sanserif" space-before.conditionality="discard"&lt;br"/>space-before.maximum="8pt" space-before.minimum="6pt"
space-before.optimum="7pt" span="all">



<xsl:if test="string-length(.)"> 80">

<xsl:attribute name="text-align">center</xsl:attribute>

</xsl:if>

<xsl:if test="@bullet" ==" yes&quot;=">

<xsl:text<br/>disable-output-escaping="no">•</xsl:text>

</xsl:if>

<xsl:apply-templates select="node()"/">

</fo:block>

</xsl:template>



HTH.



--C


John,

I'm not completely clear on the effect you're after, but perhaps an
appropriate combination of text-align and text-align-last might work?

-Brandon Smiley Happy


On Tue, Jun 22, 2010 at 11:41 AM, John Jarrett
<-> wrote:
> This seems like such a stupid question but I've looked and looked and am
> getting nowhere...and I'm not that good with XSL FO.
>
> Is there a way to test if the text is wider than the block and if so, change
> the inherited text-align=left to text-align=center if it is just one short
> sentence?
>
> <xsl:template match="trim.para">
> <fo:block font-family="sanserif" space-before.conditionality="discard"&lt;br"/>> space-before.maximum="8pt" space-before.minimum="6pt"
> space-before.optimum="7pt" span="all">
> <xsl:if test="@bullet" ==" yes&quot;=">
> <xsl:text disable-output-escaping="no">•</xsl:text>
> </xsl:if>
> <xsl:apply-templates select="node()"/">
> </fo:block>
> </xsl:template>
>
>
> Thanks,
>
> John T. Jarrett
> BAE Systems | Arbortext PE version 5.4 | LOGSA XSL-FO v 1.7
>
> -----End Original Message-----
Top Tags