0

I have created a template in ItemStyle.xsl for CQWP.

I want to store the xsl variable value that is returned from javascript:

My template is:

<xsl:template name="DepartmentsTemplate" match="Row[@Style='DepartmentsTemplate']" mode="itemstyle">

<xsl:variable name="DisplayTitle">
        <xsl:call-template name="OuterTemplate.GetTitle">
            <xsl:with-param name="Title" select="@Title"/>                                    
        </xsl:call-template>
    </xsl:variable>     
    <xsl:variable name="CurrSite"/> // I want this variable value to be assigned from javascript function return value.       

<a> <xsl:value-of select="substring-before(@Department,'|')" disable-output-escaping="yes"></xsl:value-of></a>  

 </xsl:template> 

Javascript function is:

function getValue()
{
var url = location.protocol + "//" + location.host +  L_Menu_BaseUrl;   

var n= url.lastIndexOf("/");

var currSite = url.substring(n+1,url.length);

return currSite;

}

How do I accomplish this?

Javascript function is defined in another js file that is, it is not written in the ItemStyle.xsl

2 Answers 2

1

Since XSLT transformation in SharePoint is invoked on the server side, there's no way to execute JavaScript code before XSLT transformation.


How to pass the current Web Url in Content Query web part

I assume in your scenario the current site url should be passed into ItemStyle.xsl, there is another way how it could be accomplished.

Specify ProjectProperty.SiteUrl via CQWP ViewFieldsOverride property, where ProjectProperty.Url - Full URL of the current Web site

<property name="ViewFieldsOverride" type="string"><![CDATA[<ProjectProperty Name="Url" />]]></property>  

After that ProjectProperty.Url could be used in ItemStyle.xsl:

<xsl:value-of select="@ProjectProperty.Url" /> <!-- returns a full URL of the current Web site -->
0

If Curr site is a the current site URL you can check out the xsl server variables that SharePoint makes avaialable including URL and QUERY_STRING params. A link to the MSDN docs and a tutorial can be found below.

Tutorial on using the server variables in XSLT webpart

MSDN Documentation of XSL Server variables

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.