Shil
Shil

Reputation: 221

XSLT - get the string before last '/'

I have the string for example :

 <path> c:/users/xyz/test_files/test.xml </path>

and I would like to get the string before last '/' that is:

c:/users/xyz/test_files

Thanks in Advance.

Upvotes: 2

Views: 2510

Answers (2)

Martin Honnen
Martin Honnen

Reputation: 167716

<xsl:template match="path">
  <xsl:variable name="p" select="string-join(tokenize(., '/')[position() lt last()], '/')"/>
</xsl:template>

should do.

Upvotes: 1

Daniel Haley
Daniel Haley

Reputation: 52888

Try something like this:

<xsl:variable name="tokens" select="tokenize(.,'/')"/>
<xsl:value-of select="$tokens[not(.=$tokens[last()])]" separator="/"/>

This assumes the current context is path.

Upvotes: 3

Related Questions