Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Nested xsl for-each

Posted on 2003-11-10
4
Medium Priority
?
313 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 

Accepted Solution

by:
Nog earned 100 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 100 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

688 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