XSL Transformations in Mozilla FAQ

  • Revision slug: XSL_Transformations_in_Mozilla_FAQ
  • Revision title: XSL Transformations in Mozilla FAQ
  • Revision id: 75871
  • Created:
  • Creator: Sevenspade
  • Is current revision? No
  • Comment fix deki conversion mangling; no wording changes

Revision Content

Why isn't my stylesheet applied?

Make sure the mime type for both source and stylesheet are set to an XML mimetype, namely text/xml or application/xml. The XSLT namespace is http://www.w3.org/1999/XSL/Transform. Use the <?xml-stylesheet ?> processing instruction instead of the non-standard xml:stylesheet. The most common cause is the mime type handling. To find out which MIME type your server sends, look at Page Info, use extensions like LiveHTTPHeaders or a download manager like wget. Mozilla won't load XSLT stylesheets from a different domain for security reasons.

Note that Firefox will override your XSLT stylesheet if your XML is detected as an RSS or Atom feed. A known workaround is to add a sufficiently long XML comment to the beginning of your XML file in order to "push" the <feed or <rss tag out of the first 512 bytes, which is analyzed by Firefox to determine if it's a feed or not. See the discussion on bug #338621 for more information.

It works in IE, but not in Mozilla?

There are even more differences. Most come from what we suspect IE to do after the transformation. It (AFAICT) serializes and parses the output to generate what it actually renders. Mozilla in contrast renders exactly the result of your transformation.

Can I do disable-output-escaping?

This is actually pretty close to the question above. And in short, no. Disabling output escaping requires us to add a parsing step to our output generation, which we don't. In most cases, there are pretty easy workarounds. The only use cases we have seen are bad XML or bad XSLT. And RSS feeds. The latter is pretty much the only issue to us, and we're sorry that we can't support it. But mixing parsing with XSLT is brittle and we rather not support d-o-e than either crash or be even slower.

What about document.write?

Just like for XHTML, document.write is not supported during XSLT transformations. Sadly, current builds don't error, but just give unexpected results, like crashes ({{ Bug("202765") }}). In most cases, there is no need to actually use it, though. If you need platform dependent code or stylesheets, just do

      <xsl:if test="system-property('xsl:vendor')='Transformiix'">
        <!-- Mozilla specific markup -->
      </xsl:if>
      <xsl:if test="system-property('xsl:vendor')='Microsoft'">
        <!-- IE specific markup -->
      </xsl:if>

Check system-properties.xml for the properties of your favorite system. MSXML has an additional property.

      <xsl:if xmlns:msxsl="urn:schemas-microsoft-com:xslt"
              test="system-property('msxsl:version')=3">
        <!-- MSXML3 specific markup -->
      </xsl:if>

What about media="print"?

When printing a document, Mozilla tries to render the page on paper as closely to what you see as possible. This includes stuff like text entered into textfields and other dynamic changes. This is achieved by printing the current DOM tree. Having XSLT stylesheet specific to particular media would require to retransform the original XML source, which counteracts the expectations of the user. Thus, using media in <?xml-stylesheet ?> is strongly discouraged. Future builds might only load an XSLT stylesheet if media is not specified, or if the specified media include screen.
This does not affect CSS stylesheets loaded from the generated DOM, those honor media just like in pages without XSLT.

How do I do transformNode?

There is transformToDocument and transformToFragment starting with Mozilla 1.2 final, see Using the Mozilla JavaScript interface to XSL Transformations.

Why does Internet Explorer require a different XSLT namespace than Mozilla?

IE up to version 6 required a deprecated namespace of a XSLT working draft, please update to Mozilla ;-), IE6+ or MSXML3+, as it is fixed there. As the differences between XSLT1.0 and the IE implementation of that WD are significant, we offer no legacy support.

How do I build the standalone version of TransforMiiX?

See the Building TransforMiiX standalone page.

Original Document Information

  • Author(s): Axel Hecht
  • Last Updated Date: February 2, 2005
  • Copyright Information: Portions of this content are © 1998–2006 by individual mozilla.org contributors; content available under a Creative Commons license

{{ languages( { "fr": "fr/FAQ_sur_les_transformations_XSL_dans_Mozilla", "ja": "ja/XSL_Transformations_in_Mozilla_FAQ" } ) }}

Revision Source

<h2 name="Why_isn.27t_my_stylesheet_applied.3F">Why isn't my stylesheet applied?</h2>
<p>Make sure the mime type for both source and stylesheet are set to an XML mimetype, namely <code>text/xml</code> or <code>application/xml</code>. The XSLT namespace is <code><span class="nowiki">http://www.w3.org/1999/XSL/Transform</span></code>. Use the &lt;?xml-stylesheet ?&gt; processing instruction instead of the non-standard xml:stylesheet. The most common cause is the mime type handling. To find out which MIME type your server sends, look at Page Info, use extensions like <a class="external" href="http://livehttpheaders.mozdev.org/">LiveHTTPHeaders</a> or a download manager like wget. Mozilla won't load XSLT stylesheets from a different domain for security reasons.</p>
<p>Note that Firefox will override your XSLT stylesheet if your XML is detected as an RSS or Atom feed. A known workaround is to add a sufficiently long XML comment to the beginning of your XML file in order to "push" the &lt;feed or &lt;rss tag out of the first 512 bytes, which is analyzed by Firefox to determine if it's a feed or not. See the discussion on bug <a class="link-https" href="https://bugzilla.mozilla.org/show_bug.cgi?id=338621" title="https://bugzilla.mozilla.org/show_bug.cgi?id=338621">#338621</a> for more information.</p>
<h2 name="It_works_in_IE.2C_but_not_in_Mozilla.3F">It works in IE, but not in Mozilla?</h2>
<p>There are even more differences. Most come from what we suspect IE to do after the transformation. It (AFAICT) serializes and parses the output to generate what it actually renders. Mozilla in contrast renders exactly the result of your transformation.</p>
<h2 name="Can_I_do_disable-output-escaping.3F">Can I do disable-output-escaping?</h2>
<p>This is actually pretty close to the question above. And in short, no. Disabling output escaping requires us to add a parsing step to our output generation, which we don't. In most cases, there are pretty easy workarounds. The only use cases we have seen are bad XML or bad XSLT. And RSS feeds. The latter is pretty much the only issue to us, and we're sorry that we can't support it. But mixing parsing with XSLT is brittle and we rather not support d-o-e than either crash or be even slower.</p>
<h2 name="What_about_document.write.3F">What about <code>document.write</code>?</h2>
<p>Just like for XHTML, <code>document.write</code> is not supported during XSLT transformations. Sadly, current builds don't error, but just give unexpected results, like crashes ({{ Bug("202765") }}). In most cases, there is no need to actually use it, though. If you need platform dependent code or stylesheets, just do</p>
<pre>      &lt;xsl:if test="system-property('xsl:vendor')='Transformiix'"&gt;
        &lt;!-- Mozilla specific markup --&gt;
      &lt;/xsl:if&gt;
      &lt;xsl:if test="system-property('xsl:vendor')='Microsoft'"&gt;
        &lt;!-- IE specific markup --&gt;
      &lt;/xsl:if&gt;
</pre>
<p>Check system-properties.xml for the properties of your favorite system. MSXML has an additional property.</p>
<pre>      &lt;xsl:if xmlns:msxsl="urn:schemas-microsoft-com:xslt"
              test="system-property('msxsl:version')=3"&gt;
        &lt;!-- MSXML3 specific markup --&gt;
      &lt;/xsl:if&gt;
</pre>
<h2 name="What_about_media.3D.22print.22.3F">What about <code>media="print"</code>?</h2>
<p>When printing a document, Mozilla tries to render the page on paper as closely to what you see as possible. This includes stuff like text entered into textfields and other dynamic changes. This is achieved by printing the current DOM tree. Having XSLT stylesheet specific to particular <code>media</code> would require to retransform the original XML source, which counteracts the expectations of the user. Thus, using <code>media</code> in &lt;?xml-stylesheet ?&gt; is strongly discouraged. Future builds might only load an XSLT stylesheet if <code>media</code> is not specified, or if the specified <code>media</code> include <code>screen</code>.<br>
This does not affect CSS stylesheets loaded from the generated DOM, those honor media just like in pages without XSLT.</p>
<h2 name="How_do_I_do_transformNode.3F">How do I do <code>transformNode</code>?</h2>
<p>There is <code>transformToDocument</code> and <code>transformToFragment</code> starting with Mozilla 1.2 final, see <a href="/en/Using_the_Mozilla_JavaScript_interface_to_XSL_Transformations" title="en/Using_the_Mozilla_JavaScript_interface_to_XSL_Transformations">Using the Mozilla JavaScript interface to XSL Transformations</a>.</p>
<h2 name="Why_does_Internet_Explorer_require_a_different_XSLT_namespace_than_Mozilla.3F">Why does Internet Explorer require a different XSLT namespace than Mozilla?</h2>
<p>IE up to version 6 required a deprecated namespace of a XSLT working draft, please update to Mozilla ;-), IE6+ or MSXML3+, as it is fixed there. As the differences between XSLT1.0 and the IE implementation of that WD are significant, we offer no legacy support.</p>
<h2 name="How_do_I_build_the_standalone_version_of_TransforMiiX.3F">How do I build the standalone version of TransforMiiX?</h2>
<p>See the <a href="/en/Building_TransforMiiX_standalone" title="en/Building_TransforMiiX_standalone">Building TransforMiiX standalone</a> page.</p>
<div class="originaldocinfo">
<h2 name="Original_Document_Information">Original Document Information</h2>
<ul> <li>Author(s): Axel Hecht</li> <li>Last Updated Date: February 2, 2005</li> <li>Copyright Information: Portions of this content are © 1998–2006 by individual mozilla.org contributors; content available under a Creative Commons license</li>
</ul>
</div>
<p>{{ languages( { "fr": "fr/FAQ_sur_les_transformations_XSL_dans_Mozilla", "ja": "ja/XSL_Transformations_in_Mozilla_FAQ" } ) }}</p>
Revert to this revision