locked
CQWP Custom XSLT error RRS feed

  • Question

  • Hello,

    Very basic question.

    I'm trying to create a very basic "news feed" with an icon selected when creating the "news story".

    I've copied a template (Image Right) in the ItemStyle.xsl and renamed it, and then added a blank CQWP to a page, which uses that template. So far so good! next i want to only display the first 100 or so characters of the main body text.

    When i change the following (see below), it works fine on the page, but when i click "edit web part" i get the standard "ERROR: And unexpected error has occured" and cannot view the properties of the CQWP.

    All i do is change this:

    <xsl:value-of select="@Description" />

    to this:

    <xsl:if test="string-length(@Description) != 0">
    	<span class="blog-content-newsfeed">
    		<xsl:value-of select="concat(substring(@Description, 0, 110), '&hellip;')" disable-output-escaping="yes" />
    	</span>
    </xsl:if>

    What am i doing wrong? Is it because the variable is within an "IF" statement, and this causes SharePoint to freak out? If so, how can i get around this?

    Thanks,

    B

    Saturday, March 16, 2013 4:50 PM

Answers

  • Try this (it tests the length of the string is over 110 before calling substring, which would throw an index out of range error if the string isn't over 110 characters).

    <div class="description">
        <xsl:choose>
    		<xsl:when test="string-length(@Description) &gt; 110">							
    			<xsl:value-of select="concat(substring(@Description,0,110), '&hellip;')" disable-output-escaping="yes" />                					
    		</xsl:when>
    		<xsl:otherwise>
    			<xsl:value-of select="@Description" disable-output-escaping="yes"/>
    		</xsl:otherwise>
    	</xsl:choose>  
    </div>


    Regards, Matthew
    MCPD | MCITP
    My Blog
    Please remember to click "Mark As Answer" if a post solves your problem or "Vote As Helpful" if it was useful.


    Monday, March 18, 2013 4:20 PM

All replies

  • Anyone? Even a pointer would be a big help..
    Monday, March 18, 2013 3:55 PM
  • Try this (it tests the length of the string is over 110 before calling substring, which would throw an index out of range error if the string isn't over 110 characters).

    <div class="description">
        <xsl:choose>
    		<xsl:when test="string-length(@Description) &gt; 110">							
    			<xsl:value-of select="concat(substring(@Description,0,110), '&hellip;')" disable-output-escaping="yes" />                					
    		</xsl:when>
    		<xsl:otherwise>
    			<xsl:value-of select="@Description" disable-output-escaping="yes"/>
    		</xsl:otherwise>
    	</xsl:choose>  
    </div>


    Regards, Matthew
    MCPD | MCITP
    My Blog
    Please remember to click "Mark As Answer" if a post solves your problem or "Vote As Helpful" if it was useful.


    Monday, March 18, 2013 4:20 PM
  • Thank you, Matthew!

    Worked perfectly.

    Tuesday, March 19, 2013 10:25 AM
  • I spoke too soon.. Even with your code, which works fine when viewing the page, breaks it when "edit page" is selected:

    Error

    An unexpected error has occurred.

    Web Parts Maintenance Page: If you have permission, you can use this page to temporarily close Web Parts or remove personal settings. For more information, contact your site administrator.

    Troubleshoot issues with Microsoft SharePoint Foundation.

    Correlation ID: a99068b5-f011-46f8-8a72-57017da6b6fb

    The error goes away when i revert to the default:

    <div class="description">
         <xsl:value-of select="@Description" />
    </div>
    


    Tuesday, March 19, 2013 10:38 AM
  • It turns out the '&hellip;' was the issue.

    When i removed this and replaced it with '...' there was no error upon editing the web part.

    Tuesday, March 19, 2013 11:57 AM
  • Strange, I don't have an issue using &hellip; on my test environment! The joys of XSL!

    Regards, Matthew
    MCPD | MCITP
    My Blog
    Please remember to click "Mark As Answer" if a post solves your problem or "Vote As Helpful" if it was useful.

    Tuesday, March 19, 2013 12:24 PM