Open
Bug 221640
Opened 22 years ago
Updated 3 years ago
Javascript in XSLT can't access style/layout information
Categories
(Core :: XSLT, defect)
Core
XSLT
Tracking
()
NEW
People
(Reporter: bugzilla, Assigned: peterv)
Details
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.5) Gecko/20030925
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.5) Gecko/20030925
<body onload="test()">
</body>
<script type="text/javascript">
//code works in ie6, but not in moz because document doesn't really exist yet
function test() {
//code works in both ie6 and moz here
}
</script>
Reproducible: Always
Steps to Reproduce:
XML FILE:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<test>
</test>
XSL FILE:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<center>
<h1 id="test">test</h1>
</center>
<script type="text/javascript">
window.alert(document.getElementById('test').offsetLeft);
</script>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
GENERATED HTML:
<html><body><center><h1 id="test">test</h1></center><script type="text/javascript">
window.alert(document.getElementById('test').offsetLeft);
</script></body></html>
Actual Results:
alerts 0
Expected Results:
alerts 8 (or 10 in IE6)
this XSL works in moz and IE
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body onload="test()">
<center>
<h1 id="test">test</h1>
</center>
<script type="text/javascript">
function test() {
window.alert(document.getElementById('test').offsetLeft);
}
</script>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
However, I believe that not using onload= should work as well in Mozilla. The
generated HTML works as expected if pasted into a .html file, so I would not
except it work work differently just because it is being generated from XML+XSL.
![]() |
||
Comment 1•22 years ago
|
||
Confirming. The basic issue here, of course, is that scripts run when the node
is inserted into the DOM that the XSLT processor is constructing, while
offsetLeft needs frames to be present... and those won't be around till the new
DOM is stuck into the document and a presshell is hooked up.
Status: UNCONFIRMED → NEW
Ever confirmed: true
OS: Windows 2000 → All
Hardware: PC → All
Hmm.. this is a very tricky one.
Boris: won't you run into this issue once you stop blocking the parser for
stylesheet loads?
In my mind the 'best' solution would be if we once a styleproperty is requested
started layout and made sure that all stylesheets were loaded. That would solve
boris potential problem too.
However this seems Real Hard (tm). So i'm not sure what to do with this.
Possibly if we could throw an exception if style is accessed before it's really
available. That might educate people to wait for onload.
![]() |
||
Comment 3•22 years ago
|
||
> won't you run into this issue once you stop blocking the parser
Probably, yes. I think I'll wait and see how big an issue it is before I make
things slower to deal with it, though.... Just starting layout on any script
will make the whole exercise pointless (since 99% of pages have a random script
tag in the head for no reason).
Note that this is not accessing style. It's accessing the layout model. The
problem is that the layout model has not been created yet.
updating summary since the javascrip does in fact execute when it's supposed to.
Summary: Javascript in XSL executes too soon → Javascript in XSLT can't access style/layout information
Updated•16 years ago
|
QA Contact: keith → xslt
Updated•3 years ago
|
Severity: normal → S3
You need to log in
before you can comment on or make changes to this bug.
Description
•