?
Solved

How to call javascript function inside my XSL

Posted on 2009-12-26
10
Medium Priority
?
2,821 Views
Last Modified: 2013-11-18
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

0
Comment
Question by:vmandem
  • 5
  • 5
10 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 26125224
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
0
 

Author Comment

by:vmandem
ID: 26125700
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
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 26125731
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
0
Independent Software Vendors: 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:vmandem
ID: 26126044
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.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 26126622
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
0
 

Author Comment

by:vmandem
ID: 26128398
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>
0
 

Author Comment

by:vmandem
ID: 26128399
SORRY I WAS QUICK. IN the XSL Code I mentioned where I want to get the value from Javascript, please note that.
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 200 total points
ID: 26137096
This is running a javascript during xslt transform,
here is how you do that
I assume you can merge the functionality in your own stylesheet yourself
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:ext="urn:ext:functions:xslt"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                extension-element-prefixes="ext msxsl">

<msxsl:script language="JScript" implements-prefix="ext">
	<![CDATA[
		function getscope()
		{
		var scope = 'Test1'
		return scope
		}
	]]>
</msxsl:script>
<xsl:template match="/">
	<xsl:value-of select="ext:getscope()"/>
</xsl:template>

</xsl:stylesheet>

Open in new window

0
 

Author Comment

by:vmandem
ID: 26161693
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()"
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 26161729
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
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

850 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