title: xslt copy element value if not null to a new element that may not exist
body: <p>I have an xml below.</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;truck&gt;
     &lt;time1&gt;1234&lt;/time1&gt;
     &lt;time2&gt;5678&lt;/time2&gt;
  &lt;/truck&gt;
  </code></pre>
  <p>I want to copy the value of time2 to time 1 if the time2 value is not empty.
  Time2 and Time 1 are both optional and one or both could not be present.
  If Time 2 is present and has a value I want to override time1 value or create time1 with that element.</p>
  <p>Output from above:</p>
  <pre><code>&lt;truck&gt;
     &lt;time1&gt;5678&lt;/time1&gt;
     &lt;time2&gt;5678&lt;/time2&gt;
  &lt;/truck&gt;
  </code></pre>
  <p>Example 2</p>
  <pre><code>&lt;truck&gt;
     &lt;time2&gt;5678&lt;/time2&gt;
  &lt;/truck&gt;
  </code></pre>
  <p>Example 2 Output</p>
  <pre><code>&lt;truck&gt;
     &lt;time1&gt;5678&lt;/time1&gt;
     &lt;time2&gt;5678&lt;/time2&gt;
  &lt;/truck&gt;
  </code></pre>
  <p>Example 3</p>
  <pre><code>&lt;truck&gt;
     &lt;time1&gt;1234&lt;/time1&gt;
  &lt;/truck&gt;
  </code></pre>
  <p>Example 3 Output</p>
  <pre><code>&lt;truck&gt;
     &lt;time1&gt;1234&lt;/time1&gt;
  &lt;/truck&gt;
  </code></pre>
  <p>I tried this xslt transformation but it didnt work.</p>
  <pre><code>&lt;xsl:template match=&quot;*[local-name()='time2']&quot;&gt;
      &lt;xsl:if test=&quot;not(*[.=''])&quot;&gt;
          &lt;time1&gt;
              &lt;xsl:value-of select=&quot;time2&quot;/&gt;
          &lt;/time1&gt;
          &lt;time2&gt;
              &lt;xsl:value-of select=&quot;time2&quot;/&gt;
          &lt;/time2&gt;
  
      &lt;/xsl:if&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  <p>Thank you in advance.</p>