This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

for-each loops: arithmetic functions


Pardon the newbie question (I couldn't find an answer in the archives), but
I am trying to use arithmetic operators in the XSL for-each loops.  For
example, assume the following sample XML:

<libraries>
	<library>
		<name>City Library</name>
		<booksOverdue>124</booksOverdue>
		<totalDaysOverdue>696</totalDaysOverdue>
		<finePerDay>0.10</finePerDay>
	</library>
	<library>
		<name>Branch Library #1</name>
		<booksOverdue>53</booksOverdue>
		<totalDaysOverdue>116</totalDaysOverdue>
		<finePerDay>0.15</finePerDay>
	</library>
	<library>
		<name>Branch Library #2</name>
		<booksOverdue>73</booksOverdue>
		<totalDaysOverdue>310</totalDaysOverdue>
		<finePerDay>0.20</finePerDay>
	</library>
</libraries>

It is trivial to output the values in a listing:

<xsl:for-each select="libraries/library">
Name:		<xsl:value-of select="name"/><BR/>
# books overdue: <xsl:value-of select="booksOverdue"/><BR/>
total days overdue: <xsl:value-of select="totalDaysOverdue"/><BR/>
fine per day: 	<xsl:value-of select="finePerDay"/><BR/>
</xsl:for-each>

But I would like the average days overdue for each book (=
booksOverdue/totalDaysOverdue), , not the total.
I also would like to display the total fines collected, not the fines per
day:  (=finePerDay * totalDaysOverdue).

However, XSL doesn't appear to let me use these statements:

average days overdue: 	<xsl:value-of select="totalDaysOverdue" div
select="finePerDay"/><BR/>
total $ collected: 	<xsl:value-of select="finePerDay" *
select="totalDaysOverdue"/><BR/>

I possibly have the syntax wrong.  This appears to be a very simple problem,
but I can't seem to find the answer anywhere.

Thanks for your help,

Glen Mazza
* E-Mail:  glen.mazza@eds.com



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]