*/
public static double max(ExpressionContext myContext, NodeList nl, String expr)
throws SAXNotSupportedException
{
XPathContext xctxt = null;
if (myContext instanceof XPathContext.XPathExpressionContext)
xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
else
throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext }));
if (expr == null || expr.length() == 0)
return Double.NaN;
NodeSetDTM contextNodes = new NodeSetDTM(nl, xctxt);
xctxt.pushContextNodeList(contextNodes);
double maxValue = - Double.MAX_VALUE;
for (int i = 0; i < contextNodes.getLength(); i++)
{
int contextNode = contextNodes.item(i);
xctxt.pushCurrentNode(contextNode);
double result = 0;
try
{
XPath dynamicXPath = new XPath(expr, xctxt.getSAXLocator(),
xctxt.getNamespaceContext(),
XPath.SELECT);
result = dynamicXPath.execute(xctxt, contextNode, xctxt.getNamespaceContext()).num();
}
catch (TransformerException e)
{
xctxt.popCurrentNode();
xctxt.popContextNodeList();
return Double.NaN;
}
xctxt.popCurrentNode();
if (result > maxValue)
maxValue = result;
}
xctxt.popContextNodeList();
return maxValue;
}