Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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?:
<!-- start writing XSLT -->
<msxsl:script language="C#" implements-prefix="prg">
public string pathGetExtension(string filename)
public string pathGetFileName(string filename)
public string pathGetFileNameWithoutExtension(string filename)
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:
@foreach (var item in selection)
just used this expression and it worked
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted