Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you're stuck with XSLT 1.0, you could use a recursive template like this:</p> <h3>Stylesheet</h3> <pre><code>&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt; &lt;xsl:output method="text"/&gt; &lt;xsl:template name="substring-after-last"&gt; &lt;xsl:param name="string"/&gt; &lt;xsl:param name="char"/&gt; &lt;xsl:choose&gt; &lt;xsl:when test="contains($string, $char)"&gt; &lt;xsl:call-template name="substring-after-last"&gt; &lt;xsl:with-param name="string" select="substring-after($string, $char)"/&gt; &lt;xsl:with-param name="char" select="$char"/&gt; &lt;/xsl:call-template&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;xsl:value-of select="$string"/&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:template&gt; &lt;xsl:template match="/"&gt; &lt;xsl:call-template name="substring-after-last"&gt; &lt;xsl:with-param name="string" select="'/var/log/tomcat'"/&gt; &lt;xsl:with-param name="char" select="'/'"/&gt; &lt;/xsl:call-template&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <h3>Output</h3> <pre><code>tomcat </code></pre> <p>Note, though, that this template probably won't do what you want if the last character in your path is a <code>/</code>, because it'll always just return what's after the last <code>$char</code>. In other words, for <code>/var/log/tomcat/</code> (as opposed to <code>/var/log/tomcat</code>, without the trailing forward slash), this template would return an empty string.</p> <p>To use this in your own code, you could copy-paste the <code>substring-after-last</code> template above into your own code and instead of:</p> <pre><code>&lt;xsl:attribute name="href"&gt; &lt;xsl:value-of select="url" disable-output-escaping="yes" /&gt; &lt;/xsl:attribute&gt; </code></pre> <p>You could use:</p> <pre><code>&lt;xsl:attribute name="href"&gt; &lt;xsl:call-template name="substring-after-last"&gt; &lt;xsl:with-param name="string" select="url"/&gt; &lt;xsl:with-param name="char" select="'/'"/&gt; &lt;/xsl:call-template&gt; &lt;/xsl:attribute&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload