2

私の 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 で、これらのフィールドが必要に応じてstatusRating1css クラスを受け取ることがわかります (フィールドの値を受け取るようにすべて設定されているため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したがって、属性の名前を取得しているだけで、ノードの値を参照していないと推測します。その特定のノードの値を参照する必要があります。

4

2 に答える 2

1

使用:

<xsl:variable name="currentValue" select="$thisNode/*[name()=current()/@Name]"/>

または、代わりに:

<xsl:variable name="currentValue" select="$thisNode/*[name()=$thisNode/@Name]"/>

または、代わりに(最良)

<xsl:variable name="currentValue" select="*[name()=current()/@Name]"/>
于 2012-12-27T17:52:32.500 に答える
0

ああ、何時間も何時間も何日も何ヶ月も経った後、ここに例があります(このスレッドの助けを借りて自分自身をいじりました):

これらの2行が鍵です(ディミトレの答えは近かったです):

<xsl:param name="thisNode" select="."/>
<xsl:variable name="currentValue" select="$thisNode/@*[name()=current()/@Name]" />

これは、2 つの異なる列を読み取り、値をいずれかに適用する関数全体です。

<xsl:template match="FieldRef[@Name='YesNo1']|FieldRef[@Name='YesNo2']" mode="body">
    <xsl:param name="thisNode" select="."/>

    <xsl:variable name="currentValue" select="$thisNode/@*[name()=current()/@Name]" />
    <xsl:variable name="yesvalue">Yes</xsl:variable>
    <xsl:variable name="novalue">No</xsl:variable>

    <xsl:choose>
        <xsl:when test="contains($currentValue, $yesvalue)">
            <span class="yesno yes"><xsl:value-of select="$currentValue" /></span>
        </xsl:when>
        <xsl:when test="contains($currentValue, $novalue)">
            <span class="yesno no"><xsl:value-of select="$currentValue" /></span>
        </xsl:when>
    <xsl:otherwise>
            <span class="yesnoN"><xsl:value-of select="$currentValue" /></span>
        </xsl:otherwise>
    </xsl:choose>

</xsl:template> 
于 2013-08-04T04:17:15.300 に答える