2

私のSharepointfldtypes_custom.xslファイルには、完全に機能するこのコードがあります。ただし、3 つまたは 4 つの同様のフィールドで同じコードを使用したいと考えています。

同じテンプレートでstatus1OR status2、 ORという名前のフィールドを一致させる方法はありますか? status3今のところ、このコード ブロックのコピーを 3 つ用意する必要があります。唯一の違いは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 または status2、または status3 という名前のフィールドを一致させる方法はありますか?

使用:

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

ただし、提供されたコードから、文字列"status1"とは要素名"status2"ではなく、要素の属性の"status3"可能な値にすぎないことがわかります。NameFieldRef

この場合、テンプレートは次のようになります

<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 に答える