title: How to correctly implement the if-else condition in XSLT?
body: <p>I have XML in which there is a ContactRecords node:</p>
  <pre><code>&lt;Organisations&gt;
  &lt;Organisation&gt;
  &lt;Tag1&gt;ValueElementTag1&lt;/Tag1&gt;
  &lt;Tag2&gt;ValueElementTag2&lt;/Tag2&gt;
  &lt;Tag3&gt;ValueElementTag3&lt;/Tag3&gt;
  &lt;ContactRecords&gt;
              &lt;item&gt;
                  &lt;ContactRecordType&gt;AAAAA&lt;/ContactRecordType&gt;
                  &lt;ContactValue&gt;ValueAAAAA&lt;/ContactValue&gt;
                  &lt;Address xmlns=&quot;http://www.v8.1c.ru/ssl/contactinfo&quot; xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;
                      &lt;AdrTag1 xsi:type=&quot;Adr&quot;&gt;Example1&lt;/AdrTag1&gt;
                      &lt;AdrTag2&gt;Example2&lt;/AdrTag2&gt;
                  &lt;/Address&gt;
              &lt;/item&gt;
              &lt;item&gt;
                  &lt;ContactRecordType&gt;BBBBB&lt;/ContactRecordType&gt;
                  &lt;ContactValue&gt;ValueBBBBB&lt;/ContactValue&gt;
                  &lt;Address xmlns=&quot;http://www.v8.1c.ru/ssl/contactinfo&quot; xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;
                      &lt;AdrTag1 xsi:type=&quot;Adr&quot;&gt;Example1&lt;/AdrTag1&gt;
                      &lt;AdrTag2&gt;Example2&lt;/AdrTag2&gt;
                  &lt;/Address&gt;
              &lt;/item&gt;
              &lt;item&gt;
                  &lt;ContactRecordType&gt;CCCCC&lt;/ContactRecordType&gt;
                  &lt;ContactValue&gt;ValueCCCCC&lt;/ContactValue&gt;
              &lt;/item&gt;
  &lt;/ContactRecords&gt;
  &lt;/Organisation&gt;
  &lt;Organisation&gt;
  &lt;Tag1&gt;ValueElementTag1&lt;/Tag1&gt;
  &lt;Tag2&gt;ValueElementTag2&lt;/Tag2&gt;
  &lt;Tag3&gt;ValueElementTag3&lt;/Tag3&gt;
  &lt;ContactRecords&gt;
              &lt;item&gt;
                  &lt;ContactRecordType&gt;AAAAA&lt;/ContactRecordType&gt;
                  &lt;ContactValue&gt;ValueAAAAA&lt;/ContactValue&gt;
                  &lt;Address xmlns=&quot;http://www.v8.1c.ru/ssl/contactinfo&quot; xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;                    
                      &lt;AdrTag1 xsi:type=&quot;Adr&quot;&gt;Example1&lt;/AdrTag1&gt;
                      &lt;AdrTag2&gt;Example2&lt;/AdrTag2&gt;
                  &lt;/Address&gt;
              &lt;/item&gt;
              &lt;item&gt;
                  &lt;ContactRecordType&gt;BBBBB&lt;/ContactRecordType&gt;
                  &lt;ContactValue&gt;ValueBBBBB&lt;/ContactValue&gt;
                  &lt;Address xmlns=&quot;http://www.v8.1c.ru/ssl/contactinfo&quot; xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;
                      &lt;AdrTag1 xsi:type=&quot;Adr&quot;&gt;Example1&lt;/AdrTag1&gt;
                      &lt;AdrTag2&gt;Example2&lt;/AdrTag2&gt;
                  &lt;/Address&gt;
              &lt;/item&gt;
              &lt;item&gt;
                  &lt;ContactRecordType&gt;CCCCC&lt;/ContactRecordType&gt;
                  &lt;ContactValue&gt;ValueCCCCC&lt;/ContactValue&gt;
              &lt;/item&gt;
  &lt;/ContactRecords&gt;
  &lt;/Organisation&gt;
  &lt;/Organisations&gt;
  </code></pre>
  <p>I am writing an XSLT which has a handling of a ContactRecords node:</p>
  <pre><code>&lt;xsl:transform version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;&gt;
  
  &lt;xsl:template match=&quot;/&quot;&gt; 
  
  
  &lt;xsl:element name=&quot;Organisations&quot;&gt;
      &lt;xsl:for-each select=&quot;Organisations/Organisation&quot;&gt;
          &lt;xsl:element name=&quot;{name(.)}&quot;&gt;
                &lt;xsl:for-each select=&quot;*[not(name()='ContactRecords')]&quot;&gt;
                     &lt;xsl:copy select=&quot;*&quot;&gt;
                         &lt;xsl:value-of select=&quot;normalize-space(.)&quot;/&gt;
                     &lt;/xsl:copy&gt;
                &lt;/xsl:for-each&gt;
                &lt;xsl:for-each select=&quot;ContactRecords/item&quot;&gt;
                  &lt;xsl:choose&gt;
                       &lt;xsl:when test=&quot;Address&quot;&gt;
                           &lt;h2&gt;mooooooooooooo&lt;/h2&gt;
                       &lt;/xsl:when&gt;
                       &lt;xsl:otherwise&gt;
                           &lt;h2&gt;dooooooooooooo&lt;/h2&gt;
                       &lt;/xsl:otherwise&gt;
                  &lt;/xsl:choose&gt;
                ​​&lt;/xsl:for-each&gt;
        ​&lt;/xsl:element&gt;
     ​&lt;/xsl:for-each&gt;
  &lt;/xsl:element&gt;
  
  &lt;/xsl:template&gt;
  
  &lt;/xsl:transform&gt;
  </code></pre>
  <p>I am now getting the following result:</p>
  <pre><code>&lt;h2&gt;dooooooooooooo&lt;/h2&gt;
  &lt;h2&gt;dooooooooooooo&lt;/h2&gt;
  ​​&lt;h2&gt;dooooooooooooo&lt;/h2&gt;
  </code></pre>
  <p>I expect to receive:</p>
  <pre><code>&lt;h2&gt;mooooooooooooo&lt;/h2&gt;
  &lt;h2&gt;mooooooooooooo&lt;/h2&gt;
  ​​&lt;h2&gt;dooooooooooooo&lt;/h2&gt;
  </code></pre>
  <p>What am I doing wrong?</p>
  <p>If I explain the algorithm in words, then I need the following: if there is an Address element in the item element, then we do logic number 1. If there is no Address element in the item element, then we do logic number 2.</p>
  <p>If we describe the algorithm in pseudocode, then this is how:</p>
  <pre><code>if (item.includes(Address)) {
   do logic #1
  } else {
   do logic #2
  }
  </code></pre>
  <p>UPD1: Updated XML and XSLT code
  UPD2: Add namespaces in tags Address (maybe the reason is in them)</p>