<p>I need to be able to find the last occurrence of a character within an element.</p>

<p>For example:</p>

<pre><code>&lt;mediaurl&gt;http://www.blah.com/path/to/file/media.jpg&lt;/mediaurl&gt;
</code></pre>

<p>If I try to locate it through using <code>substring-before(mediaurl, '.')</code> and <code>substring-after(mediaurl, '.')</code> then it will, of course, match on the first dot.  </p>

<p>How would I get the file extension?  Essentially, I need to get the file name and the extension from a path like this, but I am quite stumped as to how to do it using XSLT.</p>

[{'answer_id': 14547, 'author': 'Gishu', 'author_id': 1695, 'author_profile': 'https://Stackoverflow.com/users/1695', 'pm_score': 0, 'selected': False, 'text': '<p>How about tokenize with "/" and take the last element from the array ?</p>\n\n<pre><code>Example: tokenize("XPath is fun", "\\s+")\nResult: ("XPath", "is", "fun")\n</code></pre>\n\n<p>Was an XSLT fiddler sometime back... lost touch now. But HTH</p>\n'}, {'answer_id': 14686, 'author': 'James Sulak', 'author_id': 207, 'author_profile': 'https://Stackoverflow.com/users/207', 'pm_score': 2, 'selected': False, 'text': '<p>If you\'re using XSLT 2.0, it\'s easy:</p>\n\n<pre><code> &lt;xsl:variable name="extension" select="tokenize($filename, \'\\.\')[last()]"/&gt;\n</code></pre>\n\n<p>If you\'re not, it\'s a bit harder.  There\'s a good example from the <a href="http://oreilly.com/catalog/9780596003722/toc.html" rel="nofollow noreferrer">O\'Reilly XSLT Cookbook</a>.  Search for "Tokenizing a String."</p>\n\n<p>I believe there\'s also an EXSLT function, if you have that available.</p>\n'}, {'answer_id': 16414, 'author': 'samjudson', 'author_id': 1908, 'author_profile': 'https://Stackoverflow.com/users/1908', 'pm_score': 5, 'selected': True, 'text': '<p>The following is an example of a template that would produce the required output in XSLT 1.0:</p>\n\n<pre><code>&lt;xsl:template name="getExtension"&gt;\n&lt;xsl:param name="filename"/&gt;\n\n  &lt;xsl:choose&gt;\n    &lt;xsl:when test="contains($filename, \'.\')"&gt;\n    &lt;xsl:call-template name="getExtension"&gt;\n      &lt;xsl:with-param name="filename" select="substring-after($filename, \'.\')"/&gt;\n    &lt;/xsl:call-template&gt;\n    &lt;/xsl:when&gt;\n    &lt;xsl:otherwise&gt;\n      &lt;xsl:value-of select="$filename"/&gt;\n    &lt;/xsl:otherwise&gt;\n  &lt;/xsl:choose&gt;\n&lt;/xsl:template&gt;\n\n&lt;xsl:template match="/"&gt;\n    &lt;xsl:call-template name="getExtension"&gt;\n        &lt;xsl:with-param name="filename" select="\'http://www.blah.com/path/to/file/media.jpg\'"/&gt;\n    &lt;/xsl:call-template&gt;\n&lt;/xsl:template&gt;\n</code></pre>\n'}, {'answer_id': 28006, 'author': 'jelovirt', 'author_id': 2679, 'author_profile': 'https://Stackoverflow.com/users/2679', 'pm_score': 0, 'selected': False, 'text': '<p>For reference, this problem is usually called "substring-after-last" in XSLT.</p>\n'}]
['https://Stackoverflow.com/questions/14527', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/274/']