3

I'm using a content query web part to display data from lists which are located in different subsites. So far I've been able to display items, but one of the requirements is that I've to display the ListName as a link where the user can click on List Name and be redirected to the list where he can see all items.

In side the if statement below, I would like to include the list name and the url to the list:

<xsl:if test="count(following-sibling::*)=0">
    !!!!! Link to the List !!!!
</xsl:if>   

So,how can I get the list url and the name? for example: the CQWP points to this list: http://dev/lists/myevents

I would like to show this in my xslt: <a href="http://dev/lists/myevents>myevents</a>

So, how I get the list url and the title in xslt? I tried $ListName, but it throws an error.

whole code:

  <xsl:template name="Events" match="Row[@Style='Events']" mode="itemstyle">
        <xsl:variable name="SafeLinkUrl">
            <xsl:call-template name="OuterTemplate.GetSafeLink">
                <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
            </xsl:call-template>
        </xsl:variable>
        <xsl:variable name="DisplayTitle">
            <xsl:call-template name="OuterTemplate.GetTitle">
                <xsl:with-param name="Title" select="@Title"/>
                <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
            </xsl:call-template>
        </xsl:variable>


      <div class="item link-item">
        <xsl:call-template name="OuterTemplate.CallPresenceStatusIconTemplate"/>     

        <a href="{$SafeLinkUrl}"><xsl:value-of select="$DisplayTitle"></xsl:value-of></a>

        <!-- End of Events -->  
                <!-- footer -->
        <xsl:if test="count(following-sibling::*)=0">
            !!!!! Link to the List !!!!

        </xsl:if>   
        <!-- end footer -->

    </div>

    </xsl:template>
  • Edit your question with some code so that members can give you best of the answers as desired by you – Yash Saraiya Nov 2 '15 at 10:11
  • the code is just a copy and paste of the itemstyle, but the question is whether you guys understand my question or not. Please see above for my update – Burre Ifort Nov 2 '15 at 14:56
1

I cannot see your code but I Think this may do it

<span class="title"><a href="<xsl:value-of select="$SafeLinkUrl" /
rel="nofollow">"><xsl:value-of select="@Title" /></a></span>
  • just as a side note you may need to change the span class from 'title' to whatever your span class currently is, if it doesn't work post your code – Jamie_lee Nov 2 '15 at 9:38
  • 1
    $SafeLinkUrl gives me the link of the item which is quite long which contains guids in it. I need to build this: webUrl + "/"+listName – Burre Ifort Nov 2 '15 at 9:42
1

ContentQueryMain refers to a param called WebURL so you could use OuterTemplates.GetTitle to resolve that. Further down, the only other param that looks like a good candidate for the list URL is one called Source. I'm afraid to even try to get a result from using that though - I'll leave it to someone more experienced, knowledgeable!

I should add that in all cases where I've achieved similar to what you want (i.e. a button saying View all Events and it goes to the default view) I've made an itemstyle with a relative link.

In cases where my CQWP is on a publishing page, in /Pages and at the same sub site level, I can use a logical link like:

<a href="../EventList/Forms/AllItems.aspx">View all Events</a>

because that tells the browser to look one level up from /Pages, then down again to /EventList

  • The question is can you can do it dynamically. – Christopher Nov 17 '15 at 12:11
0

The list URL is not directly available, but you can extract it from the item URL like this:

<xsl:variable name="listUrl" select="substring-before(@FileRef,@FileLeafRef)" />

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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