title: XSL - Removing the filename from the path string
body: <p>I've got a SharePoint problem which I need some help with. I'm creating some custom ItemStyles to format the output of a Content Query Webpart (CQWP) but I need to insert a "view all" button into the output.</p>
  
  <p>View all needs to point to:
  <a href="http://www.site.com/subsite/doclibrary1/Forms/AllItems.aspx" rel="noreferrer">http://www.site.com/subsite/doclibrary1/Forms/AllItems.aspx</a></p>
  
  <p>All the individual files in the document library have the link of:
  <a href="http://www.site.com/subsite/doclibrary1/FileName.doc" rel="noreferrer">http://www.site.com/subsite/doclibrary1/FileName.doc</a></p>
  
  <p>So what I need is some XSL functions to strip FileName.doc from the end of the string.</p>
  
  <p>I've tried using substring-before($variable, '.') to get rid of the .doc, but I then need to find a way to use substring-after to search for the LAST forward slash in the series and truncate the orphaned filename.</p>
  
  <p><strong>Using @Mads Hansen's post, this is the code which resolved the problem:</strong></p>
  
  <p>Template in ItemStyle.xsl</p>
  
  <pre><code>&lt;xsl:template name="ImpDocs" match="Row[@Style='ImpDocs']" mode="itemstyle"&gt;
      &lt;xsl:variable name="SafeLinkUrl"&gt;
          &lt;xsl:call-template name="OuterTemplate.GetSafeLink"&gt;
              &lt;xsl:with-param name="UrlColumnName" select="'LinkUrl'"/&gt;
          &lt;/xsl:call-template&gt;
      &lt;/xsl:variable&gt;
      &lt;xsl:variable name="ViewAllLink"&gt;
          &lt;xsl:call-template name="OuterTemplate.getCleanURL"&gt;
              &lt;xsl:with-param name="path" select="@LinkUrl"/&gt;
          &lt;/xsl:call-template&gt;
      &lt;/xsl:variable&gt;
      &lt;div class="DocViewAll"&gt;
          &lt;a href="{$ViewAllLink}Forms/AllItems.aspx" title="View all"&gt;View All&lt;/a&gt;
          &lt;!--Any other code you need for your custom ItemStyle here--&gt;
      &lt;/div&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>Template in ContentQueryMain.xsl</p>
  
  <pre><code>&lt;xsl:template name="OuterTemplate.getCleanURL"&gt;
      &lt;xsl:param name="path" /&gt;
      &lt;xsl:choose&gt;
          &lt;xsl:when test="contains($path,'/')"&gt;
              &lt;xsl:value-of select="substring-before($path,'/')" /&gt;
              &lt;xsl:text&gt;/&lt;/xsl:text&gt;
              &lt;xsl:call-template name="OuterTemplate.getCleanURL"&gt;
                  &lt;xsl:with-param name="path" select="substring-after($path,'/')" /&gt;
              &lt;/xsl:call-template&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:otherwise /&gt;
      &lt;/xsl:choose&gt;
  &lt;/xsl:template&gt;
  </code></pre>