I'm sort of new in XSLT, and i need some clues, if you're willing to give me some...

What i want:

In a CQWP, i want to display items' images, with a certain rendition ID. But, when retrieving the items' images, they will already have a rendition id. And not always the same. Or maybe they won't have any rendition id. (or maybe the size is specified, we won't know for sure in advance) Now, in my xslt itemstyle, i would like to take the path of the image and replace the rendition id by my proper rendition id.

So, in input, i will have 3 possibilities :

  • "mysite/PublishingImages/myimage01.jpg"
  • "mysite/PublishingImages/myimage02.jpg?RenditionID=5"
  • "mysite/mysubsite/PublishingImages/myimage03.jpg?Width=400"

And in output, i would like to have :

  • "mysite/PublishingImages/myimage01.jpg ?RenditionID=PROPERID"
  • "mysite/PublishingImages/myimage02.jpg ?RenditionID=PROPERID"
  • "mysite/mysubsite/PublishingImages/myimage03.jpg ?RenditionID=PROPERID"

For the moment, i get my url link like the following :

<xsl:variable name="SafeImageUrl"><xsl:call-template name="OuterTemplate.GetSafeStaticUrl"><xsl:with-param name="UrlColumnName" select="'ImageUrl'"/></xsl:call-template></xsl:variable>
<img src="{$SafeImageUrl}"/>

I've already seen that you can do a concatenation

<img src="{concat($SafeImageUrl,'?RenditionID=5')}"/>

And certainly you can do a sort of replacement

    <xsl:variable name="SafeImageUrl"><xsl:call-template name="OuterTemplate.GetSafeStaticUrl"><xsl:with-param name="UrlColumnName" select="'ImageUrl'"/></xsl:call-template></xsl:variable>
   <xsl-variable name="replaced"></xsl-variable><xsl:value-of select="replace($SafeLinkUrl,'blabla','hello')"/></xsl-variable> 

But because of all the unknown, i would like to use a regex. And because i'm a beginner, i don't know how, nor wich one to use...

Could you please give me some clues?

Thanks a lot, and have a wonderful evening.

-- Edit, few hours later --

I've found another way to achieve this! Because i can have only two real ways to get an image, i just made a xsl:if and some string operations.

My solution :

<xsl:if test="contains($SafeImageUrl,'?')">
                <xsl:variable name="before"><xsl:value-of select="substring-before($SafeImageUrl,'?')"/></xsl:variable>
                <xsl:variable name="finalUrl"><xsl:value-of select="concat($before,'?RenditionID=5')"/></xsl:variable>

                <xsl:if test="$ItemsHaveStreams = 'True'"><xsl:attribute name="onclick"><xsl:value-of select="@OnClickForWebRendering"/></xsl:attribute></xsl:if>
                <xsl:if test="$ItemsHaveStreams != 'True' and @OpenInNewWindow = 'True'"><xsl:attribute name="onclick"><xsl:value-of disable-output-escaping="yes" select="$OnClickTargetAttribute"/></xsl:attribute></xsl:if>
                <img src="{$finalUrl}" title="{@Title}"/>
            <xsl:if test="not(contains($SafeImageUrl,'?'))">
                <xsl:variable name="finalUrl"><xsl:value-of select="concat($SafeImageUrl,'?RenditionID=5')"/></xsl:variable>
                <img src="{$finalUrl}" title="{@Title}">


Well, it is more a contournment than a real solution, but works like a charm for me!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.