[xsl] Using Javascript function in XSL causes HTML to be parsed into normal text

Subject: [xsl] Using Javascript function in XSL causes HTML to be parsed into normal text
From: "Nik Coughlin" <nrkn@xxxxxxxxxxx>
Date: Mon, 10 Nov 2003 13:19:41 +1300
I have an XSL file that uses some JavaScript to set an InnerHTML tag
with the contents of an XML element when a link is clicked.

Previously, I used the following structure within the <body> of the
<html>, when setting up the links themselves:

<xsl:for-each select="site/main-body/section">
<xsl:variable name="content" select="content" />
...
<a href="#" style="text-decoration:none"
onclick="tblBody.innerHTML='{normalize-space($content)}'">
<xsl:value-of select="caption" />                                 </a>
...
</xsl:for-each>

Which worked perfectly.  tblBody would display the HTML contained in
the XML element content, as expected.  

However, for a number of reasons, I wanted to make onclick call a
function instead of directly setting the innerHTML.  So I changed it
to this:

<a href="#" style="text-decoration:none"
onclick="SetTblBody({position()})">

The function is contained in the <head> of my <html> as follows:

<script language="javascript" type="text/javascript">
function SetTblBody(IDNo){
  switch (IDNo){
    <xsl:for-each select="site/main-body/section">
    <xsl:variable name="content" select="content" />
    case <xsl:value-of select="position()" />:
    document.getElementById("tblBody").innerHTML='<xsl:value-of
select="normalize-space($content)" />'
    break;</xsl:for-each>
  }
}       
</script>

Which also works fine, except, the JavaScript function is output like
this by the XSL:

          function SetTblBody(IDNo)
          {
            switch (IDNo) {
            
                case 1:
                document.getElementById("tblBody").innerHTML='&lt;cent
er&gt; Some text.&lt;br /&gt; Some more text.&lt;br /&gt; &lt;br
/&gt; ^^^ A blank line. &lt;/center&gt;'
                break;
                case 2:
                document.getElementById("tblBody").innerHTML='http://a
.url.goes.here/'
                break;
                case 3:
                document.getElementById("tblBody").innerHTML='Content
goes here'
                break;
                case 4:
                document.getElementById("tblBody").innerHTML='Content
goes here'
                break;
                case 5:
                document.getElementById("tblBody").innerHTML='Content
goes here'
                break;
            }
          }       

At what point is the XSL parsing the contents of <content> and
replacing all of the < and > symbols in the HTML as lt; and gt;
symbols?  How do I stop it from doing this?  Why is it doing it in
the function when it didn't do it in the onclick?


-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
                nrkn
http://www.livejournal.com/users/nrkn
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread