Search

I have been looking into indenting, although in a previous tread its mentioned all is good and golden, just use mode xml and indent yes, I wanted to note here that libxslt is very limited in its indenting;

xslt:

<ul>
  <li>1
    <ul>
      <li>1.1</li>
      <li>1.2
        <ul>
          <li>1.2.1</li>
          <li>1.2.2</li>
        </ul>
      </li>
    </ul>
  </li>
  <li>2</li>
</ul>

<ul>
  <li>
    <ul>
      <li></li>
      <li>
        <ul>
          <li></li>
          <li></li>
        </ul>
      </li>
    </ul>
  </li>
  <li></li>
</ul>

output

    <ul>
      <li>1
<ul><li>1.1</li><li>1.2
    <ul><li>1.2.1</li><li>1.2.2</li></ul></li></ul></li>
      <li>2</li>
    </ul>


    <ul>
      <li>
        <ul>
          <li></li>
          <li>
            <ul>
              <li></li>
              <li></li>
            </ul>
          </li>
        </ul>
      </li>
      <li></li>
    </ul>

this is because libxslt cant add a whitespace next to a text (so cant indent mixed content whitepace and none whotespace text, so it cant indent html basically)

The only way of getting ‘tidy’ indention all the way woudl be to use an apche tidy module to clean it up or use passing a parameter down to each template before, the indent level, and processing content to put that string in front of each line of text in the content but it’s a pain…

Try enclosing all of your text in <xsl:text> tags. Unusual indenting is caused when the parser sees text outside of <xsl:text> tags.

You mean any text not in a tag? Its ok to have <h3>Contact Me</h3> right?

I wanted to do that for loosing exes blank lines from my xslt in my output, but in my case it didn’t help for indenting

Yes, not in a tag. <xsl:text> is good if you want your source to be spanned across multiple lines but the output should be handled according to the indendation settings.

In other words, when the parser sees text, it will output exactly as seen in the source. Using <xsl:text> will allow to control what should be output.

i get blank entries here btw…

    <ul>
    <li><xsl:text>b</xsl:text>
        <ul>
            <li><xsl:text>b</xsl:text></li>
            <li><xsl:text>b</xsl:text>
                <ul>
                    <li><xsl:text>b</xsl:text></li>
                    <li><xsl:text>b</xsl:text></li>
                </ul>
            </li>
        </ul>
    </li>
    <li><xsl:text>b</xsl:text></li>
    </ul>

in my xslt, and no other code (except html heder body…) gives me exactly the same output as posted above; no result wahtsover.
This is on macports apache lamp. and a default install

someone in th eknow over at irc xml says that libxslt -what we are all using for life installs- will NOT indent when using this trick.

I am amazed that not more symphonains have run into this. Do we all use xhtml with such undeep levels of div nesting?… (in a more complex example the indent works up to the 5th level, and after that it doesnt, no ide why in thi sexample it already stops after the first ul…)

Hmm.. You might have already alluded to this, but it seems to only indent lists one level deep. I tried with this:

<ul>
    <li><xsl:text>a</xsl:text><ul>
            <li><xsl:text>b</xsl:text></li>
            <li><xsl:text>b</xsl:text></li>
    </ul></li>
    <li><xsl:text>a</xsl:text></li>
    <li><xsl:text>a</xsl:text></li>
</ul>

Only the top-level list items are indented properly. The same problem arises when I replace all the ul and li tags with divs.

I never found this to be a showstopping problem, it does make debugging a little more difficult though.

yes but its generally known that symphonians are perfectionists right…so want nice sourcecode….on the oher hand even unindented unspaced sourcecode is fine (even a bit fatser maybe)
who will be lookign at it anyway? fellow develoeprs? they use firebug to watch and debug…. does the debuf extension for FF also offer indented result view when the source is unindented?

Well, there are some “indentation limitations” in LibXSLT. I see these in most of my projects. But, compared to the output of any other templating engine, it looks rather close to perfect.

You could try turning indenting off and let Marc Liyanage’s XML Prettyprinter XSL template do the formatting: http://www.entropy.ch/software/xsl/welcome.html

@ bauhause would that be able in a life lamp setup?

I’ve only tested it with Marc’s Mac app, TestXSLT, but I can’t see why it wouldn’t work on a live setup.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details