Search

Hi everyone!

I'm having some problems with self-closing tags. Here is my master.xsl: http://pastebin.com/dJ8XxuEt

In the browser, viewing the page source, the self-closing tags ( , ... ) aren't closed: http://pastebin.com/wUjwtXzW

I tried some tips I've found in other posts, with no success. Does anyone knows what's going on and how to solve it?

Thanks!

I tried some tips I've found in other posts, with no success

What did you try?

My first suggestion would be to change your output type to html.

<xsl:output method="html"...

Change the output was one of them... Changed to xml, html... but no solution. :(

Odd. If you definitely want self-closing then you should definitely be using xml, since self-closing is a requirement for XML:

<xsl:output method="xml"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
omit-xml-declaration="yes"
encoding="UTF-8"
indent="yes" />

Be sure that your pages themselves do not contain an xsl:output declaration as they will override the one set in your master.

What version of PHP and libxml/libxsl are you running? You can find that in the phpinfo() output.

@joaobarbosa - would you mind pinpointing which elements you want closed?

@nickdunn yes, I never thought about pages overwriting the master output... and now it's fine! Tags closed... But, using the XML output, special chars on this tags are replaced by codes, like this:

<meta name="description" content="Skazi & #xE9; uma confec& #xE7;& #xE3;o de moda feminina com showroom localizado no Prado, BH. Produz vestidos, blusas, saias, casacos, batas criando tend& #xEA;ncias na moda feminina." />

@bzerangue of course not... mainly, the link and meta tags, but others like img too!

Keep in mind that self closing tags can cause incorrect page rendering in multiple browsers, including IE and FireFox. It is fine for XML, but not recommended in HTML.

But perfectly acceptable in XHTML.

Yep. If you set the doctype-system correctly, the parser will output perfectly valid XHTML code.

Thanks for all of your answers! (:

Still on my last post, here goes my output:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml"
    doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
    omit-xml-declaration="yes"
    encoding="UTF-8"
    indent="yes" />

... self-closing tags are ok, but special chars are replaced.

If I use html as output mode, the special chars are ok, but self-closing not. There's a way to conciliate both?

I would suggest that you use the special character encoding in your source. Simply find the appropriate character code for your encoding and use &#{code}; syntax. This should create the correct output and is much safer than using the special characters in your source.

@remie

Didn't work to... I've replaced special characters with its entity number ( &#{code} ), but it's replaced too, like this:

"é" or "& #233" ( code )

"& #xE9;" ( output )

Can you try:

<xsl:output method="xml"
    doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    omit-xml-declaration="yes"
    encoding="UTF-8"
    indent="yes" />

<xsl:template match="/">
    <html><head><title>Test</title></head><body>
    <span>Test #&233;</span>
    </body>
</xsl:template>

This should output the correct special character and indenting.

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