Solved

xml/xsl/javascript: problem calling javascript function with onclick in xsl

Posted on 2004-09-01
9
891 Views
Last Modified: 2012-05-05
Hi, does anybody see the error here..? IE says 'object expected...'
The function 'a' is defined on row 8 and called by onclick on row 22. If I replace 'onclick="a()"' with 'onclick="alert()"', it works. And if I write the same function definition and call it the same way in an ordinary html-file it works just fine.
 
 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
 <xsl:template match="header">
 
 <html>
    <head>
    <script language="javascript"> function a(b) {alert();} </script>
    <title><xsl:value-of select="child::title"/></title>
    </head>
    <body>
       <xsl:apply-templates select="artists"/>
    </body>
 </html>
 </xsl:template>
 
 <xsl:template match="artists">
    <xsl:apply-templates/>
 </xsl:template>
 
 <xsl:template match="artist">
       <div id="{child::name}"><img src="plus_2.gif" height="8" width="8" border="1" onclick="a(2)"></img><xsl:value-of select="child::name"/>
    <xsl:apply-templates select="album"/></div>
 </xsl:template>
 
 <xsl:template match="album">
    <div id="{child::albumtitle}">...<xsl:value-of select="child::albumtitle"/>
    <xsl:for-each select="child::song">    
       <div id="{id}">......<xsl:value-of select="title"/></div>
    </xsl:for-each>  </div>    
 </xsl:template>
 
 </xsl:stylesheet>
 
   

 
0
Comment
Question by:kungkalle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 11950152
Should:

    <script language="javascript"> function a(b) {alert();} </script>

be:

    <script language="javascript"> function a(b) {alert(b);} </script>
0
 
LVL 4

Expert Comment

by:chipple
ID: 11950201
Works fine here.
What's the resulting HTML? What engine are you using to process XSLT? (I tested with MSXML.)

Just a guess, but one of the following may fix your problem. Here all work the same.

<script language="javascript"><xsl:text> function a(b) {alert();} </xsl:text></script>

or

<script language="javascript"><![CDATA[ function a(b) {alert();} ]]></script>

Good luck!
0
 

Author Comment

by:kungkalle
ID: 11950210
To TimYates

No, I've already tried that and it doesn't work. The function 'a(t)' is not the one I'm planning to use, it's just the simplest possible to try to find out what's wrong with the function call.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:kungkalle
ID: 11950275
To chipple

How do I find out what engine I'm using. Perhaps I forgot to mention it but I'm very new to xml/xsl... This is kind of my first test page.

The two alternatives you suggested did not work.

Thanks
0
 

Author Comment

by:kungkalle
ID: 11950304
For sake of clarity, this is the xml-file I'm using and how I use it together with the xsl-file


<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="mp3.xsl"?>
<mp3files>
      <title>Testa xml-xsl</title>
<artists>
      <artist>
            <name id="art_1">Artist 1</name>
            <album>
                  <albumtitle>Album 1</albumtitle>
                  <song>
                        <title>Song 1</title>
                        <id>Artist 1\Album 1\Song 1</id>
                  </song>

                  <song>
                        <title>Song 2</title>
                        <id>Artist 1\Album 1\Song 2</id>
                  </song>            
            </album>
            <album>
                  <albumtitle>Album 2</albumtitle>
                  <song>
                        <title>Song 1</title>
                        <id>Artist 1\Album 2\Song 1</id>
                  </song>

                  <song>
                        <title>Song 2</title>
                        <id>Artist 1\Album 2\Song 2</id>
                  </song>            
            </album>
      </artist>
</artists>
</mp3files>
0
 
LVL 4

Expert Comment

by:chipple
ID: 11950324
How are you viewing the result? Are you accessing your XML file directly in a Web browser? Or do you have server script doing the XML+XSLT=HTML conversion?
0
 

Author Comment

by:kungkalle
ID: 11950330
I view it directly in a web browser
0
 
LVL 4

Accepted Solution

by:
chipple earned 125 total points
ID: 11950345
Your XML helped indeed. Changing
<xsl:template match="header">
to
<xsl:template match="mp3files">
should help.
0
 

Author Comment

by:kungkalle
ID: 11951136
Rewrote both xml and xsl file and then all of a sudden it worked. Have no idea why... Chipple gets the points for trying though.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question