2009-09-17 108 views
1

我正在使用此脚本截断sharepoint 2007中的文本字符串,但它不起作用,我看不出原因?!任何想法提供非常赞赏。截断sharepoint中的文本字符串

从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> 

从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> 
+1

“它不工作”是不是一个很具体的事情。什么不行?它在做什么,你期望它做什么? – Welbog 2009-09-17 14:53:57

+0

基本上webparts ItemStyle提要拒绝渲染.. – toomanyairmiles 2009-09-17 14:57:36

+0

我期望它截断字符串“@ Reason_x005F_x0020_Not_x005F_x0020_Green”到最后一个eplisis最多50个字符。 – toomanyairmiles 2009-09-17 14:59:33

回答

1

从我最初看,它看起来像 “50” 则不会发送一个字符串,它包在单引号。

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

或因为它是一个数字,明确地将它转换为这样的

<xsl:with-param name="allowablelength" select="number(50)"></xsl:with-param> 
3

OK,对于初学者来说,你使用嵌套都错了。您的paramwith-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) &gt; $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中有一个连字符。

+0

不应该是'$ Reason_x005F_x0020_Not_x005F_x0020_Green'而不是以'@'开头吗? – Annie 2013-01-22 09:43:28

1

我知道这是一个古老的线程,但它让我开始解决一个问题,我想我会把我的结果放在这里为将来的人。

我们正在使用SharePoint 2010企业级搜索和结果页面我需要从中心缩短网址并包含突出显示。当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) &lt; $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) &lt; ($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>