2012-07-03 13 views
1

如果我定義的變量不等於特定的字符串,我想取值。在這裏,如果它們分別與「湯姆」,「街道」和「城市街道」不相等,則我想採用「 - 」分隔的變量「名稱」,「地址」和「城市」的值。那可能嗎?檢查<xsl:value-of>內的條件

xsl:attribute name='person'> 
     <xsl:value-of separator="-" select= 
    "($name, $address, 
    $city)" /> 
     </xsl:attribute> 

回答

1

你可以使用你的變數謂詞:

<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> 
+0

謝謝,但這個工作ks只有三個都滿意。我只想避免某個特定變量的值不等於不需要的字符串。假如名字是湯姆,應避免變量名的值,輸出應該像「someAddress-someCity」。 – harsh

+0

@harsh - 請參閱我的更新。 –

+0

非常感謝! :) – harsh

1

使用

<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> 
+0

+1表示與ne ..謝謝! :) – harsh

+1

@harsh:更重要的是,'test'屬性中的表達式是正確的 - 與已接受的答案中的表達式不同,它要求所有三個變量與特定值不同 - 您指示的內容不是需要。 –

+0

是的,當然,非常感謝您指出了這一點。你的測試條件給出我想要的。 – harsh