我正在使用此脚本截断sharepoint 2007中的文本字符串,但它不起作用,我看不出为什么?!任何想法都非常赞赏。
来自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) > $allowablelength">
<xsl:text>...</xsl:text>
</xsl:if>
</xsl:value-of></xsl:param></xsl:param>
</xsl:template>
来自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>
答案 0 :(得分:3)
好的,对于初学者来说,你使用的是错误的嵌套。您的param
和with-param
元素不应该以这种方式嵌套。用这个代替你拥有的东西:
<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) > $allowablelength">
<xsl:text>...</xsl:text>
</xsl:if>
</xsl:template>
和
<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>
注意string-length中有一个连字符。
答案 1 :(得分:1)
从我最初的看,看起来“50”不是作为字符串发送的,用单引号括起来。
<xsl:with-param name="allowablelength" select="'50'"></xsl:with-param>
或者因为它是一个数字,所以明确地将其转换为
<xsl:with-param name="allowablelength" select="number(50)"></xsl:with-param>
答案 2 :(得分:1)
我知道这是一个老线程,但它让我开始解决一个问题,我想我会把我的结果放在这里为某人将来。
我们正在使用SharePoint 2010企业级搜索,对于结果页面,我要求缩短中心的URL并包括突出显示。但是,当缩短URL时突出显示不起作用,并且可能有更简单/更好的方法来执行此操作,但这就是我所做的:
<span class="srch-URL2" id="{concat($currentId,'_Url')}" title="{$url}">
<xsl:call-template name="truncateURL">
<xsl:with-param name="targetURL">
<xsl:value-of select="url"/>
</xsl:with-param>
<xsl:with-param name="allowablelength" select="number(40)"/>
</xsl:call-template>
</span>
<xsl:template name="truncateURL">
<xsl:param name="targetURL"/>
<xsl:param name="allowablelength"/>
<xsl:choose>
<xsl:when test="string-length($targetURL) < $allowablelength">
<xsl:choose>
<xsl:when test="hithighlightedproperties/HHUrl[. != '']">
<xsl:call-template name="HitHighlighting">
<xsl:with-param name="hh" select="hithighlightedproperties/HHUrl" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$targetURL"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="string-length($targetURL) < ($allowablelength+$allowablelength)">
<xsl:choose>
<xsl:when test="hithighlightedproperties/HHUrl[. != '']">
<xsl:call-template name="HitHighlighting">
<xsl:with-param name="hh" select="hithighlightedproperties/HHUrl" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$targetURL"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring($targetURL, 1, $allowablelength)"/>
<xsl:text>…</xsl:text>
<xsl:value-of select="substring($targetURL, (string-length($targetURL)-$allowablelength)+1, $allowablelength)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>