Solved

Nested xsl for-each

Posted on 2003-11-10
4
312 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 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

Industry Leaders: 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

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
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, …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

617 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