[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Using Javascript function in XSL causes HTML to be par

Subject: 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
xsl javascript function
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.