views:

344

answers:

2

I'm using this script to truncate a text string in sharepoint 2007, but it doesn't work and I can't see why?! Any ideas offered greatly appreciated.

From Header.xsl

<xsl:template name="fixedstring">
<xsl:param name="targetVar">
<xsl:param name="allowablelength">
<xsl:value-of select="substring($targetVar, 1, $allowablelength)">
<xsl:if test="stringlength($targetVar) &gt; $allowablelength">
<xsl:text>...</xsl:text>
</xsl:if>
</xsl:value-of></xsl:param></xsl:param>
</xsl:template>

From ItemStyle.xsl

<xsl:call-template name="fixedstring">
<xsl:with-param name="targetVar">
<xsl:value-of select="@Reason_x005F_x0020_Not_x005F_x0020_Green"/>
<xsl:with-param name="allowablelength" select="50"></xsl:with-param>
</xsl:with-param>
</xsl:call-template>
A: 

From my initial look, it looks like the "50" is not sent as a string, wrap it in single quotes.

<xsl:with-param name="allowablelength" select="'50'"></xsl:with-param>

or since it is a number, explicitly cast it as such

<xsl:with-param name="allowablelength" select="number(50)"></xsl:with-param>
Thiyagaraj
+1  A: 

OK, for starters, you're using nesting all wrong. Your param and with-param elements shouldn't be nested that way. Replace what you have with this:

<xsl:template name="fixedstring">
  <xsl:param name="targetVar"/>
  <xsl:param name="allowablelength"/>
  <xsl:value-of select="substring($targetVar, 1, $allowablelength)"/>
  <xsl:if test="string-length($targetVar) &gt; $allowablelength">
    <xsl:text>...</xsl:text>
  </xsl:if>
</xsl:template>

and

<xsl:call-template name="fixedstring">
  <xsl:with-param name="targetVar">
    <xsl:value-of select="@Reason_x005F_x0020_Not_x005F_x0020_Green"/>
  </xsl:with-param>
  <xsl:with-param name="allowablelength" select="50"/>
</xsl:call-template>

Note the string-length has a hyphen in it.

Welbog