Solved

Nested xsl for-each

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

Technology Partners: 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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Suggested Courses

739 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