I'm having trouble with XSL and javascript (using IE6). I have some external scripts which include objects and functions. I have an XSL that needs to use these scripts. I try to include the scripts but it simply won't work.
Here's a sample I built and have tested, ensuring it shows the same error.
//test.js
function TestObject(Name, Foo)
{
this.name = Name;
this.foo = Foo;
}
//test.xsl
<?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>
<head>
<script language="javascript" src="test.js"></script>
<script language="javascript" type="text/javascript">
Test = new Array;
Test.push(new TestObject("Test", "Test"));
</script>
</head>
<body>
<script type="text/javascript">
for(i=0; i<Test.length; ++i)
{
document.write(Test.name);
}
</script>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
As it stands, it complains "TestObject is undefined".
Now if I, by hand, make this into an html file:
<html>
<head>
<script language="javascript" src="test.js"></script>
<script language="javascript" type="text/javascript">
Test = new Array;
Test.push(new TestObject("Test", "Test"));
</script>
</head>
<body>
<script type="text/javascript">
for(i=0; i<Test.length; ++i)
{
document.write(Test.name);
}
</script>
</body>
</html>
It works perfectly fine, no complaints.
If I don't use the external 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>
<head>
<script language="javascript" type="text/javascript">
function TestObject(Name, Foo)
{
this.name = Name;
this.foo = Foo;
}
Test = new Array;
Test.push(new TestObject("Test", "Test"));
</script>
</head>
<body>
<script type="text/javascript">
for(i=0; i<Test.length; ++i)
{
document.write(Test.name);
}
</script>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
it also works fine.
Unfortunately, turning into an HTML by hand defeats the purpose of an XML file (which isn't used in this example, even though it's provided. It
is used where I actually need it). As well, moving the objects into the XSL files themselves defeats the purpose of an external JS file.
Why can't I use both? How can I get around it?
----Erzengel des Lichtes光の大天使Archangel of LightEverything has a use. You must know that use, and when to properly use the effects.♀≈♂?