Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 280581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:07:51+00:00 2026-05-12T05:07:51+00:00

In my CMS it is possible to create a new article, and choose an

  • 0

In my CMS it is possible to create a new article, and choose an image to be shown on that article. When an image is chosen, a thumbnail of the image will automatically be created as well.

If the uploaded image is called image.jpg, then the corresponding thumbnail will automatically be named image_thumbnail.jpg.

I would now like to use the thumbnail image, everywhere on the website where the article is mentioned, except in the article itself (where the original big image should be shown).

But how can I do that?

I imagine if I could get the original name of the image, and then split it up before the suffix (.jpg, .png, .jpeg etc.) and hardcode _thumbnail after the name, then that would be sufficient.

In other words, I want to take the complete filename, and cut it into two parts, so that I can insert the string _thumbnail between the two parts.

Maybe that would work, but what if an image called image.2horses.jpg (a file with more than one dot in the filename) is uploaded? A naive cut before the ‘.’ wouldn’t work here.

Is there a way to get around this? Perhaps by cutting the filename up before the last 4 (.jpg, .png) or 5 (.jpeg) characters?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:07:51+00:00Added an answer on May 12, 2026 at 5:07 am

    Given the image’s filename in $filename,

    If you can assume that all images will end in “.jpg” and won’t have “.jpg” elsewhere in the filename, then this should work:

    <img src="{substring-before($filename, '.jpg')}_thumbnail.jpg" ... />
    

    If you don’t know the image type (like, you want to handle gif and png as well), or if you think the extension may occur multiple times in the filename (“image.jpg.jpg”), then you will want a template to help you:

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="xml" indent="yes"/>
    
        <xsl:template match="/">
            <p>
                <xsl:call-template name="image_thumbnail">
                <xsl:with-param name="filename" select="'image.jpg'"/>
                </xsl:call-template>
            </p>
    
            <p>
                <xsl:call-template name="image_thumbnail">
                <xsl:with-param name="filename" select="'image.09.07.11.jpg'"/>
                </xsl:call-template>
            </p>
    
            <p>
                <xsl:call-template name="image_thumbnail">
                <xsl:with-param name="filename" select="'image.gif'"/>
                </xsl:call-template>
            </p>
    
            <p>
                <xsl:call-template name="image_thumbnail">
                <xsl:with-param name="filename" select="'image with spaces.jpg'"/>
                </xsl:call-template>
            </p>
    
            <p>
                <xsl:call-template name="image_thumbnail">
                <xsl:with-param name="filename" select="'image  with  irregular    spaces.jpg'"/>
                </xsl:call-template>
            </p>
    
            <p>
                <xsl:call-template name="image_thumbnail">
                <xsl:with-param name="filename" select="'image.jpg.again.jpg'"/>
                </xsl:call-template>
            </p>
    
        </xsl:template>
    
        <xsl:template name="image_thumbnail">
        <xsl:param name="filename"/>
            <xsl:choose>
            <xsl:when test="contains($filename, '.')">
                <xsl:variable name="before" select="substring-before($filename, '.')"/>
                <xsl:variable name="after" select="substring-after($filename, '.')"/>
                <xsl:choose>
                <xsl:when test="contains($after, '.')">
                    <xsl:variable name="recursive">
                        <xsl:call-template name="image_thumbnail">
                        <xsl:with-param name="filename" select="$after"/>
                        </xsl:call-template>
                    </xsl:variable>
                    <xsl:value-of select="concat($before, '.', $recursive)"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="concat($before, '_thumbnail.', $after)"/>
                </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$filename"/>
            </xsl:otherwise>
            </xsl:choose>
        </xsl:template>
    
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a CMS application in PHP and one of the requirements is that
We're building a CMS. The site will be built and managed by the users
I'm building a CMS in PHP and one dread I have is that the
We need a good CMS that supports data clustering (managing and storing data on
In our CMS, we have a place in which we enable users to play
I'm creating a cms and have not yet settled on the matter of where
I need some basic CMS functionality with rich text editing. On stack overflow there
I'm building a CMS in ASP.NET MVC and want to allow users to pick
We use Sharepoint as CMS for our webpages at work. I know how to
I am building a CMS and the naming convention for classes has been debated

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.