Open
Bug 631455
Opened 14 years ago
Updated 3 years ago
XSLT with default html namespace (xmlns="http://www.w3.org/1999/xhtml ") fails badly
Categories
(Firefox :: General, defect)
Firefox
General
Tracking
()
NEW
People
(Reporter: rick.brown, Unassigned)
Details
Attachments
(2 files)
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:2.0b10) Gecko/20100101 Firefox/4.0b10
Build Identifier: Mozilla/5.0 (Windows NT 5.1; rv:2.0b10) Gecko/20100101 Firefox/4.0b10
When performing client-side XSLT in Firefox the HTML result produced by the transform is not correctly interpreted as HTML by Firefox (which seems to think it is dealing with XML).
Executing the line "document.body.innerHTML = document.body.innerHTML" resolves the problem and Firefox renders the HTML correctly.
Removing the attribute 'xmlns="http://www.w3.org/1999/xhtml"' from the xsl:stylesheet element makes this issue go away.
Chrome 9 and IE8 do not have this problem.
Reproducible: Always
Steps to Reproduce:
1. Save the included XML and XSL into a directory where you can execute from your webserver.
2. Load the XML in Firefox.
XSL FILE:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://dummy.com/mynamespace"
version="1.0">
<xsl:output method="html"
doctype-public="XSLT-compat"
encoding="UTF-8"
indent="no"
omit-xml-declaration="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="ui:example">
<html>
<head>
<title>Example</title>
</head>
<body>
<form action=".">
<xsl:apply-templates/>
</form>
</body>
</html>
</xsl:template>
<xsl:template match="ui:table">
<xsl:variable name="id" select="@id"/>
<xsl:variable name="functionalClass">
<xsl:if test="ui:pagination">
<xsl:text> paginatedTable</xsl:text>
</xsl:if>
</xsl:variable>
<div id="{$id}">
<xsl:attribute name="class">
<xsl:text>table-wrapper</xsl:text>
</xsl:attribute>
<table>
<xsl:apply-templates select="ui:thead" mode="table"/>
<xsl:apply-templates select="ui:tbody" mode="table"/>
<xsl:call-template name="tfoot"/>
</table>
</div>
</xsl:template>
<xsl:template match="ui:pagination">
<xsl:variable name='tableId' select="../@id"/>
<xsl:variable name='name'>
<xsl:value-of select="concat($tableId, '.page')"/>
</xsl:variable>
<xsl:variable name='pages'>
<xsl:value-of select="ceiling(@rows div @rowsPerPage)"/>
</xsl:variable>
<xsl:if test="@rows > 0">
<xsl:element name="LABEL">
<xsl:attribute name="for">
<xsl:value-of select="$name"/>
</xsl:attribute>
<xsl:variable name="resultSuffix">
<xsl:if test="@rows != '1'">
<xsl:text>s</xsl:text>
</xsl:if>
</xsl:variable>
<xsl:value-of select="concat(@rows,' Result', $resultSuffix, ', page: ')"/>
</xsl:element>
<xsl:element name="SELECT">
<xsl:attribute name="id">
<xsl:value-of select="$name"/>
</xsl:attribute>
<xsl:attribute name="class">
<xsl:text>paginationList</xsl:text>
</xsl:attribute>
<xsl:attribute name="name">
<xsl:value-of select="$name"/>
</xsl:attribute>
<xsl:call-template name="pagination.option.for.loop">
<xsl:with-param name="i">0</xsl:with-param>
<xsl:with-param name="count"><xsl:value-of select="$pages"/></xsl:with-param>
<xsl:with-param name="current"><xsl:value-of select="@currentPage"/></xsl:with-param>
</xsl:call-template>
</xsl:element>
<xsl:variable name="buttonType">
<xsl:text>button</xsl:text>
</xsl:variable>
<xsl:call-template name="paginationButton">
<xsl:with-param name="title" select="'First page'"/>
<xsl:with-param name="type" select="$buttonType"/>
<xsl:with-param name="idSuffix" select="'1'"/>
</xsl:call-template>
<xsl:call-template name="paginationButton">
<xsl:with-param name="title" select="'Previous page'"/>
<xsl:with-param name="type" select="$buttonType"/>
<xsl:with-param name="idSuffix" select="'2'"/>
</xsl:call-template>
<xsl:call-template name="paginationButton">
<xsl:with-param name="title" select="'Next page'"/>
<xsl:with-param name="type" select="$buttonType"/>
<xsl:with-param name="idSuffix" select="'3'"/>
</xsl:call-template>
<xsl:call-template name="paginationButton">
<xsl:with-param name="title" select="'Last page'"/>
<xsl:with-param name="type" select="$buttonType"/>
<xsl:with-param name="idSuffix" select="'4'"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template match="ui:thead" mode="table">
<thead>
<tr>
<xsl:apply-templates mode="table"/>
</tr>
</thead>
</xsl:template>
<xsl:template match="ui:tbody" mode="table">
<tbody class="page">
<xsl:apply-templates mode="table" />
</tbody>
</xsl:template>
<xsl:template match="ui:tr" mode="table">
<tr>
<xsl:apply-templates mode="table"/>
</tr>
</xsl:template>
<xsl:template match="ui:th" mode="table">
<th>
<xsl:value-of select="."/>
</th>
</xsl:template>
<xsl:template match="ui:td" mode="table">
<td>
<xsl:value-of select="."/>
</td>
</xsl:template>
<xsl:template name="tfoot">
<xsl:variable name="hasPagination">
<xsl:choose>
<xsl:when test="ui:pagination">
<xsl:number value="1" />
</xsl:when>
<xsl:otherwise>
<xsl:number value="0" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name='hasFooterElements'>
<xsl:value-of select="$hasPagination"/>
</xsl:variable>
<xsl:if test="$hasFooterElements > 0">
<xsl:variable name="numCols">
<xsl:choose>
<xsl:when test="ui:thead/ui:th">
<xsl:value-of select="count(ui:thead/ui:th)"/>
</xsl:when>
<xsl:when test="ui:tbody/ui:tr[position()=1]/ui:td">
<xsl:value-of select="count(ui:tbody/ui:tr[position()=1]/ui:td)"/>
</xsl:when>
<xsl:otherwise>
<xsl:number value="1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="totalCols">
<xsl:value-of select="$numCols"/>
</xsl:variable>
<xsl:variable name='colSpan1'>
<xsl:value-of select="ceiling($totalCols div $hasFooterElements)"/>
</xsl:variable>
<xsl:variable name='colSpan2'>
<xsl:value-of select="$totalCols - $colSpan1"/>
</xsl:variable>
<tfoot>
<tr>
<xsl:if test="$hasPagination = 1">
<td>
<xsl:attribute name="colspan">
<xsl:value-of select="$colSpan2"/>
</xsl:attribute>
<xsl:apply-templates select="ui:pagination"/>
</td>
</xsl:if>
</tr>
</tfoot>
</xsl:if>
</xsl:template>
<xsl:template name="pagination.option.for.loop">
<xsl:param name="i" />
<xsl:param name="count" />
<xsl:param name="current" />
<xsl:if test="$i < $count">
<option value="{$i}">
<xsl:if test="$i = $current">
<xsl:attribute name="selected">selected</xsl:attribute>
</xsl:if>
<xsl:value-of select="$i + 1"/>
</option>
<xsl:call-template name="pagination.option.for.loop">
<xsl:with-param name="i">
<xsl:value-of select="$i + 1"/>
</xsl:with-param>
<xsl:with-param name="count">
<xsl:value-of select="$count"/>
</xsl:with-param>
<xsl:with-param name="current">
<xsl:value-of select="$current"/>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="paginationButton">
<xsl:param name="name"/>
<xsl:param name="title"/>
<xsl:param name="class"/>
<xsl:param name="value"/>
<xsl:param name="pages"/>
<xsl:param name="type"/>
<xsl:param name="idSuffix"/>
<xsl:element name="BUTTON">
<xsl:attribute name="id">
<xsl:value-of select="concat(../@id,'.pagination.',$idSuffix)"/>
</xsl:attribute>
<xsl:if test="$class">
<xsl:attribute name="class">
<xsl:value-of select="$class"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="$name">
<xsl:attribute name="name">
<xsl:value-of select="$name"/>
</xsl:attribute>
</xsl:if>
<xsl:attribute name="title">
<xsl:value-of select="$title"/>
</xsl:attribute>
<xsl:attribute name="type">
<xsl:value-of select="$type"/>
</xsl:attribute>
<span class="offscreen">
<xsl:value-of select="$title"/>
</span>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
XML FILE:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="table.xsl"?>
<ui:example
xmlns:ui="http://dummy.com/mynamespace"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:html="http://www.w3.org/1999/xhtml">
<ui:table id="table_1">
<ui:pagination rowsPerPage="5" rows="25" currentPage="2"/>
<ui:thead>
<ui:th>Heading 1</ui:th>
<ui:th>Heading 2</ui:th>
<ui:th>Heading 3</ui:th>
<ui:th>Heading 4</ui:th>
<ui:th>Heading 5</ui:th>
</ui:thead>
<ui:tbody>
<ui:tr rowIndex="1">
<ui:td>Cell 1_1</ui:td>
<ui:td>Cell 1_2</ui:td>
<ui:td>Cell 1_3</ui:td>
<ui:td>Cell 1_4</ui:td>
<ui:td>Cell 1_5</ui:td>
</ui:tr>
<ui:tr rowIndex="2">
<ui:td>Cell 2_1</ui:td>
<ui:td>Cell 2_2</ui:td>
<ui:td>Cell 2_3</ui:td>
<ui:td>Cell 2_4</ui:td>
<ui:td>Cell 2_5</ui:td>
</ui:tr>
<ui:tr rowIndex="3">
<ui:td>Cell 3_1</ui:td>
<ui:td>Cell 3_2</ui:td>
<ui:td>Cell 3_3</ui:td>
<ui:td>Cell 3_4</ui:td>
<ui:td>Cell 3_5</ui:td>
</ui:tr>
<ui:tr rowIndex="4">
<ui:td>Cell 4_1</ui:td>
<ui:td>Cell 4_2</ui:td>
<ui:td>Cell 4_3</ui:td>
<ui:td>Cell 4_4</ui:td>
<ui:td>Cell 4_5</ui:td>
</ui:tr>
<ui:tr rowIndex="5">
<ui:td>Cell 5_1</ui:td>
<ui:td>Cell 5_2</ui:td>
<ui:td>Cell 5_3</ui:td>
<ui:td>Cell 5_4</ui:td>
<ui:td>Cell 5_5</ui:td>
</ui:tr>
</ui:tbody>
</ui:table>
</ui:example>
Actual Results:
The page is not rendered correctly (note the buttons and select element are not interpreted as HTML form controls).
Expected Results:
The result of the XSLT should be interepreted as HTML.
For example, grab hold of the select element and inspect its namespaceURI with this line: document.getElementById("table_1.page").namespaceURI
You will see it is "http://www.w3.org/1999/xhtml" as it should be for HTML.
In Firebug or the address bar execute the line "document.body.innerHTML = document.body.innerHTML", now Firefox will render the page correctly.
Remove the line: xmlns="http://www.w3.org/1999/xhtml" from the XSL and it all works swimmingly.
save this file and table.xsl into the same directory then view this xml in firefox
Updated•14 years ago
|
Version: unspecified → Trunk
Comment 3•14 years ago
|
||
This does not work on Build identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13.
On Internet Explorer 8 works fine.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Updated•14 years ago
|
OS: Windows XP → All
Hardware: x86 → All
Comment 4•13 years ago
|
||
I have replicated this root cause for a similar simple example listed below.
XML:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="xslt.xsl"?>
<root><node></node></root>
XSLT - broken:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<xsl:output indent="no" omit-xml-declaration="yes" method="html" encoding="UTF-8" media-type="text/html" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"/>
<xsl:template match="/">
<html><head></head><body>
<table border="1">
<xsl:call-template name="row"/>
<xsl:call-template name="row"/>
<xsl:call-template name="row"/>
</table>
</body></html>
</xsl:template>
<xsl:template name="row">
<tr><td>row</td></tr>
</xsl:template>
</xsl:stylesheet>
XSLT - working:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="no" omit-xml-declaration="yes" method="html" encoding="UTF-8" media-type="text/html" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"/>
<xsl:template match="/">
<html><head></head><body>
<table border="1">
<xsl:call-template name="row"/>
<xsl:call-template name="row"/>
<xsl:call-template name="row"/>
</table>
</body></html>
</xsl:template>
<xsl:template name="row">
<tr><td>row</td></tr>
</xsl:template>
</xsl:stylesheet>
Updated•3 years ago
|
Severity: normal → S3
You need to log in
before you can comment on or make changes to this bug.
Description
•