2

在我的 Sharepointfldtypes_custom.xsl文件中,我有这段代码,它运行良好。但是,我想在三个或四个类似的字段上使用相同的代码。

有没有办法在同一个模板中匹配名为status1OR status2、 OR的字段?status3现在我必须拥有这段代码的三个副本,唯一的区别是fieldref名称。我想整理一下代码。

<xsl:template match="FieldRef[@Name='status1']" mode="body">
    <xsl:param name="thisNode" select="."/>
    <xsl:variable name="currentValue" select="$thisNode/@status1" />
    <xsl:variable name="statusRating1">(1)</xsl:variable>
    <xsl:variable name="statusRating2">(2)</xsl:variable>
    <xsl:variable name="statusRating3">(3)</xsl:variable>

    <xsl:choose>
        <xsl:when test="contains($currentValue, $statusRating1)">
            <span class="statusRatingX statusRating1"></span>
        </xsl:when>
        <xsl:when test="contains($currentValue, $statusRating2)">
            <span class="statusRatingX statusRating2"></span>
        </xsl:when> 
        <xsl:when test="contains($currentValue, $statusRating3)">
            <span class="statusRatingX statusRating3"></span>
        </xsl:when> 
        <xsl:otherwise>
            <span class="statusRatingN"></span>
        </xsl:otherwise>                    
    </xsl:choose>
</xsl:template> 
4

1 回答 1

2

有没有办法在同一个模板中匹配名为 status1 OR status2、OR status3 的字段?

使用

<xsl:template match="status1 | status2 | status3">
  <!-- Your processing here -->
</xsl:template>

但是,我从提供的代码中看到,字符串"status1""status2"不是"status3"元素名称——它们只是元素Name属性的可能值FieldRef

在这种情况下,您的模板可能是

<xsl:template match="FieldRef
     [@Name = 'status1' or @Name = 'status2' or @Name = 'status3']">
  <!-- Your processing here -->
</xsl:template>

如果属性有许多可能的值Name,可以使用以下缩写

<xsl:template match="FieldRef
     [contains('|status1|status2|staus3|', concat('|',@Name, '|'))]">
  <!-- Your processing here -->
</xsl:template>
于 2012-12-27T15:52:42.253 回答