XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
morten norgaardSubject: pass xsl-variable to javascript onmouseover_ event
Author: morten norgaard
Date: 23 Sep 2006 05:22 PM
Hello, all,

well, I could use some help with this one. I've been trying to crack it for 2 days but it's no good. I need to pass the result of an xsl variable, whose value is the result of a call-template, to a javascript onmouseover_-event. I can print the result of the call-template call, but I simply cannot pass the resulting string to the javascript function. Try for yourselves, and move the mouse into the filename - the div on top of the filename should write the same text as the text just to the right of the filename, but I just won't... I'm at my wits end. Can anyone help...? :-(


I boiled everything down to the bare minimum:

the xml:

<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE parents []>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<parents>
<parent caption="parent1">
<child>
<childImageName>SCN0001.jpg</childImageName>
<childData>
<denominator name="testData">valueHere</denominator>
</childData>
</child>
</parent>
</parents>


... and the xsl, "test.xsl":


<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
<xsl:template match="/">

<html>
<head>
<script language="javascript">
<![CDATA[

function showNode( text )
{
document.getElementById("testDiv").innerHTML = text;
}
]]>

</script>
</head>

<body>
<div id="testDiv">here</div>
<xsl:apply-templates />
</body>
</html>

</xsl:template>
<xsl:template match="parent">
<xsl:apply-templates />
</xsl:template>

<xsl:template match="child">
<xsl:apply-templates select="childImageName"/>
</xsl:template>

<xsl:template match="childImageName">

<xsl:variable name="childDataVariable" select="../childData" />

<xsl:variable name="testVariable">
<xsl:call-template name="giveMeSomeChildDataTemplate">
<xsl:with-param name="nodEdit" select="$childDataVariable"></xsl:with-param>
</xsl:call-template>
</xsl:variable>


<span class="imageSpan">
<xsl:attribute name="onmouseover_">
showNode("<xsl:value-of select="testVariable"></xsl:value-of>")
</xsl:attribute>
<xsl:value-of select="text()"></xsl:value-of>
</span>


<xsl:value-of select="$testVariable"></xsl:value-of>
</xsl:template>


<xsl:template name="giveMeSomeChildDataTemplate">
<xsl:param name="nodEdit"/>
<xsl:for-each select="$nodEdit/denominator">caption: <xsl:value-of select="@name"></xsl:value-of> value:<xsl:value-of select="text()"></xsl:value-of></xsl:for-each>

</xsl:template>

</xsl:stylesheet>


Unknowntest(14).xml
test.xml

Unknowntest(14).xsl
test.xsl

Posttop
morten norgaardSubject: pass xsl-variable to javascript onmouseover__ event
Author: morten norgaard
Date: 25 Sep 2006 05:30 PM
God, my stupidity...

" showNode("<xsl:value-of select="testVariable"></xsl:value-of>")"

Should be

" showNode("<xsl:value-of select="$testVariable"></xsl:value-of>")

I forgot to put the dollar-sign in there with the "testVariable"...

Jesus. Hope this helps some one else, some time. Don't f*** up like I did, 's all I can say!

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.