none
XSLT changes in "Search Core Results" - Link to containing folder - how? RRS feed

Answers

  • Hi Jack,

    In my opinion there are no "easy" ways to do this in xslt. But it's solvable with a template. A quick search on Stack Overflow yielded this result:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        version="1.0">
    <xsl:template match="/">
    
        <xsl:call-template name="getURL">
            <xsl:with-param name="path">http://www.site.com/subsite/doclibrary1/FileName.doc</xsl:with-param>
        </xsl:call-template>
    </xsl:template>
    
        <xsl:template name="getURL">
            <xsl:param name="path" />
            <xsl:choose>
                <xsl:when test="contains($path,'/')">
                    <xsl:value-of select="substring-before($path,'/')" />
                    <xsl:text>/</xsl:text>
                    <xsl:call-template name="getURL">
                        <xsl:with-param name="path" select="substring-after($path,'/')" />
                    </xsl:call-template>
                </xsl:when>
                <xsl:otherwise />
            </xsl:choose>
        </xsl:template>
    
    </xsl:stylesheet>
    


    The other option is to take advantage of callback functions in xslt which is supported in .Net. Then you could call upon the System.IO.Path.GetDirectoryName to strip off the filename. This however requires the deployment of a dll in your SP environment with such a callback function.

    For larger projects using xslt I always do this, as particularly string manipulation is cumbersome in xslt compared to .Net.

    Regards,
    Mikael Svenson 


    Search Enthusiast - SharePoint MVP/WCF4/ASP.Net4
    http://techmikael.blogspot.com/
    Thursday, September 8, 2011 7:13 PM

All replies

  • Hi Jack,

    In my opinion there are no "easy" ways to do this in xslt. But it's solvable with a template. A quick search on Stack Overflow yielded this result:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        version="1.0">
    <xsl:template match="/">
    
        <xsl:call-template name="getURL">
            <xsl:with-param name="path">http://www.site.com/subsite/doclibrary1/FileName.doc</xsl:with-param>
        </xsl:call-template>
    </xsl:template>
    
        <xsl:template name="getURL">
            <xsl:param name="path" />
            <xsl:choose>
                <xsl:when test="contains($path,'/')">
                    <xsl:value-of select="substring-before($path,'/')" />
                    <xsl:text>/</xsl:text>
                    <xsl:call-template name="getURL">
                        <xsl:with-param name="path" select="substring-after($path,'/')" />
                    </xsl:call-template>
                </xsl:when>
                <xsl:otherwise />
            </xsl:choose>
        </xsl:template>
    
    </xsl:stylesheet>
    


    The other option is to take advantage of callback functions in xslt which is supported in .Net. Then you could call upon the System.IO.Path.GetDirectoryName to strip off the filename. This however requires the deployment of a dll in your SP environment with such a callback function.

    For larger projects using xslt I always do this, as particularly string manipulation is cumbersome in xslt compared to .Net.

    Regards,
    Mikael Svenson 


    Search Enthusiast - SharePoint MVP/WCF4/ASP.Net4
    http://techmikael.blogspot.com/
    Thursday, September 8, 2011 7:13 PM
  • Alternatively, you could always manipulate the URL in a pipeline extensibility stage.

    Marcus Johansson | Search Nerd | comperiosearch.com | linkedin.com/in/marcusjohansson
    Thursday, September 8, 2011 7:25 PM