截断sharepoint中的文本字符串

截断sharepoint中的文本字符串,sharepoint,xslt,sharepoint-2007,Sharepoint,Xslt,Sharepoint 2007,我正在使用此脚本截断sharepoint 2007中的文本字符串,但它不起作用,我不明白为什么?!非常感谢您提出的任何想法 从Header.xsl <xsl:template name="fixedstring"> <xsl:param name="targetVar"> <xsl:param name="allowablelength"> <xsl:value-of select="substring($targetVar, 1, $allowable

我正在使用此脚本截断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) &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>

从我的初始外观来看,“50”似乎不是以字符串形式发送的,请用单引号将其括起来

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

或者因为它是一个数字,所以显式地将其转换为数字

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

从我的初始外观来看,“50”似乎不是以字符串形式发送的,请用单引号将其括起来

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

或者因为它是一个数字,所以显式地将其转换为数字

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

好的,首先,您使用嵌套是完全错误的。您的
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) &gt; $allowablelength">
    <xsl:text>...</xsl:text>
  </xsl:if>
</xsl:template>

...



注意,中有一个连字符。

好的,首先,您使用的嵌套是错误的。您的
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) &gt; $allowablelength">
    <xsl:text>...</xsl:text>
  </xsl:if>
</xsl:template>

...



注意,其中有一个连字符。

我知道这是一个旧线程,但它让我开始解决一个问题,我想我会把我的结果放在这里,供将来的人参考

我们正在使用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) &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>

我知道这是一条老线索,但它让我开始解决一个问题,我想我会把我的结果放在这里,供将来的人参考

我们正在使用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) &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>

“它不起作用”并不是一件非常具体的事情。什么不起作用?它在做什么,你希望它做什么?基本上webparts ItemStyle提要拒绝呈现..我希望它将字符串“@Reason_x005F_x0020_Not_x005F_x0020_Green”截断为最多50个字符,并在末尾加上一个eplisis。“它不工作”不是一件非常具体的事情。什么不起作用?它在做什么,你希望它做什么?基本上webparts ItemStyle提要拒绝呈现..我希望它截断字符串“@Reason\u x005F\u x0020\u Not\u x005F\u x0020\u Green”最多50个字符,结尾有一个eplisis。它不应该是
$Reason\u x005F\u x0020\u不是\u x005F\u x0020\u Green
而不是以
@
开头吗?它不应该是
$Reason\u x005F\u x0020\u不是\u x005F\u x0020\u Green
而不是以
开头吗?