Firefox 3. XSLT Processing Engine bug?
I stumbled upon really strange issue while researching unexpected behavior of existing web application under Firefox 3.
So, there are ultimately simplified steps to reproduce:
1. XML document:
<?xml version="1.0"?>
<items>
<item>
<id>1</id>
</item>
<item>
<id>2</id>
</item>
<item>
<id>3</id>
</item>
</items>
2. XSL stylesheet:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="item">
<tr id="{id}">
<td>
<xsl:value-of select="id" />
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
3. Load these XML and XSL documents to Document instances.
4. Transform this XML document using given XSL stylesheet with the following code:
var processor = new XSLTProcessor();
processor.importStylesheet(xsl);
var doc = processor.transformToDocument(xml);
In Firefox 2 we would get following document as a result of this utterly ordinary code:
<transformiix:result xmlns:transformiix="http://www.mozilla.org/TransforMiix">
<TR id="1">
<TD>1</TD>
</TR>
<TR id="2">
<TD>2</TD>
</TR>
<TR id="3">
<TD>3</TD>
</TR>
</transformiix:result>
Since we used transformToDocument and there is no root node in the resulting XML fragment then we have wrapping <transformiix:result /> document element node.
But, as I said, in Firefox 3 result differs. I got following document:
<transformiix:result xmlns:transformiix="http://www.mozilla.org/TransforMiix">
<transformiix:result>
<TR id="1">
<TD>1</TD>
</TR>
<TR id="2">
<TD>2</TD>
</TR>
</transformiix:result>
<TR id="3">
<TD>3</TD>
</TR>
</transformiix:result>
Do you see the difference? There is unexpected (at least to me) <transformiix:result /> element wrapping first two <tr /> elements in the resulting document.
And it gets event more interesting with an increase of the number of items in the original document. For example with four items we would get:
<transformiix:result xmlns:transformiix="http://www.mozilla.org/TransforMiix">
<transformiix:result>
<transformiix:result>
<TR id="1">
<TD>1</TD>
</TR>
<TR id="2">
<TD>2</TD>
</TR>
</transformiix:result>
<TR id="3">
<TD>3</TD>
</TR>
</transformiix:result>
<TR id="4">
<TD>4</TD>
</TR>
</transformiix:result>
And so on...
This behavior starts when the number of elements is equal to or grater than 3.
Any thoughts?