XSLT: how to exit the "for everyone" cycle if the condition is met

How to exit the "for everyone" cycle in XSL if the condition is met? For example, suppose XSL should display the address of apartments that have (2 bedrooms and rental <= 1000) in the following XML, the following XSL code:

<xsl:for-each select="//apartment/apartment_details">
  <xsl:if test="bedrooms=$bedrooms and rent &lt;= $budget "> 
    <!--display apartment address--> 
  </xsl:if>
</xsl:for-each>

will return the same apartment address twice. I want to display the address of the apartment only once, even if for an apartment that satisfies the condition, several.

XML structure:

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

Thank.

+3
source share
2 answers

How to exit the "for everyone" cycle in XSL if the condition is met?

. XSLT xsl:for-each . , , , .

<xsl:for-each select=
 "/*/apartment
      [apartment_details[bedrooms=$bedrooms and $budget  >= rent]]">
  <!-- output apartment address here -->  
</xsl:for-each>

apartment, XML apartment_details, bedrooms rent true(), : bedrooms=$bedrooms and $budget >= rent

+4

, , :

<xsl:value-of select="NODE[CRITERIA][1]">
0

All Articles