XSLTProcessor.transformToFragment seems to use only output method "text"

RESOLVED FIXED in mozilla1.9beta4

Status

()

Core
XSLT
P4
normal
RESOLVED FIXED
12 years ago
11 years ago

People

(Reporter: C1, Assigned: peterv)

Tracking

Trunk
mozilla1.9beta4
x86
Windows XP
Points:
---
Bug Flags:
in-testsuite ?

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(2 attachments)

(Reporter)

Description

12 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7

In the small program I add here it happens all the time. In my major project (which i cannot attach here) it seems to happen only when the document passed to the transformToFragment has a hash in its url (local anchor) but I am not sure.

In this example I tried 3 different versions of translating, but none was helpful


Reproducible: Always

Steps to Reproduce:
Please see attached files for example.

html.html
==========

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<title>XSLT Bug test</title>
		<script type="text/javascript" defer="defer" src="./js.js"></script>
	</head>
	<body onload="javascript: go(); ">
		<a name="top"></a>
		<p>Hello</p>
		<div id="idTarget">
		</div>
		<p>Bye</p>
	</body>
</html>


xml.xml 
========

<?xml version="1.0" ?>
<root>
	<mylist>
		<item>Why</item>
		<item>this</item>
		<item>is</item>
		<item>not</item>
		<item>translated</item>
		<item>into</item>
		<item>an</item>
		<item>UL</item>
		<item>list?</item>
	</mylist>
</root>

xsl.xsl
========
<?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="/">
		<ul>
			<xsl:for-each select="/root/mylist/item">
				<li>
					<xsl:value-of select="." />
				</li>
			</xsl:for-each>
		</ul>
	</xsl:template>

</xsl:stylesheet>

js.js
======

function go()
{
	//// load the stylesheet
	var reqXsl = new XMLHttpRequest();
	reqXsl.open("GET", "./xsl.xsl", false);
	reqXsl.overrideMimeType('text/xml');
	reqXsl.send(null);

	//// load the data
	var reqXml = new XMLHttpRequest();
	reqXml.open("GET", "./xml.xml", false);
	reqXml.overrideMimeType('text/xml');
	reqXml.send(null);

	var xsltProcessor = new XSLTProcessor();
	xsltProcessor.importStylesheet( reqXsl.responseXML.documentElement );

	var where= document.getElementById("idTarget");

	//// none of these 3 options works
	var transmode= 1;
	if (transmode == 1)
	{
		//// Option 1 - Fails: transform like text
		var nodeFragment= xsltProcessor.transformToFragment( reqXml.responseXML.documentElement, document );
		where.appendChild(nodeFragment);
	}
	else if (transmode == 2)
	{
		//// Option 2 - Fails: transform like text
		var docTemp = document.implementation.createDocument("", "", null);
		var nodeFragment= xsltProcessor.transformToFragment( reqXml.responseXML.documentElement, docTemp );
		var nodeInOurDoc= document.importNode(nodeFragment, true);
		where.appendChild(nodeInOurDoc);				
	}
	else if (transmode == 3)
	{
		//// Option 3 - Fails: translated-document has no documentElement
		var docTemp = xsltProcessor.transformToDocument( reqXml.responseXML.documentElement );
		if ( docTemp.documentElement )
		{
			var nodeInOurDoc= document.importNode(docTemp.documentElement, true);
			where.appendChild(nodeInOurDoc);
		}
		else
		{
			alert('no documentElement');
		}
	}
	document.body.appendChild( document.createTextNode( transmode ) );
}


Actual Results:  
the translation ignores all html-tags, and only text is output. When I look in the DOM inspector for the fragment I get only one node of #text (containing unformatted text from all expected nodes) instead the expected tree (in the example a UL node with many LI nodes).
(Assignee)

Updated

12 years ago
Component: General → XSLT
Product: Firefox → Core
Version: unspecified → Trunk
(Assignee)

Comment 1

12 years ago
Pass reqXml.responseXML instead of reqXml.responseXML.documentElement as the node to transform.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 12 years ago
Resolution: --- → INVALID
(Reporter)

Comment 2

12 years ago
ok, you're right, please lets try the following code-

===== html2.html start =====
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<title>XSLT Bug test (#2)</title>
		<script type="text/javascript" defer="defer"><!--
		function doInnerHtml (where, strXhtml)
		{
			var parserData= new DOMParser ();
			var docSource= parserData.parseFromString( strXhtml, "application/xml" );

			var transformAlmostIdentity= '	\
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">	\
<xsl:output method="html" />	\
<xsl:template match="node()|@*"><xsl:copy><xsl:apply-templates select="node()|@*" /></xsl:copy></xsl:template>	\
</xsl:stylesheet>	\
';

			var parserStyle= new DOMParser ();
			var docStyle= parserStyle.parseFromString( transformAlmostIdentity, "text/xml" );

			var xsltProcessor = new XSLTProcessor();
			xsltProcessor.importStylesheet( docStyle );

			var nodeResult= xsltProcessor.transformToFragment( docSource, document );

			where.appendChild(nodeResult);
		}

		function go()
		{
			var where= document.getElementById("idTarget");
			doInnerHtml(where, '<ul><li>Peace</li><li>Love</li></ul>');
		}
		//-->
		</script>
	</head>
	<body onload="javascript: go(); ">
		<a name="top"></a>
		<p>Hello</p>
		<div id="idTarget">
		</div>
		<p>Bye</p>
	</body>
</html>
===== html2.html end =====


When this page is called ( for example, http://.../html2.html ) it is shown as expected and the parser parse the xml well, but if the page is requested with a hash ( for example, http://.../html2.html#top ) the parser seems to use output-method of text only.
(make sure to clear the cache between calls)
Status: RESOLVED → UNCONFIRMED
Resolution: INVALID → ---
Assignee: nobody → xslt
QA Contact: general → keith
(Reporter)

Comment 3

12 years ago
Congratulations for FF 2.0, Unfortunately the problem still exists

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0
Please attach a minimal testcase so that we can actually test this rather than just try to figure out what's happening by looking at the source. It should be possible to create a testcase much smaller than your current example. Remember that the testcase doesn't have to do anything useful, just demonstrate the bug.
(Reporter)

Comment 5

11 years ago
Thank you. please see this example below, you can copy it to an HTML file and test it. 
On FF v2.0.0.10 the problem still persists.

=== Start HTML ===
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <title>XSLT Bug test (#2)</title>
        <script type="text/javascript" defer="defer"><!--
        function doInnerHtml (where, strXhtml)
        {
            var parserData= new DOMParser ();
            var docSource= parserData.parseFromString( strXhtml,
              "application/xml" );

            var transformAlmostIdentity= ' \
<xsl:stylesheet version="1.0" \
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> \
<xsl:output method="html" />  \
<xsl:template match="node()|@*"><xsl:copy><xsl:apply-templates \
  select="node()|@*" /></xsl:copy></xsl:template> \
</xsl:stylesheet>    \
';

            var parserStyle= new DOMParser ();
            var docStyle= parserStyle.parseFromString(
              transformAlmostIdentity, "text/xml" );

            var xsltProcessor = new XSLTProcessor();
            xsltProcessor.importStylesheet( docStyle );

            var nodeResult= xsltProcessor.transformToFragment(
              docSource, document );

            where.appendChild(nodeResult);
        }

        function go()
        {
            var where= document.getElementById("idTarget");
            doInnerHtml(where,
              '<ul><li>Peace</li><li>Love</li></ul>');
        }
        //-->
        </script>
    </head>
    <body onload="javascript: go(); ">
        <a name="top"></a>
        <p>Hello</p>
        <div id="idTarget">
        </div>
        <p>Bye</p>
    </body>
</html>
=== End HTML ===

Since the XSL is a simple identity transformation the expected output is a UL list, something like that:
Hello
* Peace
* Love
Bye

But when the page is loaded with a hash (for example http://.../test.html#top) the XSL ignores the tags and text is written unformatted:
Hello
PeaceLove
Bye
(Reporter)

Comment 6

11 years ago
Created attachment 290460 [details]
testcase

The XSLT ignores tags when the page is called with a hash (for example, http://.../html2.html#top )
(Reporter)

Comment 7

11 years ago
See the attachment here
https://bugzilla.mozilla.org/attachment.cgi?id=290460
and here
https://bugzilla.mozilla.org/attachment.cgi?id=290460#top
The XSLT behaves differently

Comment 8

11 years ago
I confirmed that this is still an issue in the latest Minefield release:

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9b4pre) Gecko/2008021304 Minefield/3.0b4pre

(Assignee)

Comment 9

11 years ago
Created attachment 304045 [details] [diff] [review]
v1

When compiling a stylesheet from a node we use the url of the node's ownerDocument as the url of the stylesheet, but we should clear the ref because a stylesheet with a ref means an embedded stylesheet.
Assignee: xslt → peterv
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Attachment #304045 - Flags: superreview?(jonas)
Attachment #304045 - Flags: review?(jonas)
Comment on attachment 304045 [details] [diff] [review]
v1

doh!
Attachment #304045 - Flags: superreview?(jonas)
Attachment #304045 - Flags: superreview+
Attachment #304045 - Flags: review?(jonas)
Attachment #304045 - Flags: review+
(Assignee)

Comment 11

11 years ago
Comment on attachment 304045 [details] [diff] [review]
v1

Low risk fix. Only affects XSLT transformations done from script.
Attachment #304045 - Flags: approval1.9?
Comment on attachment 304045 [details] [diff] [review]
v1

a=beltzner for 1.9
Attachment #304045 - Flags: approval1.9? → approval1.9+
(Assignee)

Updated

11 years ago
Duplicate of this bug: 212362
(Assignee)

Updated

11 years ago
Status: ASSIGNED → RESOLVED
Last Resolved: 12 years ago11 years ago
Flags: in-testsuite?
Priority: -- → P4
Resolution: --- → FIXED
Target Milestone: --- → mozilla1.9beta4
You need to log in before you can comment on or make changes to this bug.