XSLT generated JavaScript not executed

My problem is the following:

I generate JavaScript Code in XSLT that should be excecuted in the IE (V. 6.0). I create a <select> box with some <option> in it. Instead of using <xsl:choose><xsl:when> repeatly I thought I just create a Function that get's called afterwards and sets the right option.

The XML:
<root>
<element>2</element>
<element>1</element>
</root>


The XSLT:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output version="1.0" encoding="utf-8" omit-xml-declaration="yes" media-type="text/html" />
<!-- main template -->
<xsl:template match="/">
<h2>This is the transformation</h2>
<script type="text/javascript">
function evalSelectedOption(objSel, optnValue) {
if(objSel != null) {
for(var i=0;i!=objSel.length;i++) {
if(objSel.options[\i].value == optnValue)
objSel.options[\i].selected=1;
}
}
alert(objSel.id);
alert("option with value of  "+optnValue+" set to 'selected'");
}
</script>
<xsl:choose>
<xsl:when test="/Root/element">
<xsl:for-each select="/Root/element">
<xsl:call-template name="templName" />
</xsl:for-each>
</xsl:when>
</xsl:choose>
</xsl:template>
<!-- template that gets called -->
<xsl:template name="templName">
<xsl:param name="id" select="generate-id()" />
<select id="{$id}" >
<option value="1">first option</option>
<option value="2">second option</option>
<option value="3">third option</option>
</select>
<script type="text/javascript">
evalSelectedOption(document.getElementById('<xsl:value-of select="$id"/>'),'<xsl:value-of select="."/>');
</script>
</xsl:template>
</xsl:stylesheet>



Now if you put the code in seperate files and link them together, for example using < xml-stylesheet type="text/xsl" href="nameOf.xsl" > in the .xml and call it in IE it works.

But I wan't to use Data-Islands since the XML and XSLT are generated serverside. So this is just an example of the concept I want to use.

Now if I load the documents in the DOM in JavaScript and do the transformation, the JavaScript that is generated by the XSLT-Processor won't be executed anymore.

Is this a bug or a feature *lol* Or maybe am I missusing something Its working in Firefox.

I can post the JavaScript also if it would help!

Greetins
Spanky

EDIT: The example works, you just need to cut the backslashes before the i in ..options[\i].. There was a light displayed leaving it as is.


Answer this question

XSLT generated JavaScript not executed