Solved

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

Posted on 2004-09-01
9
847 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
  • 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
 

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now