I have the following below code, i am trying to populate search box. What i need is to get the textbox value throught javascript inside xslt. Please see the bold text right now when i keydown in my textbox i am able to see the functions directly print as string. if any one can guide i would be very thankful.
I don't think I understand what you want to do — you can not call a JavaScript function inside the XSLT file if that's your problem; The XSLT rendering happens on the server, so by the time the JavaScript is running in the browser it's way past XSLT's bedtime so to speak :-)
If you need the search term inside XSLT on subsequent renderings, you can use the library extensions RequestQueryString() or RequestForm() to get the value that was sent...
Don't know if that answers your question - feel free to supply more details.
Many thanks for your reply, actually i have a textbox where i am loading auto suggested results by alphabet, when i enter F for example the datas from alphatbet F loads. i am posting the entire code below...the bold text i am trying to get the text box value.
<xsl:for-each select="$currentRoot/ShoppingCategoryList/ShoppingList/* [@isDoc and name() = 'ShoppingDetails' and contains(Exslt.ExsltStrings:uppercase(inShopTitle), Exslt.ExsltStrings:uppercase($filterkey))]">
- What you're trying to do is to take that "F" from the textfield, and somehow use it in the XSLT - but the XSLT rendered the page a long time ago, back in step 2 already, so there's no way you can do that without another page request.
I can see some ASP.NET tags in the code too, which suggest to me that your're maybe trying to convert a .NET page to XSLT — if so, maybe you should just use a UserControl macro instead?
The way you do something like this would be to have a separate macro rendering the results of a query like /page/?filter=F and then you would call that using Ajax from your main page - that way you could grab the value and use it to filter the nodes to return...
Javascript function inside xslt
Hi
I have the following below code, i am trying to populate search box. What i need is to get the textbox value throught javascript inside xslt. Please see the bold text right now when i keydown in my textbox i am able to see the functions directly print as string. if any one can guide i would be very thankful.
<script type="text/javascript" defer="defer" language="javascript">
//<![CDATA[
var searchRequest=false;
var searchSugestDelay=1000;
var timeOutId;
function getValue(e){
return e.val;
}
function getSearch(e) {
// alert($(e).val());
//]]>
<xsl:variable name="filterkey">
<xsl:text>$(e).val();</xsl:text>
</xsl:variable>
Hi mvkamalesh,
I don't think I understand what you want to do — you can not call a JavaScript function inside the XSLT file if that's your problem; The XSLT rendering happens on the server, so by the time the JavaScript is running in the browser it's way past XSLT's bedtime so to speak :-)
If you need the search term inside XSLT on subsequent renderings, you can use the library extensions RequestQueryString() or RequestForm() to get the value that was sent...
Don't know if that answers your question - feel free to supply more details.
/Chriztian
Hi Chriztian,
Many thanks for your reply, actually i have a textbox where i am loading auto suggested results by alphabet, when i enter F for example the datas from alphatbet F loads. i am posting the entire code below...the bold text i am trying to get the text box value.
here you go..
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:ucomponents.email="urn:ucomponents.email" xmlns:ucomponents.media="urn:ucomponents.media" xmlns:ucomponents.nodes="urn:ucomponents.nodes" xmlns:ucomponents.urls="urn:ucomponents.urls"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ucomponents.email ucomponents.media ucomponents.nodes ucomponents.urls ">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:param name="currentPage"/>
<xsl:variable name="currentRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
<xsl:template match="/">
<script type="text/javascript" defer="defer" language="javascript">
//<![CDATA[
var searchRequest=false;
var searchSugestDelay=1000;
var timeOutId;
function getValue(e){
return e.val;
}
function getSearch(e) {
// alert($(e).val());
//]]>
<xsl:variable name="filterkey">
<xsl:text>$(e).val();</xsl:text>
</xsl:variable>
<xsl:variable name="searchResults">
<xsl:text disable-output-escaping="yes"><ul class="search-suggest"></xsl:text>
<xsl:text><li></xsl:text><xsl:value-of select="$filterkey"/><xsl:text></li></xsl:text>
<xsl:for-each select="$currentRoot/ShoppingCategoryList/ShoppingList/* [@isDoc and name() = 'ShoppingDetails' and contains(Exslt.ExsltStrings:uppercase(inShopTitle), Exslt.ExsltStrings:uppercase($filterkey))]">
<xsl:text disable-output-escaping="yes"><li><a href="</xsl:text>
<xsl:value-of select="umbraco.library:NiceUrl(./@id)" disable-output-escaping="yes"/>
<xsl:text disable-output-escaping="yes">"></xsl:text>
<xsl:value-of select="umbraco.library:Replace(./inShopTitle,"'",'')"/>
<xsl:text disable-output-escaping="yes"></a></li></xsl:text>
</xsl:for-each>
<xsl:text disable-output-escaping="yes"></ul></xsl:text>
</xsl:variable>
<xsl:choose>
<xsl:when test="$searchResults!=''">
$('#suggestsearch').show();
$('#suggestsearch').html('<xsl:value-of select="$searchResults" disable-output-escaping="yes"/>');
$items = $('#suggestsearch li');
$itemcount = $items.length;
$('#suggestsearch li a:first').addClass('current');
$('#suggestsearch a').hover(function(){
$('#suggestsearch a').removeClass('current');
$currentItem = $(this).addClass('current');
$currpos = $currentItem.position().top;
$("#suggestsearch:not(:animated)").animate({ scrollTop: $currpos-50}, 500 );
},
function(){
});
$("#suggestsearch:not(:animated)").animate({ scrollTop: 0}, 500 );
</xsl:when>
<xsl:otherwise>
$('#suggestsearch').hide();
</xsl:otherwise>
</xsl:choose>
<!-- setSearch(<xsl:value-of select="$searchResults" disable-output-escaping="yes"/>);-->
//<![CDATA[
}
function setSearch(searchResult) {
$('#suggestsearch').show();
$('#suggestsearch').html(searchResult);
$items = $('#suggestsearch li');
$itemcount = $items.length;
$('#suggestsearch li a:first').addClass('current');
$('#suggestsearch a').hover(function(){
$('#suggestsearch a').removeClass('current');
$currentItem = $(this).addClass('current');
$currpos = $currentItem.position().top;
$("#suggestsearch:not(:animated)").animate({ scrollTop: $currpos-50}, 500 );
//$('#<%= searchKeyword.ClientID %>').val($(this).text())
},
function(){
});
$("#suggestsearch:not(:animated)").animate({ scrollTop: 0}, 500 );
}
$("html").click(function(){
$('#suggestsearch').html("");
$('#suggestsearch').hide();
});
$('#<%= searchKeyword.ClientID %>').attr('autocomplete','on');
//Chosen
$(window).load(function(){
$('.searchcat').chosen();
$("#search-another-cat").chosen();
$href = "";
$('.frm-search .txt').bind('keyup', function(e){
e.stopPropagation();
if(e.keyCode == 40){
$current = $('#suggestsearch a.current');
$current.parents('li').next('li').find('a').addClass('current');
$href = $current.parents('li').next('li').find('a').attr('href');
//$('#<%= searchKeyword.ClientID %>').val($current.parents('li').next('li').find('a').text())
$itemlen = $('#suggestsearch li').length-1;
//console.log($current.parents('li').index() + "/" + $itemlen)
if($itemlen != $current.parents('li').index()){
$currentheight = $current.position().top;
$("#suggestsearch:not(:animated)").animate({ scrollTop: $currentheight}, 500 );
$current.removeClass('current');
}
}
else if(e.keyCode == 38){
$currentup = $('#suggestsearch a.current');
$currentupval = $currentup.parents('li').prev('li').find('a').addClass('current');
//$('#<%= searchKeyword.ClientID %>').val($currentup.parents('li').prev('li').find('a').text());
$href = $currentup.parents('li').prev('li').find('a').attr('href');
if($currentup.parents('li').index() != 0){
$currentbtm = $currentupval.position().top;
$("#suggestsearch:not(:animated)").animate({ scrollTop: $currentbtm}, 500 );
$currentup.removeClass('current');
}
}
else {
if(e.keyCode == 13){
if($href == ""){
$('search').submit();
}else{
window.location = $href;
};
return false;
} else {
getSearch(this.value);
}
}
});
});
//]]>
</script>
</xsl:template>
</xsl:stylesheet>
Any one out there to fix teh above issue?
.
Hi mvkamalesh,
This is what happens:
is working on a reply...