views:

1948

answers:

2

Hello,

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

+1  A: 

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" />
Nat
Hi Nat,I'm not clear on how the code you provided would inject additional properties into the html image tag?Would it not be possible to extract the src property from the html image tag in @EmpPhoto then build my own with the additional properties I require?Thanks very much for your help!!
Jonny
I think John Liu's answer is a pretty good start :)
Nat
+2  A: 

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;')" />
John Liu