3

XSLT では、'if' に関してコードを DRY に保つための推奨される方法は何ですか?

現時点で私はこれをやっています:

<xsl:if test="select/some/long/path">
    <element>
        <xsl:value-of select="select/some/long/path" />
    </element>
</xsl:if>

「select/some/long/path」は一度だけ書きたいと思います。

4

2 に答える 2

6

あなたの言ってる事がわかります。パスの長さが 200 文字の場合、コードが乱雑になる可能性があります。

変数に追加するだけです

<xsl:variable name="path" select="select/some/long/path"/>

<xsl:if test="$path">    
   <xsl:value-of select="$path" />
</xsl:if>
于 2009-08-26T09:50:33.347 に答える
0

次の違いはどこにありますか。

<xsl:if test="select/some/long/path">
  <xsl:value-of select="select/some/long/path" />
</xsl:if>

<xsl:value-of select="select/some/long/path" />

? 存在しない場合、value-of は空の文字列を出力します (つまり、何もありません)。では、なぜテストを?

于 2009-08-26T10:12:30.603 に答える