title: Xquery Get Position()
body: <p>This is a part of our xml file.</p>
  
  <pre><code>                &lt;point distanceTotal="162" seqNo="189"&gt;
                  &lt;lineSection id="395" track="1" direction="1"&gt;
                  &lt;outInfos&gt;
                      &lt;comment commentTypeId="4" priority="1"oneLiner="BOT"&gt;
                          &lt;layerVPK seasonValue="S0"/&gt;
                          &lt;vectors&gt;
                              &lt;vector dateFrom="2016-12-11"/&gt;
                          &lt;/vectors&gt;
                          &lt;frenchText&gt;1x3 MH&lt;/frenchText&gt;
                      &lt;/comment&gt;
                      &lt;comment commentTypeId="4" priority="1" oneLiner="bot"&gt;
                          &lt;layerVPK seasonValue="S0"/&gt;
                          &lt;frenchText&gt;Réception voie occupée&lt;/frenchText&gt;
                          &lt;dutchText&gt;Test&lt;/dutchText&gt;
                      &lt;/comment&gt;
                  &lt;/outInfos&gt;
              &lt;/point&gt;
  </code></pre>
  
  <p>We are uploading this to a SqlServer column and with XQuery we are fetching the values.
  But, I can't find a way to get the position() coded, and basically T-SQL ROW_NUMBER or dense rank can't be used as not always all data exists.
  As example the dutchText only exists on the second comment and there is no field that identifies the 2 comments....</p>
  
  <p>This is the SQL Code</p>
  
  <pre><code>SELECT  fi.file_uid,
          fi.file_date,
          T1.ref.value('@id',           'varchar(100)') AS gTV_id,
          T2.ref.value('@id',           'varchar(100)') AS gTrn_id,
          T4.ref.value('@seqNo',        'varchar(100)') AS gTrnTPp_seqNo,
          T7.ref.value('text()[1]',     'varchar(1000)') AS gTrnTPpOiCDT_Text,
          T6.ref.query('/globalTrainVariant/trains/globalTrainVariant/train/timetablePoints/point/outInfos/comment[position()]') AS Test
     FROM ods.filesin fi
          CROSS APPLY fi.file_xml.nodes('declare namespace cern="http://...";
                                         (/cern:trains/globalTrainVariant)') T1(ref)
          CROSS APPLY T1.ref.nodes('declare namespace cern="http://...";
                                    (train)') T2(ref)
          CROSS APPLY T2.ref.nodes('declare namespace cern="http://...";
                                   (timetablePoints)') T3(ref)
          CROSS APPLY T3.ref.nodes('declare namespace cern="http://...";
                                    (point)') T4(ref)
          CROSS APPLY T4.ref.nodes('declare namespace cern="http://...";
                                    (outInfos)') T5(ref)
          CROSS APPLY T5.ref.nodes('declare namespace cern="http://...";
                                    (comment)') T6(ref)
          CROSS APPLY T6.ref.nodes('declare namespace cern="http://...";
                                    (dutchText)') T7(ref)
    WHERE fi.file_type = 'trains'
  </code></pre>
  
  <p>The code gives no errors, but the Test field  is always blank.</p>
  
  <p>Any suggestions ?</p>