Re: [xsl] Indentation question

Subject: Re: [xsl] Indentation question
From: knocte <knocte@xxxxxxxxx>
Date: Fri, 2 Sep 2005 11:29:50 +0200
2005/9/2, Joris Gillis <roac@xxxxxxxxxx>:
> Hi,
>
> Tempore 09:06:47, die 09/02/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx
scripsit knocte <knocte@xxxxxxxxx>:
>
> > Sometimes when I deal with XSLT, if I use this indent method:
> >
> > <xsl:output method="xml" indent="no" />
> >
> > Then I obtain all the results in one line, no EOL's.
> >
> > But I have found a case where this is not true, why?
>
> Because your xslt snippet contains non-whitespace-only text nodes with
line-breaks, which are copied in an unaffected matter (whitespaces preserved)
to the result tree.
>
> To avoid this, change
>
> >             <xsl:when test="LoginName">
> >               1
> >             </xsl:when>
>
> to
>
> <xsl:when test="LoginName">1</xsl:when>
>
> or to
>
> <xsl:when test="LoginName">
>         <xsl:text>1</xsl:text>
> </xsl:when>
>
>
> regards,
>

Thanks Joris. I have fixed some annoying whitespaces with this advice.
But now I have another related issue:

In HTML I have the advantage of writing a paragraph using EOL's and
don't worrying about the end view of the page because EOL's will be
converted to whitespaces.

Example:

  <p>
    This is a easy-to-edit paragraph because
    I can break it into multiple lines.
  <p>

The result in the browser will not contain any line-breaks.

Now, doesn't XSLT provide a "similar" way to edit paragraphs without
sending unnecessary line-breaks to the final result?

I mean, given this:

  <xsl:when test="whatever">
    <p>
      This is my paragraph which I want to break in multiple
      lines so as to edit it later more easily.
    </p>
  </xsl:when>

If I use this, I obtain the unnecessary blank spaces which are present
between the words "multiple" and "lines". If I use <xml:text> with the
whole paragraph I will obtain the same because I still use
line-breaks:

  <xsl:when test="whatever">
    <p>
      <xsl:text>
        This is my paragraph which I want to break in multiple
        lines so as to edit it later more easily.
      </xsl:text>
    </p>
  </xsl:when>

The unique solution I have is to use <xsl:text> for EVERY LINE. This
is not very comfortable to maintain and also I have to worry about
putting a final whitespace at the end of each line (except the last
one) so as not to concatenate incorrectly:

  <xsl:when test="whatever">
    <p>
      <xsl:text>This is my paragraph which I want to break in multiple
</xsl:text>
      <xsl:text>lines so as to edit it later more easily.</xsl:text>
    </p>
  </xsl:when>

Is there any better solution out there for this issue?

  Thanks,

    Andrew

--

Current Thread