Solved

Iterating through XML Nodes

Posted on 2004-10-27
161 Views
Last Modified: 2010-04-17
Hi,
I have an XML as follows:

- <ratings>
- <Criteria TeamID="5" Code="cLTC00001">
<RequiredInfo ReqInfo="Required Info Areas To Improve LTC 1.1" />
</Criteria>
- <Criteria TeamID="5" Code="cLTC00002">
<RequiredInfo ReqInfo="Required Information LTC 1.2" />
<RequiredInfo ReqInfo="Required Information LTC 1.2" />
</Criteria>


I have a <xsl:for-each> to loop through each criteria. And I display the Required Information for that corresponding criteria.

Problem comes when a criteria has 2 requiredinfo. I need to set up the counter and need to display the requiredinfo at position 2 when I loop through the counter. Can someone help me with the Syntax please.

The following is the XSL I currently have:

<xsl:for-each select="./RequiredInfo">   <!-- This comes from XML Doc 1-->
<tr>
<td>&#160;</td>
<td>&#160;</td>
<td valign="top" class="details">
<xsl:value-of select="@TextDetails" />
<br></br>
</td>
</tr>
<tr>
<td>&#160;</td>
<td>&#160;</td>
<xsl:if test="string-length(document($dataURL1)/*/Criteria[@Criteria = $criteria]/RequiredInfo) > 0">

<Comments>  for your understanding
<!-- DataURL1 is a reference to stored procedure like this <xsl:variable name="dataURL1">
            <!--<xsl:value-of select="'http://xyz/ams_sqlxml2?sql=select+*+from+vSACriteriaRatings+where+TeamID=7+for+xml+auto,Elements&amp;root=ratings'" />-->
            <xsl:value-of select="'http://comet/ams_sqlxml2?sql=spCCHSA_RatingandReqInfoTree+5&amp;root=ratings1'" />
      </xsl:variable> -->
<Comments>

<td>
<table style="border:1px black solid" cellpadding="5" class="nothing" width="100%">
<tbody>
<tr>
<td>
<xsl:value-of select="document($dataURL1)/*/Criteria[@Criteria = $criteria]/RequiredInfo" />
</td>
</tr>
</tbody>
</table>
</td>
</xsl:if>
</tr>
</xsl:for-each>

Thanks
Vijaya
0
Question by:CCHSA
    3 Comments
     

    Expert Comment

    by:Stiow
    Just to clarify - what you want to do is display the LAST one if there are more than one?  If there were 10 would you still want to display number 2, or would you want to display number 10?

    Stuart.
    0
     

    Author Comment

    by:CCHSA
    Thanks Stuart,

    I resolved this thing. When I removed the TeamID in the XML and have only the criteria in the child node, it worked.
    0
     

    Accepted Solution

    by:
    PAQed with points refunded (500)

    modulo
    Community Support Moderator
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Anonabox PRO Tor & VPN Router

    PRO is the most advanced way to fortify your privacy and online anonymity by layering the Tor network with VPN services. Use both together or separately, and without needing to download software onto your devices.

    Suggested Solutions

    Title # Comments Views Activity
    Modbus - whats the maximum I can store in one register? 4 49
    count7 challenge 12 26
    allStar challenge 1 12
    strCount chalenge 3 12
    Purpose To explain how to place a textual stamp on a PDF document.  This is commonly referred to as an annotation, or possibly a watermark, but a watermark is generally different in that it is somewhat translucent.  Watermark’s may be text or graph…
    This article will show, step by step, how to integrate R code into a R Sweave document
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    913 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

    17 Experts available now in Live!

    Get 1:1 Help Now