私の xsl では、match
いくつかのノードで、一致したノードの値を変数に取得したいと考えています。どうやってやるの?
以下の代わりにワイルドカード変数を配置する必要がありBudget0
ます。
<xsl:template match="FieldRef[@Name='Budget0' or @Name='Scope' or @Name='Risk' or @Name='Schedule']" mode="body">
<xsl:param name="thisNode" select="."/>
<xsl:variable name="currentValue" select="$thisNode/Budget0" />
<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"><xsl:value-of select="$currentValue" /></span>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
このスニペットでは、xsl:template match...
問題なく動作します。それらのフィールドに一致するようです。Firebug で、これらのフィールドが必要に応じてstatusRating1
css クラスを受け取ることがわかります (フィールドの値を受け取るようにすべて設定されているためBudget0
です。
[アップデート]
これを変数に使用すると、次のことがわかりました。
<xsl:variable name="currentValue" select="current()/@Name" />
また
<xsl:variable name="currentValue" select="FieldRef[@Name=current()/@Name"] />
otherwise
タグに引っ掛かり、フィールドの名前を出力します。言い換えれば、htmlは印刷します
<span class="statusRatingN">Budget0</span>
Dimitre のソリューション (以下) のいずれかを試してみると、どのwhen
句にも一致せず、html は次のように出力されます (スパンのテキストが空白であることに注意してください)。
<span class="statusRatingN"></span>
$currentValue
したがって、属性の名前を取得しているだけで、ノードの値を参照していないと推測します。その特定のノードの値を参照する必要があります。