Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have managed to create an ItemStyle template for my CQWP. It pulls from various announcements. I have set the character limit to 400 and placed a link at the end where a user can click to view the full announcement. However, this displays on all announcements, regardless of length.

How can I set it to where the link only shows when the announcement is cut off / over 400 characters?

Here is my XSL:

                    <table> 
                    <tr><td>
                        <xsl:variable name="SafeLinkUrl">
                            <xsl:call-template name="OuterTemplate.GetSafeLink">
                                <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
                            </xsl:call-template>
                        </xsl:variable>
                        <h3><a href="{$SafeLinkUrl}"><xsl:value-of select="@MyTitle"/></a></h3>         
                    </td></tr>
                    <tr><td>
                        <xsl:variable name="SafeLinkUrl">
                            <xsl:call-template name="OuterTemplate.GetSafeLink">
                                <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
                            </xsl:call-template>
                        </xsl:variable>
            <xsl:value-of disable-output-escaping="yes" select="substring(@MyDesc,1,400)" /> - <a href="{$SafeLinkUrl}">[Full Announcement]</a><br /></td></tr>
                    <tr>
                        <td> 

                        </td>
                    </tr>
                </table>
share|improve this question

1 Answer 1

up vote 0 down vote accepted

You'd want to wrap that in an if, something along the lines of this:

<xsl:if test="string-length(@MyDesc) &gt; 400">
<xsl:value-of disable-output-escaping="yes" select="substring(@MyDesc,1,400)" /> - <a href="{$SafeLinkUrl}">[Full Announcement]</a><br />
</xsl:if>
share|improve this answer
    
That works! I had to put it before the start of the link or it would hide all the articles that were less than 400 characters. <xsl:value-of disable-output-escaping="yes" select="substring(@MyDesc,1,400)" /> <xsl:if test="string-length(@MyDesc) &gt; 400"> - <a href="{$SafeLinkUrl}">[Full Announcement]</a><br /> </xsl:if> –  Jim Jul 23 at 17:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.