如果满足条件,如何退出 XSL 中的“for-each”循环?例如,假设我希望 XSL 在以下 XML 中显示具有(2 间卧室和租金 <= 1000)的公寓的地址,以下 XSL 代码:
<xsl:for-each select="//apartment/apartment_details">
<xsl:if test="bedrooms=$bedrooms and rent <= $budget ">
<!--display apartment address-->
</xsl:if>
</xsl:for-each>
将返回相同的公寓地址两次。即使满足条件的公寓有多个,我也只想显示一次公寓地址。
XML结构:
<apartments>
<apartment>
<address>
<street>....</street>
<city>....</city>
</address>
<apartment_details>
<bedrooms>2</bedrooms>
<bathrooms>2</bathrooms>
<rent>1000</rent>
</apartment_details>
<apartment_details>
<bedrooms>2</bedrooms>
<bathrooms>1</bathrooms>
<rent>900</rent>
</apartment_details>
...
</apartment>
...
</apartments>
谢谢你。