Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharepoint ItemStyle.xsl for CQWP using images from a content type

Tags:

I'm building a custom Content Query Web Part to display rollup information from an employee content type. This content type has a Publishing Image site column called EmpPhoto. My CQWP is working great and all the site columns I need are available.

I am now creating a custom xsl template to render the information correctly but am stuck using the EmpPhoto image.

If I use the code:

<xsl:value-of select="@EmpPhoto" disable-output-escaping="yes" />

... I get a correctly rendered image which is great. However I want to build an onmouseover event for this image and this approach will not work.

I thought to create an xsl variable to grab the actual image URL then build my own html img and write the onmouseover into that e.g.

<xsl:variable name="EmpPhotoUrl">
    <xsl:call-template name="OuterTemplate.GetSafeStaticUrl">
        <xsl:with-param name="UrlColumnName" select="@EmpPhoto"/>
    </xsl:call-template>
</xsl:variable>

...

<img src="{$EmpPhotoUrl}" onmouseover="" alt="test" />

This doesn't get the URL from the EmpPhoto site column however. I am new to xsl so I might well be missing an obvious solution!

Any help much appreciated,

Jonny

like image 419
Jonny Avatar asked Feb 18 '09 22:02

Jonny


2 Answers

This is cheating... and it's making assumptions about the src attribute. But here it is!

<xsl:variable name="EmpPhotoUrl" select="substring-before(substring-after(@EmpPhoto, 'src=&quot;'), '&quot;')" />
like image 98
John Liu Avatar answered Nov 19 '22 15:11

John Liu


Given the @EmpPhoto value is just a string representing an html image tag, you could "inject" the mouseover script into the value, e.g.

<xsl:variable name="EmpPhoto"><xsl:value-of select=sub-string(@EmpPhoto) />[and some other code to add the mouseover etc]</xsl:variable>

<xsl:value-of select="$EmpPhoto" />
like image 31
Nat Avatar answered Nov 19 '22 14:11

Nat