xsl-list
[Top] [All Lists]

Re: [xsl] Getting text from string

2011-11-01 12:32:37
On 01/11/2011 17:18, Stan Mikita wrote:
Hi,

I have a directory path value and i want to grab the text "filename"
to the right of the last "/". I've tried using the below without any
luck. Is there a reverse search where you can tell it to search from
the right up to the first occurence of a "/"? Value can be many
directories deep.

path = "dir1/dir2/dir3/dir4/filename"

xsl:variable name="dirPath" select="substring-before(@path,'/')"/

xsl:variable name="dirPath" select="substring-after(@path,'/')"/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


In XSLT 2.0 you can do select="tokenize(@path, '/')[last()]".

In XSLT 1.0 it needs a recursive template: conceptually

getLast(X) -> if (contains(X, '/') then getLast(substring-after(X, '/')) else X

Michael Kay
Saxonica



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--