title: Multiple Condition in XSLT not working
body: <p>I have the following XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;bp_list xmlns="http://example.com/2012/03/01/canonical/BusinessPartner"&gt;
  &lt;total_count&gt;221&lt;/total_count&gt;
  &lt;bp&gt;
      &lt;bp_id&gt;10&lt;/bp_id&gt;
      &lt;bp_name&gt;aad&lt;/bp_name&gt;
      &lt;last_changed_date&gt;2016-12-20T02:38:14&lt;/last_changed_date&gt;
      &lt;location&gt;
          &lt;location_id&gt;200020&lt;/location_id&gt;
          &lt;location_name&gt;gfh&lt;/location_name&gt;
          &lt;is_location_owner&gt;true&lt;/is_location_owner&gt;
          &lt;location_registration_status&gt;
              &lt;registration_status_id&gt;7202&lt;/registration_status_id&gt;
              &lt;registration_status_name&gt;Unregistered&lt;/registration_status_name&gt;
              &lt;registration_status_effective_date&gt;2015-07-24T00:00:00&lt;/registration_status_effective_date&gt;
          &lt;/location_registration_status&gt;
          &lt;location_status&gt;
              &lt;name&gt;In Progress&lt;/name&gt;
          &lt;/location_status&gt;
          &lt;marked_for_delete&gt;false&lt;/marked_for_delete&gt;
          &lt;bp_location&gt;
              &lt;bp&gt;
                  &lt;bp_id&gt;10&lt;/bp_id&gt;
              &lt;/bp&gt;
              &lt;bp_location_capability&gt;
                  &lt;is_primary_capability&gt;true&lt;/is_primary_capability&gt;
                  &lt;location_function_capability_category_id&gt;50&lt;/location_function_capability_category_id&gt;
                  &lt;location_function_capability_name&gt;hq&lt;/location_function_capability_name&gt;
              &lt;/bp_location_capability&gt;
              &lt;bp_location_capability&gt;
                  &lt;is_primary_capability&gt;true&lt;/is_primary_capability&gt;
                  &lt;location_function_capability_category_id&gt;53&lt;/location_function_capability_category_id&gt;
                  &lt;location_function_capability_name&gt;Remit To&lt;/location_function_capability_name&gt;
              &lt;/bp_location_capability&gt;
          &lt;/bp_location&gt;
          &lt;address&gt;
              &lt;id&gt;103754&lt;/id&gt;
              &lt;line1&gt;someadress&lt;/line1&gt;
              &lt;city&gt;Columbus&lt;/city&gt;
              &lt;postal_code&gt;47201&lt;/postal_code&gt;
              &lt;country_code&gt;US&lt;/country_code&gt;
              &lt;country_name&gt;UNITED STATES&lt;/country_name&gt;
              &lt;subdivision_code&gt;US-IN     &lt;/subdivision_code&gt;
              &lt;subdivision_name&gt;Indiana&lt;/subdivision_name&gt;
              &lt;validation_status&gt;0&lt;/validation_status&gt;
          &lt;/address&gt;
          &lt;location_type&gt;
              &lt;location_type_id&gt;5003&lt;/location_type_id&gt;
              &lt;location_type_name&gt;Business Office&lt;/location_type_name&gt;
          &lt;/location_type&gt;
          &lt;location_type&gt;
              &lt;location_type_id&gt;5002&lt;/location_type_id&gt;
              &lt;location_type_name&gt;Warehouse&lt;/location_type_name&gt;
          &lt;/location_type&gt;
          &lt;location_capability&gt;
              &lt;location_capability_id&gt;13&lt;/location_capability_id&gt;
              &lt;location_capability_name&gt;Stores Cartons&lt;/location_capability_name&gt;
              &lt;location_capability_category&gt;1&lt;/location_capability_category&gt;
          &lt;/location_capability&gt;
          &lt;location_capability&gt;
              &lt;location_capability_id&gt;50&lt;/location_capability_id&gt;
              &lt;location_capability_name&gt;hq&lt;/location_capability_name&gt;
              &lt;location_capability_category&gt;2&lt;/location_capability_category&gt;
          &lt;/location_capability&gt;
          &lt;location_capability&gt;
              &lt;location_capability_id&gt;53&lt;/location_capability_id&gt;
              &lt;location_capability_name&gt;Remit To&lt;/location_capability_name&gt;
              &lt;location_capability_category&gt;2&lt;/location_capability_category&gt;
          &lt;/location_capability&gt;
      &lt;/location&gt;
      &lt;location&gt;
          &lt;location_id&gt;16677059&lt;/location_id&gt;
          &lt;location_name&gt;ggg(something Co. Ltd)&lt;/location_name&gt;
          &lt;is_location_owner&gt;false&lt;/is_location_owner&gt;
          &lt;location_registration_status&gt;
              &lt;registration_status_id&gt;7202&lt;/registration_status_id&gt;
              &lt;registration_status_name&gt;Unregistered&lt;/registration_status_name&gt;
          &lt;/location_registration_status&gt;
          &lt;location_status&gt;
              &lt;name&gt;In Progress&lt;/name&gt;
          &lt;/location_status&gt;
          &lt;marked_for_delete&gt;false&lt;/marked_for_delete&gt;
          &lt;bp_location&gt;
              &lt;bp&gt;
                  &lt;bp_id&gt;29303&lt;/bp_id&gt;
              &lt;/bp&gt;
          &lt;/bp_location&gt;
          &lt;address&gt;
              &lt;id&gt;122088&lt;/id&gt;
              &lt;line1&gt;No.139 abc.&lt;/line1&gt;
              &lt;line2&gt;down the woods&lt;/line2&gt;
              &lt;city&gt;ff&lt;/city&gt;
              &lt;postal_code&gt;4567&lt;/postal_code&gt;
              &lt;country_code&gt;CN&lt;/country_code&gt;
              &lt;country_name&gt;CHINA&lt;/country_name&gt;
              &lt;subdivision_code&gt;r5     &lt;/subdivision_code&gt;
              &lt;subdivision_name&gt;Fujian&lt;/subdivision_name&gt;
              &lt;validation_status&gt;1702&lt;/validation_status&gt;
          &lt;/address&gt;
          &lt;location_type&gt;
              &lt;location_type_id&gt;5001&lt;/location_type_id&gt;
              &lt;location_type_name&gt;Factory&lt;/location_type_name&gt;
          &lt;/location_type&gt;
          &lt;location_capability&gt;
              &lt;location_capability_id&gt;10&lt;/location_capability_id&gt;
              &lt;location_capability_name&gt;Produces Product&lt;/location_capability_name&gt;
              &lt;location_capability_category&gt;1&lt;/location_capability_category&gt;
          &lt;/location_capability&gt;
      &lt;/location&gt;
      &lt;/bp&gt;
  </code></pre>
  
  <p>I have to take the Line1 and Line 2 of the address where "Is Primary capability" is true and "Location function capability" is hq.</p>
  
  <p>In this particular situation, I should not get anything in line2 because the address does not have any (For the above address that fulfills the condition). However my XSLT is picking up the line2 from the next address. This has me believing that the condition that I have coded is not working.Although I am getting the expected output in Line1, it is only because it it is the very first address. Below is my XSLT:</p>
  
  <pre><code>&lt;xsl:stylesheet version="1.0"     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:ns="http://target.com/2012/03/01/canonical/BusinessPartner"&gt;
  &lt;xsl:strip-space elements="*" /&gt;
  &lt;xsl:output method="text" version="1.0" encoding="UTF-8" indent="yes"/&gt;
  &lt;xsl:template match="/"&gt;bp_name|bp_id|line1|line2
      &lt;xsl:for-each select="ns:bp_list/ns:bp"&gt;
          &lt;xsl:variable name="bp_name" select="normalize-space(ns:bp_name)"/&gt;
          &lt;xsl:value-of select="$bp_name"/&gt;|&lt;xsl:value-of select="normalize-space(ns:bp_id)"/&gt;|&lt;xsl:if test="((ns:location/ns:bp_location/ns:bp_location_capability/ns:is_primary_capability = 'true') and (ns:location/ns:bp_location/ns:bp_location_capability/ns:location_function_capability_name = 'hq'))"&gt; &lt;xsl:value-of select="normalize-space(ns:location/ns:address/ns:line1)"/&gt;&lt;/xsl:if&gt;|&lt;xsl:if test="((ns:location/ns:bp_location/ns:bp_location_capability/ns:is_primary_capability = 'true') and (ns:location/ns:bp_location/ns:bp_location_capability/ns:location_function_capability_name = 'hq'))"&gt; &lt;xsl:value-of select="normalize-space(ns:location/ns:address/ns:line2)"/&gt;&lt;xsl:text&gt;&amp;#xA;&lt;/xsl:text&gt;
      &lt;/xsl:for-each&gt;&lt;/xsl:template&gt;
   &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>What can be the issue here and how can I resolve this?</p>