I needed a way to get media file names without their extensions. Did not find any quick way in pure xslt. So I made this script, anyone has a more direct way?:
If you've uploaded them into the media section you can access the extension property, which you can do a string replace on to remove. Something like this:
Yes, did not know about that property, thanks, however - if the extension also exist as part of the filename this will not be a good solution. Perhaps better use the length of the extension and remove that number +1 of chars from the end. But the more I use xslt the more I want as short instructions as possible. For readability. Perhaps one should put functions like this in a xslt-dll-extension.
The extension variable I created also includes the fullstop (e.g. ".jpg") so as long as the file name is not some like "pic.jpgbig.jpg" it will work OK. Ie. bigpic_jpg.jpg will return bigpic_jpg as the file name.
Filename without extension
Hi!
I needed a way to get media file names without their extensions. Did not find any quick way in pure xslt. So I made this script, anyone has a more direct way?:
If you've uploaded them into the media section you can access the extension property, which you can do a string replace on to remove. Something like this:
<xsl:for-each select="umbraco.library:GetMedia(./@id, 'true')/node">
<xsl:variable name="extension">.<xsl:value-of select="./data[@alias='umbracoExtension']"/></xsl:variable>
<xsl:variable name="theTitle" select="Exslt.ExsltStrings:replace(@nodeName, $extension, '')"/>
Yes, did not know about that property, thanks, however - if the extension also exist as part of the filename this will not be a good solution. Perhaps better use the length of the extension and remove that number +1 of chars from the end. But the more I use xslt the more I want as short instructions as possible. For readability. Perhaps one should put functions like this in a xslt-dll-extension.
The extension variable I created also includes the fullstop (e.g. ".jpg") so as long as the file name is not some like "pic.jpgbig.jpg" it will work OK. Ie. bigpic_jpg.jpg will return bigpic_jpg as the file name.
How do I do that now? I'm not familiar with XSLT, so I'm looking for a way to do it in Razor, like in this default folder listing code:
Any ideas?
EDIT: nvm
just used this expression and it worked
is working on a reply...