0

私はxsltにかなり慣れていません

次の xslt スニペットがあります (わかりやすくするために疑似的にしています)。

<xsl:for-each select="fields/field">
  <xsl:if test="field=someThing">
    <div>
      <!--some content output-->
      <!--here by doing-->
      <!--some complex stuff-->
    </div>
  </xsl:if>
</xsl:for-each>

しかし、ループからのフィールドの値に基づいて、必要に応じて、最後の div の前に他のことをしたいと考えています。

だから(ピカピカの新しいxsl本で武装して)私は次のようなことができると思った:

<xsl:for-each select="fields/field">
  <xsl:if test="field=someThing">
    <div>
      <!--some content output-->
      <!--here by doing-->
      <!--some complex stuff-->
    <xsl:choose>
      <xsl:when test="field=someThingSpecific">
        <div>
        <!--process some additional-->
        <!--stuff here-->
        </div>
        <!--then close div-->
        </div>
      </xsl:when>
      <xsl:otherwise>
        <!--nothing to do here-->
        <!--just close the div-->
        </div>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:if>
</xsl:for-each>

しかし、それは爆発します。

どうやら、終了 div が条件付き xsl:choose ブロックに移動したためです。

だから本当に2つの質問:

なぜそのままでは動作しないのですか?

どうすれば目的を達成できますか?

4

1 に答える 1

0

XSLT の形式が整っていないため、問題が発生しています。divの外側で最初の を開いたら、 の外側でxsl:choose閉じなければなりませんxsl:choose

また、 で何もする必要がない場合は、xsl:otherwise別のことをしてくださいxsl:if:

<xsl:for-each select="fields/field">
    <xsl:if test="field=someThing">
        <div>
            <!--some content output-->
            <!--here by doing-->
            <!--some complex stuff-->
            <xsl:if test="field=someThingSpecific">
                <div>
                    <!--process some additional-->
                    <!--stuff here-->
                </div>
            </xsl:if>
            <!--then close div-->
        </div>
    </xsl:if>
</xsl:for-each>
于 2012-08-06T01:21:19.883 に答える