Link to home
Start Free TrialLog in
Avatar of vmandem
vmandem

asked on

How to call javascript function inside my XSL

I have the below XSL part of code. How to call a javascript function to change the select value inside the  <xsl:value-of select="my javascript"> But I get error. The XSL is inside the webpart.

<a href="{$fieldvalue}"><xsl:value-of select="hithighlightedproperties/HHTitle/text()" />


<xsl:if test="$fieldtitle">: </xsl:if>
					<xsl:choose>
						<xsl:when test="$fieldtype='url'">
							<a href="{$fieldvalue}"><xsl:value-of select="hithighlightedproperties/HHTitle/text()" />
							</a>
						</xsl:when>
						<xsl:when test="$fieldtype='user'">
							<xsl:value-of select="$fieldvalue" disable-output-escaping="yes" />
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="hithighlightedproperties/HHTitle/text()" />
						</xsl:otherwise>
					</xsl:choose>

Open in new window

Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

The question is not clear enough
XSLT transforms XML into HTML (in this case)
1. Do you want the Javascript to execute during the XSLT processing? Then you are bound to use an XSLT processor that supports JavaScript extension functions... I believe you are limited to msxml then. Which processor do you use in that case?
There is more involved to doing that but simply calling the Javascript function, for instance you need an extension namespace for that
2. Do you want to insert javascript in the resulting html?
Then you can simply add the javascript as literal text. What usually goes wrong in that case is that you would forget to add some single quotes around the functions

So, please be more specific and clear now
Avatar of vmandem
vmandem

ASKER

It is a webpart that outputs searh results using xslt template. Basically I want to display my custom result using JavaScript for one of the columns. Is it possible while the webpart loads the data and call the JavaScript
function and modify that one column with my value. If not clear please let me know i can explain better
THis sounds very much like having a javascript in the resulting html
it helps if you try to get the javascript working in a static html
(just in order to devbug that)
After that you try to generate that html plus javascript using XSLT
Avatar of vmandem

ASKER

I'm sure it works under normal html with the javascript function. I would like an example of how that column can be embedded with in XSL and call the javascript function.
OK, then you have to be more clear on what exactly you want, because your original question is very unclear.
I would appreciate if you showed a snippet of the resulting HTML containing the JavaScript
and a relevant snippet of the source XML.
As it currently stands, I simply don't have enough context to give you a decent answer
Avatar of vmandem

ASKER

I have a javascript function inside a webpart like this

<script language="javascript">
function getscope()
{
var scope = 'Test1'
return scope
}
</scrip>
---NOW MY XSL STYLE SHEET CODE
<xsl:if test="not($hidedetail)" ddwrt:cf_ignore="1">
                                    <a href="javascript:" onclick="javascript:ExpGroupBy(this);return false;">
                                          <img src="{$imagesrc}" border="0" alt="{$alttext}" name="{$altname}" /></a>
                              </xsl:if>
                              <xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">&amp;nbsp;</xsl:text>
                              
                              <b>
                                    <xsl:value-of select="$fieldtitle" />
                              </b>
                              <xsl:if test="$fieldtitle">: </xsl:if>
                              <xsl:choose>
                                    <xsl:when test="$fieldtype='url'">
                                          <a href="{$fieldvalue}"><xsl:value-of select="I WANT TO GET THE VALUE HERE FROM JAVASCRIPT" />
                                          </a>
                                    </xsl:when>
                                    <xsl:when test="$fieldtype='user'">
                                          <xsl:value-of select="$fieldvalue" disable-output-escaping="yes" />
                                    </xsl:when>
                                    <xsl:otherwise>
                                          <xsl:value-of select="I WANT TO GET THE VALUE HERE FROM JAVASCRIPT"/>
                                    </xsl:otherwise>
                              </xsl:choose>
                        </td>
                  </tr>
            </xsl:if>
      </xsl:template></xsl:stylesheet></Xsl>
Avatar of vmandem

ASKER

SORRY I WAS QUICK. IN the XSL Code I mentioned where I want to get the value from Javascript, please note that.
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vmandem

ASKER

Is it possible to call Javascript function without using msxsl because my webpart doesn't support the msxsl and throws and error at "ext:getscope()"
an other option is using Xalan, but you need to put the jar for rhinoceros in the classpath then,
other than Xalan and msxml I don't thinks you can use javascript in your stylesheet