Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Iterating through XML Nodes

Posted on 2004-10-27
Medium Priority
Last Modified: 2010-04-17
I have an XML as follows:

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

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-->
<td valign="top" class="details">
<xsl:value-of select="@TextDetails" />
<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&root=ratings'" />-->
            <xsl:value-of select="'http://comet/ams_sqlxml2?sql=spCCHSA_RatingandReqInfoTree+5&root=ratings1'" />
      </xsl:variable> -->

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

Question by:CCHSA
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

Expert Comment

ID: 12433644
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?


Author Comment

ID: 12437029
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.

Accepted Solution

modulo earned 0 total points
ID: 12654112
PAQed with points refunded (500)

Community Support Moderator

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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…

597 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