Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

XSLT - Loop through unknown node names

Avatar of hendrix500
hendrix500 asked on
Web Languages and StandardsXML
5 Comments1 Solution626 ViewsLast Modified:
My XSLT/XPATH is a bit rusty. The sample xml contains several <price> elements and I  need to figure out how sum up these values, but only the CHEAPEST of each service type.
So far, i've done this:

<xsl:for-each select="AvailabilitySearch/Services">
      <xsl:value-of select="sum(child::*/child::*/child::Price)"/>

This gets me the sum of all the price elements. However, I need to extend this to:
1/ Only Sum up the cheapest of each service i.e. the cheapest book, the cheapest cd, the chepest game
2/ Be able to skip a specified service e.g. Don't include the Books in the calculation, only sum up the cheapest cd and game.

To be able to sum up only the cheapest, i'm guessing that I should be doing a sort. As a test, I tried this:
<xsl:for-each select="child::*/child::*">
            <xsl:sort data-type="number" order="ascending" select="Price"/>
      <xsl:value-of select="Price"/>

However this sorts the WHOLE of the results by price, rather than the services individually.

Any help would be great. If anything isn't clear please let me know and i'll try and explain further.

			<Book id="1">
				<Name>Book 1</Name>
			<Book id="1">
				<Name>Book 1</Name>
				<Name>CD 1</Name>
				<Name>CD 2</Name>
				<Name>Game 1</Name>
				<Name>Game 2</Name>
				<Name>Game 3</Name>
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)Flag of Belgium imageInformation Architect
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answers