mozilla

Revision 75866 of XSL Transformations in Mozilla FAQ

  • Revision slug: XSL_Transformations_in_Mozilla_FAQ
  • Revision title: XSL Transformations in Mozilla FAQ
  • Revision id: 75866
  • Created:
  • Creator: Raymond wu
  • Is current revision? No
  • Comment /* It works in IE, but not in Mozilla? */
Tags: 

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.

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.
<select name="country">
<xsl:text disable-output-escaping="yes">&lt;option value="2"&gt;Taiwan&lt;/option&gt;</xsl:text>
<xsl:text disable-output-escaping="yes">&lt;option value="2"&gt;China&lt;/option&gt;</xsl:text>
<xsl:text disable-output-escaping="yes">&lt;option value="2"&gt;Japan&lt;/option&gt;</xsl:text>
<xsl:text disable-output-escaping="yes">&lt;option value="2"&gt;Hong Kong&lt;/option&gt;</xsl:text>
</select>

The output will be

<select>
&lt;option value="2"&gt;Taiwan&lt;/option&gt;
&lt;option value="2"&gt;China&lt;/option&gt;
&lt;option value="2"&gt;Japan&lt;/option&gt;
&lt;option value="2"&gt;Hong Kong&lt;/option&gt;
</select>

in Firefox. But I hope it is

<select>
<option value="2">Taiwan</option>
<option value="2">China</option>
<option value="2">Japan</option>
<option value="2">Hong Kong</option>
</select>

This template can work in IE, but not in Forefox.
What a bad feeling it is?
To make a HTML SELECT OPTIONS from XML document is too difficult.

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 ({{template.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
{{ wiki.languages( { "fr": "fr/FAQ_sur_les_transformations_XSL_dans_Mozilla" } ) }}

Revision Source

<p>
</p>
<h4 name="Why_isn.27t_my_stylesheet_applied.3F"> Why isn't my stylesheet applied? </h4>
<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="plain">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>
<h4 name="It_works_in_IE.2C_but_not_in_Mozilla.3F"> It works in IE, but not in Mozilla? </h4>
<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.
<br>
&lt;select name="country"&gt;<br>
&lt;xsl:text disable-output-escaping="yes"&gt;&amp;lt;option value="2"&amp;gt;Taiwan&amp;lt;/option&amp;gt;&lt;/xsl:text&gt;<br>
&lt;xsl:text disable-output-escaping="yes"&gt;&amp;lt;option value="2"&amp;gt;China&amp;lt;/option&amp;gt;&lt;/xsl:text&gt;<br>
&lt;xsl:text disable-output-escaping="yes"&gt;&amp;lt;option value="2"&amp;gt;Japan&amp;lt;/option&amp;gt;&lt;/xsl:text&gt;<br>
&lt;xsl:text disable-output-escaping="yes"&gt;&amp;lt;option value="2"&amp;gt;Hong Kong&amp;lt;/option&amp;gt;&lt;/xsl:text&gt;<br>
&lt;/select&gt;<br>
<br>
The output will be<br>
<br>
&lt;select&gt;<br>
&amp;lt;option value="2"&amp;gt;Taiwan&amp;lt;/option&amp;gt;<br>
&amp;lt;option value="2"&amp;gt;China&amp;lt;/option&amp;gt;<br>
&amp;lt;option value="2"&amp;gt;Japan&amp;lt;/option&amp;gt;<br>
&amp;lt;option value="2"&amp;gt;Hong Kong&amp;lt;/option&amp;gt;<br>
&lt;/select&gt;<br>
<br>
in Firefox. But I hope it is<br>
<br>
&lt;select&gt;<br>
&lt;option value="2"&gt;Taiwan&lt;/option&gt;<br>
&lt;option value="2"&gt;China&lt;/option&gt;<br>
&lt;option value="2"&gt;Japan&lt;/option&gt;<br>
&lt;option value="2"&gt;Hong Kong&lt;/option&gt;<br>
&lt;/select&gt;<br>
<br>
This template can work in IE, but not in Forefox.<br>
What a bad feeling it is?<br>
To make a HTML SELECT OPTIONS from XML document is too difficult.<br>
</p>
<h4 name="Can_I_do_disable-output-escaping.3F"> Can I do disable-output-escaping? </h4>
<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>
<h4 name="What_about_document.write.3F"> What about <code>document.write</code>? </h4>
<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 ({{template.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>
<h4 name="What_about_media.3D.22print.22.3F"> What about <code>media="print"</code>? </h4>
<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>
<h4 name="How_do_I_do_transformNode.3F"> How do I do <code>transformNode</code>? </h4>
<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">Using the Mozilla JavaScript interface to XSL Transformations</a>.
</p>
<h4 name="Why_does_Internet_Explorer_require_a_different_XSLT_namespace_than_Mozilla.3F"> Why does Internet Explorer require a different XSLT namespace than Mozilla? </h4>
<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>
<h4 name="How_do_I_build_the_standalone_version_of_TransforMiiX.3F"> How do I build the standalone version of TransforMiiX? </h4>
<p>See the <a href="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>
{{ wiki.languages( { "fr": "fr/FAQ_sur_les_transformations_XSL_dans_Mozilla" } ) }}
Revert to this revision