Re: [xsl] How to prevent spaces in the output

Subject: Re: [xsl] How to prevent spaces in the output
From: Abel Braaksma <>
Date: Thu, 24 Jan 2008 22:10:57 +0100
Hi Mansour,

This is a FAQ. Use xsl:text when you want to output text. The reason that you see whitespace is because around the "=" sign, there's significant whitespace because you created mixed content. Using xsl:text you avoid this:


Of course, alternatively you can also remove the significant whitespace.

On a side note: your xsl:for-each is not necessary. If it is the only instruction in your template, you can remove it completely (it is redundant) while changing the template match to this:

<xsl:template match="something/@*">

If you left out some code and you do more in the template, you can also split it:

<xsl:template match="something">
    <xsl:apply-templates select="@*" />
    ... other things on "something"

<xsl:template match="something/@*">

HTH, Cheers, -- Abel Braaksma

Mansour wrote:
Hello every one:
I am facing some difficulties with the spaces in the resulting output. For example:

<xsl:template match="something" >
<xsl:for-each select="@*">
                           <xsl:value-of select="concat(' ',name(.))" />
                               select="concat('&quot;',.,'&quot;')" />

the output is : <formatting:ATTRIBUTENAME> attri </formatting:ATTRIBUTENAME> = <formatting:ATTRIBUTEVALUE> "value" </formatting:ATTRIBUTEVALUE>

Then when I convert it to html, there are spaces like this: attri = "value"

How do I avoid this ??

Current Thread