Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 314
  • Last Modified:

Nested xsl for-each

Don't know why this code doesn't work. It will work when the loops aren't nested.
ANy help would be great!!

            
            
            <xsl:for-each select="QUERY_RESULTS/POLICY">
                  
                  <tr>
                  <td><b>Policy Number: </b></td>
                  <td><font color="blue"><xsl:value-of select="policy_number" /></font></td>
                  </tr>

                  <xsl:for-each select="QUERY_RESULTS/POLICY/VRM_DETAILS">
                        <tr>
                        <td><font color="blue"><xsl:value-of select="effective_date" /></font></td>
                        <td><font color="blue"><xsl:value-of select="expiry_date" /></font></td>
                        </tr>
                  </xsl:for-each>


                  </xsl:for-each>
                  
                  
0
ew24
Asked:
ew24
2 Solutions
 
NogCommented:
Because for each moves the cursor to the selected node, so a nested for each needs to reference from that node. Your XPath expression requires nodes in the inner for-each to match on QUERY_RESULTS/POLICY/QUERY_RESULTS/POLICY/VRM_DETAILS
Try changing the inner for-each select statement to be <xsl:for-each select="VRM_DETAILS">
0
 
exile_4Commented:
Nog is right, your first loop is stepping at QUERY_RESULTS/POLICY and the inner loop is traversing QUERY_RESULTS/POLICY/VRM_DETAILS wherein, the xsl is expecting an xml structure like this:

<QUERY_RESULTS>
    <POLICY>                      <--- your first loop
          <QUERY_RESULTS>
                <POLICY>
                      <VRM_DETAILS>        <-- your second loop
                      </VRM_DETAILS>
                </POLICY>
          </QUERY_RESULTS>
    <POLICY>
</QUERY_RESULTS>

but if your XML structure is like this,

<QUERY_RESULTS>
    <POLICY>                      <--- your first loop
          <VRM_DETAILS>        <-- your second loop, changed "QUERY_RESULTS/POLICY/VRM_DETAILS" to "VRM_DETAILS"
           </VRM_DETAILS>
          <VRM_DETAILS>      
           </VRM_DETAILS>
    <POLICY>
</QUERY_RESULTS>

Cheers,
Exile_4
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now