title: XSLT : Nested Loops, If Condition
body: <p>I am new to XSL-FO and XPATH and have difficult in achieving the following requirement. My Requirement is to get results as below from the XML and XSL-FO:</p>
  
  <p>I need to show the results as below</p>
  
  <pre><code>Line# Item Description   Quantity  LINE_ARRIVAL_DATE
  1      test PO print-1     15      30-AUG-2016
  2      test PO print-2     25      30-SEP-2016
  </code></pre>
  
  <p>As you see the <code>Line #</code>, <code>Item Description</code> and <code>Quantity</code> come from <code>PO_DATA/LINES/LINES_ROW/</code> information and <code>LINE_ARRIVAL_DATE</code> comes from <code>PO_DATA/PURCHASEORDER/LINE_REF/PO_LINE_TYPE</code> 
  and the only way they are related is by the <code>PO_LINE_ID</code>  in <code>LINES_ROW</code> and <code>PO_LINE_TYPE</code> XML parents.<br>
  I thought having 2 for-each but that is not helping and I am not able to do for-each with the XSL-FO (below) and maybe my lack of knowledge on XSL-FO is the constraint.
  Please let me know if I can achieve this requirement and also of how I could achieve this.</p>
  
  <p>Thanks for looking.</p>
  
  <pre><code>&lt;PO_DATA&gt;
      &lt;SEGMENT1&gt;321178&lt;/SEGMENT1&gt;
      &lt;LINES&gt;
          &lt;LINES_ROW&gt;
              &lt;LINE_NUM&gt;1&lt;/LINE_NUM&gt;
              &lt;ITEM_DESCRIPTION&gt;test PO print-1&lt;/ITEM_DESCRIPTION&gt;
              &lt;CANCEL_FLAG&gt;N&lt;/CANCEL_FLAG&gt;
              &lt;UNIT_MEAS_LOOKUP_CODE&gt;EACH&lt;/UNIT_MEAS_LOOKUP_CODE&gt;
              &lt;ORDER_TYPE_LOOKUP_CODE&gt;QUANTITY&lt;/ORDER_TYPE_LOOKUP_CODE&gt;
              &lt;UNIT_PRICE&gt;25&lt;/UNIT_PRICE&gt;
              &lt;QUANTITY&gt;15&lt;/QUANTITY&gt;
              &lt;PO_HEADER_ID&gt;408363&lt;/PO_HEADER_ID&gt;
              &lt;PO_LINE_ID&gt;697709&lt;/PO_LINE_ID&gt;
          &lt;/LINES_ROW&gt;
          &lt;LINES_ROW&gt;
              &lt;LINE_NUM&gt;2&lt;/LINE_NUM&gt;
              &lt;ITEM_DESCRIPTION&gt;test PO print-2&lt;/ITEM_DESCRIPTION&gt;
              &lt;CANCEL_FLAG&gt;N&lt;/CANCEL_FLAG&gt;
              &lt;UNIT_MEAS_LOOKUP_CODE&gt;EACH&lt;/UNIT_MEAS_LOOKUP_CODE&gt;
              &lt;ORDER_TYPE_LOOKUP_CODE&gt;QUANTITY&lt;/ORDER_TYPE_LOOKUP_CODE&gt;
              &lt;UNIT_PRICE&gt;25&lt;/UNIT_PRICE&gt;
              &lt;QUANTITY&gt;15&lt;/QUANTITY&gt;
              &lt;PO_HEADER_ID&gt;408363&lt;/PO_HEADER_ID&gt;
              &lt;PO_LINE_ID&gt;697710&lt;/PO_LINE_ID&gt;
          &lt;/LINES_ROW&gt;  
      &lt;/LINES&gt;
      &lt;PURCHASEORDER&gt;
              &lt;PO_HEADER_ID&gt;408363&lt;/PO_HEADER_ID&gt;
              &lt;LINE_REF&gt;
                  &lt;POLINE_TYP&gt;
                      &lt;PO_LINE_ID&gt;697709&lt;/PO_LINE_ID&gt;
                      &lt;LINE_ARRIVAL_DATE&gt;30-AUG-2016&lt;/LINE_ARRIVAL_DATE&gt;
                  &lt;/POLINE_TYP&gt;   
                  &lt;POLINE_TYP&gt;
                      &lt;PO_LINE_ID&gt;697710&lt;/PO_LINE_ID&gt;
                      &lt;LINE_ARRIVAL_DATE&gt;30-SEP-2016&lt;/LINE_ARRIVAL_DATE&gt;
                  &lt;/POLINE_TYP&gt;   
              &lt;/LINE_REF&gt;    
      &lt;/PURCHASEORDER&gt;  
  &lt;/PO_DATA&gt;
  </code></pre>
  
  <p>
  </p>
  
  <pre><code>&lt;xsl:template match="/"&gt;
    &lt;html&gt;
    &lt;body&gt;
    &lt;h2&gt;My PO Lines&lt;/h2&gt;
      &lt;table border="1"&gt;
        &lt;tr bgcolor="#9acd32"&gt;
          &lt;th style="text-align:left"&gt;Line #&lt;/th&gt;
          &lt;th style="text-align:left"&gt;Item Description&lt;/th&gt;
          &lt;th style="text-align:left"&gt;spolineid&lt;/th&gt;      
          &lt;th style="text-align:left"&gt;cpolineid&lt;/th&gt;      
          &lt;th style="text-align:left"&gt;comparison&lt;/th&gt;     
        &lt;/tr&gt;
        &lt;xsl:for-each select="PO_DATA/LINES/LINES_ROW"&gt;
        &lt;!--xsl:for-each select="PURCHASEORDER/LINE_REF"--&gt;     
        &lt;!--xsl:for-each select="PURCHASEORDER/LINE_REF/POLINE_TYP"--&gt;          
        &lt;tr&gt;
          &lt;td&gt;&lt;xsl:value-of select="LINE_NUM"/&gt;&lt;/td&gt;
          &lt;td&gt;&lt;xsl:value-of select="ITEM_DESCRIPTION"/&gt;&lt;/td&gt;
          &lt;!--xsl:variable name="spolineid" select="string(PO_LINE_ID)"/&gt;     
          &lt;td&gt;&lt;xsl:value-of select="$spolineid" /&gt;&lt;/td&gt;
          &lt;xsl:variable name="cpolineid" select="string(../../PURCHASEORDER/LINE_REF/POLINE_TYP/PO_LINE_ID)"/&gt;        
          &lt;td&gt;&lt;xsl:value-of select="$cpolineid" /&gt;&lt;/td&gt;
          &lt;td&gt;&lt;xsl:if test = "$spolineid = $cpolineid "&gt; &lt;xsl:value-of select="../../PURCHASEORDER/LINE_REF/POLINE_TYP/LINE_ARRIVAL_DATE"/&gt;&lt;/xsl:if&gt;&lt;/td--&gt;
  
           &lt;td&gt;&lt;xsl:for-each select="PO_DATA/PURCHASEORDER/LINE_REF/POLINE_TYP"&gt;
                  &lt;xsl:value-of select="LINE_ARRIVAL_DATE"/&gt;
                  &lt;/xsl:for-each&gt;&lt;/td&gt;        
  
          &lt;/tr&gt;
        &lt;/xsl:for-each&gt;
        &lt;!--/xsl:for-each--&gt;    
      &lt;/table&gt;
    &lt;/body&gt;
    &lt;/html&gt;
  &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>