One way would be to use the substring-after function - you would have to use it in a nested fashion as per the following code:
So the inner substring is trimming the "/media/" bit as this will always be constant, and then the outer substring is returning everything after the next "/"
I appreciate this is probably not the best solution (flexibility, extensibility, etc) but it works based on your example.
Thinking I'll add some extra functions to the uComponents' IO extensions! ;-) (e.g. Path.GetExtension, Path.GetFileName, Path.GetFileNameWithoutExtension, Path.GetDirectoryName)
best way to trim a filename?
I'm bringing the following from umbraco.library:GetMedia($img,'false')/umbracoFile:
/media/3410/searchengineland-periodic-table-of-seo.pdf
which I'd like to trim to
searchengineland-periodic-table-of-seo.pdf
I thought ucomponents.strings:PathShortener() might do the trick but no dice.
do I have to do some regex? is there a neat tool somewhere to acheive this?
thanks for any help
- Tim
Hi there
One way would be to use the substring-after function - you would have to use it in a nested fashion as per the following code:
So the inner substring is trimming the "/media/" bit as this will always be constant, and then the outer substring is returning everything after the next "/"
I appreciate this is probably not the best solution (flexibility, extensibility, etc) but it works based on your example.
Cheers
Nigel
Hi Tim,
Nigel's code seems to have been munged by the Forum Monster (TM) - but I'm guessing it's one of two approaches:
/Chriztian
Awesome, thanks Christian (and thanks Nigel)
both of these work, the recursive template example is pretty cool, I didn't know about not(contains()) I'm sure that will come in handy in future!
thanks also for the heads up on the 'false' thing.
P.S when are you releasing the 10 commandments of xslt book ;)
- Tim
Loving the recursive template Chriztian!
Thinking I'll add some extra functions to the uComponents' IO extensions! ;-) (e.g. Path.GetExtension, Path.GetFileName, Path.GetFileNameWithoutExtension, Path.GetDirectoryName)
Cheers, Lee.
@Tim: I might release a stone version, a wood version and possibly an EPUB - but definitely an XML version :-)
@Lee: Those would probably be great additions!
/Chriztian
It has been done.
@Chriztian - I owe you an email from last week ... I will get around to it! :-)
is working on a reply...