You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Daniel Schaedler <li...@daniel.schaedler.name> on 2007/02/21 17:37:21 UTC

spaces between calls to same template

Hi

I use the following template to generate my PDF:
***
   <xsl:template match="lettertext/styledtext">

   	<xsl:variable name="weight">
			<xsl:value-of select="weight" />
		</xsl:variable>
		<xsl:variable name="style">
			<xsl:value-of select="style" />
		</xsl:variable>
		<xsl:variable name="decoration">
			<xsl:value-of select="decoration" />
		</xsl:variable>
		
   	<xsl:choose>
   		<xsl:when test="newline='newline'">
   			<fo:block></fo:block>
   			<fo:inline font-weight="{$weight}" font-style="{$style}" 
text-decoration="{$decoration}">
   				<xsl:value-of select="text" />
   			</fo:inline>
   		</xsl:when>
   		<xsl:otherwise>
   			<fo:inline font-weight="{$weight}" font-style="{$style}" 
text-decoration="{$decoration}">
   				<xsl:value-of select="text" />
   			</fo:inline>
   		</xsl:otherwise>
   	</xsl:choose>
   </xsl:template>
***
It is called several times successively to build a formatted text. But 
it always inserts a space(" ") between two calls. How can I avoid this 
space?

I checked the Input. It's correct.

the template itself is called by
****
....
<fo:block space-before="1cm" font-family="{$font}">
   <xsl:apply-templates select="body/lettertext"/>
</fo:block>
...
****

Daniel

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: spaces between calls to same template

Posted by "J.Pietschmann" <j3...@yahoo.de>.
Daniel Schaedler wrote:
> I reduced the template to:
> ***
> <xsl:template match="lettertext/styledtext">
>  <xsl:value-of select="text" />
> </xsl:template>
> ***
> and I still get the spaces.
> I'm also sure that the input for the 'value-of' does not contain any 
> spaces.
> 
> When I change the template to:
> ***
> <xsl:template match="lettertext/styledtext">
>  <xsl:value-of select="text" />
>  <xsl:value-of select="text" />
> </xsl:template>
> ***
> Then I get every text doubled without a space between the doubletts - as 
> expected.
> 
> That's the reason why I believe it has something to do with the calling 
> of the template itself (?)
> quite strange - I don't understand it...

The usual reply is "there is probably an error in the part of the code
or input you didn't show". The most likely reason is that the space
somehow comes from the input. Note that you apply templates to
a lettertext element, while the template matches a styledtext element.
Unless you have another template matching lettertext elements, the
default template is invoked, which usually leads to whitespaces been
passed through by the default template matching text().

Either post the full input and style sheet, or continue the process of
further simplifying both the input and the *whole* style sheet by
yourself.

J.Pietschmann

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: spaces between calls to same template

Posted by Andreas L Delmelle <a_...@pandora.be>.
On Feb 22, 2007, at 10:14, Daniel Schaedler wrote:

Hi Daniel,

> Andreas L Delmelle wrote:
<snip />
>> Very quick way to check this is to try adding the following to  
>> your stylesheet:
>> <xsl:template match="text()" />
>
> You are absolutely right :-)
> I wasn't aware that linebreaks and spaces do matter in my XML.
> This solved my problems - thank you!!

Glad I could help.

Be warned though: my suggestion will only work if the stylesheet  
*never* relies on the built-in template rule for text() (which  
corresponds to using *only* xsl:value-of to output CDATA content from  
the source XML).

Just so you know where to look when text suddenly starts disappearing  
after my proposed change.


Cheers,

Andreas

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: spaces between calls to same template

Posted by Daniel Schaedler <li...@daniel.schaedler.name>.
Andreas L Delmelle wrote:
> On Feb 21, 2007, at 22:54, Daniel Schaedler wrote:
> 
> Hi,
> 
> The explanation is probably that you have no explicit matching template 
> for text() nodes (note: text(), not your text nodes). In the first case, 
> a linefeed or space in between two text-nodes in your source XML will 
> invoke the built-in template rule:
> 
> <xsl:template match="text()">
>   <xsl:value-of select="." />
> </xsl:template>
> 
> When using default/initial values for white-space-treatment, 
> white-space-collapse and linefeed-treatment, these will all be 
> normalized into space characters by FOP.
> 
> Very quick way to check this is to try adding the following to your 
> stylesheet:
> 
> <xsl:template match="text()" />
> 

You are absolutely right :-)
I wasn't aware that linebreaks and spaces do matter in my XML.
This solved my problems - thank you!!

Daniel

> HTH!
> 
> Cheers,
> 
> Andreas
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: spaces between calls to same template

Posted by Andreas L Delmelle <a_...@pandora.be>.
On Feb 21, 2007, at 22:54, Daniel Schaedler wrote:

Hi,

<snip />
> I reduced the template to:
> ***
> <xsl:template match="lettertext/styledtext">
>  <xsl:value-of select="text" />
> </xsl:template>
> ***
> and I still get the spaces.
> I'm also sure that the input for the 'value-of' does not contain  
> any spaces.
>
> When I change the template to:
> ***
> <xsl:template match="lettertext/styledtext">
>  <xsl:value-of select="text" />
>  <xsl:value-of select="text" />
> </xsl:template>
> ***
> Then I get every text doubled without a space between the doubletts  
> - as expected.
>
> That's the reason why I believe it has something to do with the  
> calling of the template itself (?)
> quite strange - I don't understand it...

The explanation is probably that you have no explicit matching  
template for text() nodes (note: text(), not your text nodes). In the  
first case, a linefeed or space in between two text-nodes in your  
source XML will invoke the built-in template rule:

<xsl:template match="text()">
   <xsl:value-of select="." />
</xsl:template>

When using default/initial values for white-space-treatment, white- 
space-collapse and linefeed-treatment, these will all be normalized  
into space characters by FOP.

Very quick way to check this is to try adding the following to your  
stylesheet:

<xsl:template match="text()" />


HTH!

Cheers,

Andreas

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: spaces between calls to same template

Posted by Daniel Schaedler <li...@daniel.schaedler.name>.
J.Pietschmann wrote:

> How do you know "it" inserts a space?
> I recommend to produce a FO file and inspect it, and if the source
> of the irritating space still isn't obvious, trim down both the input
> source or the style sheet a bit and repeat the process.

I reduced the template to:
***
<xsl:template match="lettertext/styledtext">
  <xsl:value-of select="text" />
</xsl:template>
***
and I still get the spaces.
I'm also sure that the input for the 'value-of' does not contain any spaces.

When I change the template to:
***
<xsl:template match="lettertext/styledtext">
  <xsl:value-of select="text" />
  <xsl:value-of select="text" />
</xsl:template>
***
Then I get every text doubled without a space between the doubletts - as 
expected.

That's the reason why I believe it has something to do with the calling 
of the template itself (?)
quite strange - I don't understand it...

Daniel

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: spaces between calls to same template

Posted by "J.Pietschmann" <j3...@yahoo.de>.
Daniel Schaedler wrote:
> I use the following template to generate my PDF:
[snip]
> It is called several times successively to build a formatted text. But 
> it always inserts a space(" ") between two calls. How can I avoid this 
> space?
> 
> I checked the Input. It's correct.

How do you know "it" inserts a space?
I recommend to produce a FO file and inspect it, and if the source
of the irritating space still isn't obvious, trim down both the input
source or the style sheet a bit and repeat the process.

J.Pietschmann

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org