0

I have written the following code which checks whether the string provided is greater than 1- characters in which case only print the first 10 characters, otherwise print complete string. But I am getting error "Unable to display this web part" probably due to some bug in my syntax. Please check.

<xsl:template name="ShortenDetail">
    <xsl:param name="String">
        <xsl:choose>
            <xsl:when test="string-length($String) &gt; '10'">
                <xsl:value-of select="substring($String, 0,9)"></xsl:value-of>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$String"></xsl:value-of>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:param>
</xsl:template>

EDIT
And please also tell me how to use this function within a function in xslt. Following is the code which I am already using in my XSLT. This function cleans the "Detail" column that I am receiving from list and then after that I want to apply ShortenDetail function (mentioned above) but I don't know how to do that.

<xsl:call-template name="RemoveHtml">
       <xsl:with-param name="String" select="@Detail"/>
</xsl:call-template>

I tried using like this but getting error:

<xsl:call-template name="ShortenDetail">
     <xsl:call-template name="RemoveHtml">
           <xsl:with-param name="String" select="@Detail"/>
     </xsl:call-template>
</xsl:call-template>

1 Answer 1

2

The way you have this written at the moment you seem to be trying to set the value of the parameter. I think the parameter tag should be closed before you start the choose.

EDIT: to reflect the changes to the question - I think this is what you are trying to achieve?

<xsl:template name="ShortenDetail">
    <xsl:variable name="String">
        <xsl:call-template name="RemoveHtml">
            <xsl:with-param name="String" select="@Detail"/>
        </xsl:call-template>
    </xsl:variable>
    <xsl:choose>
        <xsl:when test="string-length($String) &gt; '10'">
            <xsl:value-of select="substring($String, 0,9)"></xsl:value-of>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$String"></xsl:value-of>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
1
  • Thanks. Need to ask one more thing. Can't post code here as there would be no formatting so I have edited my question above. Please check. Jul 29, 2013 at 6:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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