如果我定義的變量不等於特定的字符串,我想取值。在這裏,如果它們分別與「湯姆」,「街道」和「城市街道」不相等,則我想採用「 - 」分隔的變量「名稱」,「地址」和「城市」的值。那可能嗎?檢查<xsl:value-of>內的條件
xsl:attribute name='person'>
<xsl:value-of separator="-" select=
"($name, $address,
$city)" />
</xsl:attribute>
如果我定義的變量不等於特定的字符串,我想取值。在這裏,如果它們分別與「湯姆」,「街道」和「城市街道」不相等,則我想採用「 - 」分隔的變量「名稱」,「地址」和「城市」的值。那可能嗎?檢查<xsl:value-of>內的條件
xsl:attribute name='person'>
<xsl:value-of separator="-" select=
"($name, $address,
$city)" />
</xsl:attribute>
你可以使用你的變數謂詞:
<xsl:attribute name='person'>
<xsl:value-of separator="-" select="($name[.!='Tom'], $address[.!='Street'],$city[.!='CityStreet'])"/>
</xsl:attribute>
或者這個,如果你不想要一個空的屬性:
<xsl:if test="$name != 'Tom' and
$address != 'Street' and
$city != 'CityStreet'">
<xsl:attribute name="person">
<xsl:value-of separator="-" select="($name[.!='Tom'], $address[.!='Street'],$city[.!='CityStreet'])"/>
</xsl:attribute>
</xsl:if>
使用:
<xsl:if test=
"not($name eq 'Tom' and $address eq 'Street' and $city eq 'CityStreet')">
<xsl:attribute name="person">
<xsl:value-of separator="-" select=
"($name[. ne 'Tom'], $address[. ne 'Street'], $city[. ne 'CityStreet'])"/>
</xsl:attribute>
</xsl:if>
謝謝,但這個工作ks只有三個都滿意。我只想避免某個特定變量的值不等於不需要的字符串。假如名字是湯姆,應避免變量名的值,輸出應該像「someAddress-someCity」。 – harsh
@harsh - 請參閱我的更新。 –
非常感謝! :) – harsh