Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML/XSL Pulling element value based on an attribute

Status
Not open for further replies.

diablokicks

IS-IT--Management
Mar 25, 2010
4
US
Okay, so i'm trying to pull two subtotals. I have a table with two currency values, EUROS and DOLLARS. So in my XML file i have for example :
<BOOKS>
<Book>
<title isbn="2" kind="Food" inStock="8 Count">How to Cook</title>
<author>Tom Lee</author>
<price currency="Euros">25</price>
<pages>529</pages>
</Book></BOOKS>

I know the way it is setup is stupid having it as an attribute, but its the way it needs to be. I was able to add up the total pages for all books, but i'm having troubles with seperating the EUROS and Dollars and then finding the value of the element with each attribute.

TOTAL: $
<xsl:for-each select="Books/Book//price[@currency='USD']" />
<xsl:value-of select="//*" />
</xsl:for-each>

I know that i need to use the sum function to add them up, but i am just having issues even getting the values.

Please help me.

Thank you for your time,
Patrick
 
Context node is "/".
[tt]<xsl:for-each select="[red]BOOKS[/red]/Book[red]/[/red]price[@currency='USD']"[highlight]>[/highlight]
<xsl:value-of select="[red].[/red]" />
<xsl:text>&#x0d;&#x0a;</xsl:text>
</xsl:for-each>[/tt]
 
Can I ask you what the
<xsl:text>&#x0d;&#x0a;</xsl:text>
does?
 
Ah nevermind, it adds the space. That displays the two seperate values, but i still need to add them up, the sum() feature doesn't seem to work.
 
>but i still need to add them up, the sum() feature doesn't seem to work.
You need a lot of thing too such as reading up.
 
Agreed. I still have a lot to learn. Thought i would come ask for help here. Thank you for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top