title: XSL: Just the filename without the path
body: <p>I'm new in XSL programming and I guess it is a simple question:
  How can I get the filename without the path?
  At the moment my code looks like this and I get the whole path:
  <strong>Result.xml:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;All_Results&gt;
      &lt;Result&gt;
        &lt;id&gt;1&lt;/id&gt;
        &lt;workid&gt;144&lt;/workid&gt;
        &lt;rank&gt;100000000&lt;/rank&gt;
        &lt;title&gt;Test Dokument&lt;/title&gt;
        &lt;author_multival&gt;Test&lt;/author_multival&gt;
        &lt;author&gt;Test&lt;/author&gt;
        &lt;size&gt;34185&lt;/size&gt;
        &lt;url&gt;https://test.test.com/docs/globalit/Lists/Documents/Datumtest/Test.docx&lt;/url&gt;
        &lt;urlEncoded&gt;https%3A%2F%2Ftest%2Etest%2Ecom%2Fdocs%2Fglobalit%2FLists%2FDocuments%2FDatumtest%2FTest%2Edocx&lt;/urlEncoded&gt;
        &lt;description&gt;&lt;/description&gt;
        &lt;write&gt;5/3/2013&lt;/write&gt;
        &lt;sitename&gt;https://test.test.com/docs/globalit/Lists/Documents/Datumtest&lt;/sitename&gt;
        &lt;collapsingstatus&gt;0&lt;/collapsingstatus&gt;
        &lt;hithighlightedsummary&gt;Noch mehr text Noch mehr text  &lt;ddd /&gt; &lt;/hithighlightedsummary&gt;
        &lt;hithighlightedproperties&gt;
          &lt;HHTitle&gt;Test Dokument&lt;/HHTitle&gt;
          &lt;HHUrl&gt;https://test.test.com/docs/globalit/Lists/Documents/Datumtest/Test.docx&lt;/HHUrl&gt;
        &lt;/hithighlightedproperties&gt;
        &lt;contentclass&gt;STS_ListItem_DocumentLibrary&lt;/contentclass&gt;
        &lt;isdocument&gt;True&lt;/isdocument&gt;
        &lt;picturethumbnailurl&gt;&lt;/picturethumbnailurl&gt;
        &lt;serverredirectedurl&gt;https://test.test.com/docs/globalit/_layouts/WordViewer.aspx?id=/docs/globalit/Lists/Documents/Datumtest/Test.docx&amp;amp;DefaultItemOpen=1&lt;/serveedirectedurl&gt; 
  &lt;doclanguage&gt;German&lt;/doclanguage&gt;
    &lt;doctitle&gt;Test&lt;/doctitle&gt;
    &lt;docauthor&gt;Team&lt;/docauthor&gt;
    &lt;revisiondate&gt;5/3/2013&lt;/revisiondate&gt;
    &lt;filename&gt;Test.docx&lt;/filename&gt;
    &lt;fileextension&gt;DOCX&lt;/fileextension&gt;
    &lt;imageurl imageurldescription="Microsoft Word"&gt;/_layouts/images/icdocx.png&lt;/imageurl&gt;
  &lt;/Result&gt;
  &lt;/All_Results&gt;
  </code></pre>
  
  <p><strong>result.xsl</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"&gt;
    &lt;xsl:output method="xml" indent="yes"/&gt;
  
    &lt;xsl:template match="TotalResults" /&gt;
    &lt;xsl:template match="NumberOfResults" /&gt;
  
    &lt;xsl:template name="DisplayString"&gt;
      &lt;xsl:param name="str" /&gt;
      &lt;xsl:if test='string-length($str) &amp;gt; 0'&gt;
        &lt;xsl:value-of select="$str" /&gt;
      &lt;/xsl:if&gt;
    &lt;/xsl:template&gt;
  
    &lt;xsl:template name="HitHighlighting"&gt;
      &lt;xsl:param name="hh" /&gt;
      &lt;xsl:apply-templates select="$hh"/&gt;
    &lt;/xsl:template&gt;
  
    &lt;xsl:template name="ResultPreviewToolTip"&gt;
      &lt;xsl:param name="contentclass" /&gt;
      &lt;xsl:param name="picturethumbnailurl" /&gt;
      &lt;xsl:param name="url" /&gt;
      &lt;xsl:param name="title" /&gt;
      &lt;xsl:param name="hithighlightedsummary" /&gt;
      &lt;xsl:param name="description" /&gt;
      &lt;xsl:param name="version" /&gt;
  
      &lt;xsl:choose&gt;
        &lt;xsl:when test="$contentclass[. = 'STS_ListItem_PictureLibrary'] and $picturethumbnailurl[. != '']"&gt;
          &lt;div&gt;
            &lt;a href="{$url}" title="{$title}"&gt;
              &lt;img src="{$picturethumbnailurl}" alt="" /&gt;
            &lt;/a&gt;
          &lt;/div&gt;
        &lt;/xsl:when&gt;
        &lt;xsl:when test="contains( $url, 'jpg' ) or contains( $url, 'jpeg' ) or contains( $url, 'gif' ) or contains( $url, 'JPG' ) or contains( $url, 'JPEG' ) or contains( $url, 'GIF' )"&gt;
          &lt;div&gt;
            &lt;img src="/_layouts/AssetUploader.aspx?Size=Medium&amp;amp;ImageUrl={$url}" alt="" /&gt;
          &lt;/div&gt;
        &lt;/xsl:when&gt;
        &lt;xsl:otherwise&gt;
          &lt;div&gt;
            &lt;xsl:choose&gt;
              &lt;xsl:when test="$hithighlightedsummary[. != '']"&gt;
                &lt;b&gt;Preview:&lt;/b&gt;
                &lt;br/&gt;
                &lt;xsl:call-template name="HitHighlighting"&gt;
                  &lt;xsl:with-param name="hh" select="$hithighlightedsummary" /&gt;
                &lt;/xsl:call-template&gt;
              &lt;/xsl:when&gt;
              &lt;xsl:when test="$description[. != '']"&gt;
                &lt;b&gt;Preview:&lt;/b&gt;
                &lt;br/&gt;
                &lt;xsl:value-of select="$description"/&gt;
              &lt;/xsl:when&gt;
              &lt;xsl:otherwise&gt;
                No preview available
              &lt;/xsl:otherwise&gt;
            &lt;/xsl:choose&gt;
            &lt;xsl:call-template name="DisplayString"&gt;
              &lt;xsl:with-param name="str" select="$version" /&gt;
              &lt;xsl:with-param name="text" select="'Version: '" /&gt;
              &lt;xsl:with-param name="stringcolor" select="'#808080'" /&gt;
            &lt;/xsl:call-template&gt;
  
          &lt;/div &gt;
        &lt;/xsl:otherwise&gt;
      &lt;/xsl:choose&gt;
    &lt;/xsl:template&gt;
  
    &lt;xsl:template match="Result"&gt;
      &lt;xsl:variable name="tdClass"&gt;
        &lt;xsl:if test="(position() mod 2 = 0)"&gt;
          &lt;xsl:value-of select="'even'" /&gt;
        &lt;/xsl:if&gt;
        &lt;xsl:if test="(position() mod 2 = 1)"&gt;
          &lt;xsl:value-of select="'odd'" /&gt;
        &lt;/xsl:if&gt;
      &lt;/xsl:variable&gt;
  
      &lt;tr&gt;
        &lt;td class="{$tdClass}"&gt;
          &lt;a href="#" class="tooltip"&gt;
            &lt;img&gt;
              &lt;xsl:attribute name="src"&gt;
                &lt;xsl:value-of select="imageurl"/&gt;
              &lt;/xsl:attribute&gt;
            &lt;/img&gt;
            &lt;span&gt;
              &lt;xsl:call-template name="ResultPreviewToolTip"&gt;
                &lt;xsl:with-param name="contentclass" select="contentclass" /&gt;
                &lt;xsl:with-param name="description" select="description" /&gt;
                &lt;xsl:with-param name="hithighlightedsummary" select="hithighlightedsummary" /&gt;
                &lt;xsl:with-param name="picturethumbnailurl" select="picturethumbnailurl" /&gt;
                &lt;xsl:with-param name="title" select="title" /&gt;
                &lt;xsl:with-param name="url" select="url" /&gt;
                &lt;xsl:with-param name="version" select="version" /&gt;
              &lt;/xsl:call-template&gt;
            &lt;/span&gt;
          &lt;/a&gt;
        &lt;/td&gt;
        &lt;td&gt;
          &lt;a&gt;
            &lt;xsl:attribute name="href"&gt;
              &lt;xsl:value-of select="url" disable-output-escaping="yes" /&gt;
            &lt;/xsl:attribute&gt;
            &lt;xsl:value-of select="filename"/&gt;
          &lt;/a&gt;
        &lt;/td&gt;
        &lt;td class="{$tdClass}"&gt;
          &lt;a&gt;
            &lt;xsl:attribute name="href"&gt;
              &lt;xsl:value-of select="url" disable-output-escaping="yes" /&gt;
            &lt;/xsl:attribute&gt;
            &lt;xsl:choose&gt;
              &lt;xsl:when test="doctitle != ''"&gt;
                &lt;xsl:value-of select="doctitle"/&gt;
              &lt;/xsl:when&gt;
              &lt;xsl:otherwise&gt;
                &lt;xsl:value-of select="title"/&gt;
              &lt;/xsl:otherwise&gt;
            &lt;/xsl:choose&gt;
          &lt;/a&gt;
        &lt;/td&gt;      
        &lt;td class="{$tdClass}"&gt;
          &lt;xsl:choose&gt;
            &lt;xsl:when test="docauthor != ''"&gt;
              &lt;xsl:value-of select="docauthor"/&gt;
            &lt;/xsl:when&gt;
            &lt;xsl:otherwise&gt;
              &lt;xsl:value-of select="author"/&gt;
            &lt;/xsl:otherwise&gt;
          &lt;/xsl:choose&gt;
        &lt;/td&gt;
        &lt;td class="{$tdClass}"&gt;
          &lt;xsl:value-of select="revisiondate" /&gt;
        &lt;/td&gt;
        &lt;td class="{$tdClass}"&gt;
          &lt;xsl:value-of select="doclanguage"/&gt;
        &lt;/td&gt;
        &lt;td class="{$tdClass}"&gt;
          &lt;a&gt;
            &lt;xsl:attribute name="href"&gt;
              &lt;xsl:value-of select="sitename" disable-output-escaping="yes" /&gt;
            &lt;/xsl:attribute&gt;
            &lt;img src="/_layouts/images/breadcrumbbutton.png" style="border-style: none" /&gt;
          &lt;/a&gt;
          &lt;xsl:call-template name="ShowVersionHistory" /&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
  
    &lt;/xsl:template&gt;
  
    &lt;xsl:template name="ShowVersionHistory"&gt;
  
      &lt;!-- First, encode Url --&gt;
      &lt;xsl:variable name="EncodedUrl"&gt;
        &lt;xsl:value-of disable-output-escaping="yes" select="ddwrt:UrlEncode(url)" /&gt;
      &lt;/xsl:variable&gt;    
  
      &lt;!--  does only work for office docuemnts --&gt;
      &lt;xsl:if test="string-length(serverredirectedurl) &amp;gt; 0"&gt;
  
        &lt;!-- get web url from office web app link --&gt;
        &lt;xsl:variable name="WebUrl"&gt;
          &lt;xsl:value-of select="substring-before(serverredirectedurl, '_layouts')"/&gt;
        &lt;/xsl:variable&gt;
  
        &lt;!-- create link --&gt;
        &lt;xsl:variable name="FinalLink"&gt;
          &lt;xsl:value-of select="$WebUrl"/&gt;
          &lt;xsl:text&gt;_layouts/Versions.aspx?FileName=&lt;/xsl:text&gt;
          &lt;xsl:value-of select="$EncodedUrl"/&gt;
        &lt;/xsl:variable&gt;
  
        &lt;a href="{$FinalLink}" target="_blank" Title="Version History"&gt;
          &lt;img src="/_layouts/images/versions.gif" style="border-style: none" /&gt;
        &lt;/a&gt;
      &lt;/xsl:if&gt; 
  
    &lt;/xsl:template&gt;
  
    &lt;xsl:template match="/"&gt;
      &lt;table class="searchresult"&gt;
        &lt;tr&gt;
          &lt;th width="18"&gt;&lt;/th&gt;
          &lt;th&gt;Filename&lt;/th&gt;
          &lt;th&gt;Title&lt;/th&gt;
          &lt;th&gt;Author&lt;/th&gt;
          &lt;th&gt;Revision Date&lt;/th&gt;
          &lt;th&gt;Language&lt;/th&gt;
          &lt;th&gt;Actions&lt;/th&gt;
        &lt;/tr&gt;
        &lt;xsl:apply-templates /&gt;
      &lt;/table&gt;
    &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>I only need to get it like Test.dotx or Test.xlsx.
  I tried sth with <code>&lt;xsl:value-of select="substring-after-last($url, '/')" disable-output-escaping="yes" /&gt;</code> but got an error.</p>
  
  <p>What can I do? How can I solve my problem?
  Thans for your support.
  Kind regards,
  Matthias</p>