5 users online. Create an account or sign in to join them.Users

Search

I have a string:

240x140/Main/All_Languages/Holiday_Live/Caribbean/Cuba/The_Cayos/Cayo_Santa_Maria/Melia_Las_Dunas/CBVDA997DOT.jpg

that I need to get the filename (minus the extension) from. I know how to get the string minus the extension:

substring-before('stringhere', '.j')

but I don’t know how to substring-after the last /

Any XSLT Ninjas out there?

You could try the EXSLT str:tokenize function to split up the string with / as delimiter.

From the top of my head, without any testing:

<xsl:template name="basename">
    <xsl:param name="text" />

    <xsl:choose>
        <xsl:when test="contains($text,'/')">
            <xsl:call-template name="basename">
                <xsl:with-param name="text" select="substring-after($text,'/')" />
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$text" />
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

nice one :-)

Cool!

I forgot to mention though, can this be done with one line of xpath? I need it for a Reflection Field. :o)

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.2 or above
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.0 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details