Solved

Nested xsl for-each

Posted on 2003-11-10
4
305 Views
Last Modified: 2012-08-13
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
Comment
Question by:ew24
4 Comments
 

Accepted Solution

by:
Nog earned 25 total points
ID: 9715640
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
 
LVL 2

Assisted Solution

by:exile_4
exile_4 earned 25 total points
ID: 9736728
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now