title: XSLT for parsing 2 pars XML document
body: <p>I have this soap answer file, coming from financials.</p>
  
  <pre><code>&lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
      &lt;soap:Body&gt;
          &lt;RequestRecordAsXmlResponse xmlns="http://xml.thomson.com/financial/v1/tools/distribution/dataworks/enterprise/2003-07/"&gt;
              &lt;RequestRecordAsXmlResult&gt;
                  &lt;Record&gt;
                      &lt;Source&gt;Datastream&lt;/Source&gt;
                      &lt;Instrument&gt;TOTMKEU&lt;/Instrument&gt;
                      &lt;StatusType&gt;Connected&lt;/StatusType&gt;
                      &lt;StatusCode&gt;0&lt;/StatusCode&gt;
                      &lt;StatusMessage/&gt;
                      &lt;Fields&gt;
                          &lt;CCY&gt;U$&lt;/CCY&gt;
                          &lt;DATE&gt;
                              &lt;Item&gt;2014-01-06T00:00:00&lt;/Item&gt;
                              &lt;Item&gt;2014-01-07T00:00:00&lt;/Item&gt;
                              &lt;Item&gt;2014-01-08T00:00:00&lt;/Item&gt;
                              &lt;Item&gt;2014-01-09T00:00:00&lt;/Item&gt;
                              &lt;Item&gt;2014-01-10T00:00:00&lt;/Item&gt;
  
                          &lt;/DATE&gt;
                          &lt;DISPNAME&gt;EU-DS Market&lt;/DISPNAME&gt;
                          &lt;FREQUENCY&gt;D&lt;/FREQUENCY&gt;
                          &lt;P&gt;
                              &lt;Item&gt;1740.46&lt;/Item&gt;
                              &lt;Item&gt;1749.02&lt;/Item&gt;
                              &lt;Item&gt;1749.66&lt;/Item&gt;
                              &lt;Item&gt;1742.87&lt;/Item&gt;
                              &lt;Item&gt;1761.12&lt;/Item&gt;
                          &lt;/P&gt;
                          &lt;SYMBOL&gt;TOTMKEU&lt;/SYMBOL&gt;
                      &lt;/Fields&gt;
                  &lt;/Record&gt;
              &lt;/RequestRecordAsXmlResult&gt;
          &lt;/RequestRecordAsXmlResponse&gt;
      &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>I want to create the xml output : </p>
  
  <pre><code>&lt;results&gt;
    &lt;result&gt;
      &lt;tmstp&gt;2014-01-07T00:00:00&lt;/tmstp&gt;
      &lt;val&gt;1740.46&lt;/val&gt;
    &lt;/result&gt;
    &lt;result&gt;
      &lt;tmstp&gt;2014-01-08T00:00:00&lt;/tmstp&gt;
      &lt;val&gt;1749.02&lt;/val&gt;
    &lt;/result&gt; etc ...
  </code></pre>
  
  <p>I tried a lot of things but failed to do it completely.
  I'm only able to process one of the two nodes (DATE or P), never the two.</p>
  
  <p>My last attemps was to iterate on the node DATE to get the dates (Item) then using the position() function in order to go grab the corresponding item in the node P. Like this : </p>
  
  <pre><code>&lt;xslt:stylesheet xmlns:xslt="http://www.w3.org/1999/XSL/Transform" xmlns:csw-xform="http://www.compositesw.com/2003/xform" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://xml.thomson.com/financial/v1/tools/distribution/dataworks/enterprise/2003-07/" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0"&gt;
    &lt;xslt:template match="/"&gt;
      &lt;xslt:variable name="_tmstp"/&gt;
      &lt;xslt:variable name="_val"/&gt;
      &lt;xslt:element name="results"&gt;
        &lt;xslt:for-each select="soap-env:Envelope/soap-env:Body/ns1:RequestRecordAsXmlResponse/ns1:RequestRecordAsXmlResult/ns1:Record/ns1:Fields"&gt;
          &lt;xslt:for-each select="ns1:DATE"&gt;
            &lt;xslt:for-each select="ns1:Item"&gt;
              &lt;xslt:variable name="_tmstp" select="."/&gt;
              &lt;xslt:variable name="_val" select="soap-env:Envelope/soap-env:Body/ns1:RequestRecordAsXmlResponse/ns1:RequestRecordAsXmlResult/ns1:Record/ns1:Fields/ns1:P/ns1:Item[position()]"/&gt;
              &lt;xslt:element name="result"&gt;
                &lt;xslt:element name="tmstp"&gt;
                  &lt;xslt:value-of select="$_tmstp"/&gt;
                &lt;/xslt:element&gt;
                &lt;xslt:element name="val"&gt;
                  &lt;xslt:value-of select="$_val"/&gt;
                &lt;/xslt:element&gt;
              &lt;/xslt:element&gt;
            &lt;/xslt:for-each&gt;
          &lt;/xslt:for-each&gt;
        &lt;/xslt:for-each&gt;
      &lt;/xslt:element&gt;
    &lt;/xslt:template&gt;
  &lt;/xslt:stylesheet&gt;
  </code></pre>
  
  <p>But it failed.
  I also used xslt "loops" but didn't have much success : the "tmstp" value is ok but the "val" (second node = P) still is null.</p>
  
  <p>Can you please help for that ?
  After a lot of research, trial, errors, I'm stuck on this thing that I feel simple but that is definitely stronger than me today.</p>
  
  <p>Thanks a lot
  Vincent</p>