[xsl] Xalan equivalent for <msxsl:script>?

Subject: [xsl] Xalan equivalent for <msxsl:script>?
From: "Mazza, Glen" <glen.mazza@xxxxxxx>
Date: Mon, 12 Feb 2001 18:30:16 -0500
Hello,

Given an XML of authors and their books:

<authors>
	<author name="Author1">
		<books>
			<book title="Book#1">
				<cost>12.00</cost>
			</book>
			<book title="Book#2">
				<cost>21.00</cost>
			</book>
			<book title="Book#3">
				<cost>18.00</cost>
			</book>
		</books>
	</author>
	<author name="Author2">
	...
	</author>
</authors>

I wish to identify the most expensive book of each author.  I've seen the
recursion example (#11 in http://www.dpawson.co.uk/xsl/N8090.html) in the
FAQ, but to avoid recursion, I used a msxml:script function:

<msxsl:script implements-prefix="user">
<![CDATA[
    function mostExpensive(e) 
	{
	  	var maxVal = 0;
		var bookCost = 0;
		var node = e.nextNode();

		while (node != null) 
		{
		   bookCost = parseInt(node.selectSingleNode("cost").text);
		   if (bookCost > maxVal)
			  maxVal = bookCost;
	       node = e.nextNode();
		} 
		return maxVal;
	}
]]>
</msxsl:script>

My code above works fine:

<td align = "right"><xsl:value-of
select="user:mostExpensive(./books/book)"/></td>


Two questions here:

1)  As a sanity check, is this pretty much the way to calculate the largest
value in a list?  Is there any quick XPath/XSLT instruction that would do
the same thing without me needing to resort to functions or recursion?

2)  I would like to move my XSL to a Java application, using Xalan to take
my XML and XSL and output HTML.  But the <msxsl:script> tag is
Microsoft-specific.  Is there a Xalan equivalent for XSLT-process-time
<msxsl:script>?  I'm just starting to learn Xalan, so if you can just give
me a pointer of where I need to look in its documentation, it would be
appreciated.

Thanks,
Glen Mazza

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


Current Thread