FileDocCategorySizeDatePackage
FuncLast.javaAPI DocJava SE 5 API3013Fri Aug 26 14:56:08 BST 2005com.sun.org.apache.xpath.internal.functions

FuncLast

public class FuncLast extends Function
Execute the Last() function.
xsl.usage
advanced

Fields Summary
private boolean
m_isTopLevel
Constructors Summary
Methods Summary
public com.sun.org.apache.xpath.internal.objects.XObjectexecute(com.sun.org.apache.xpath.internal.XPathContext xctxt)
Execute the function. The function must return a valid object.

param
xctxt The current execution context.
return
A valid XObject.
throws
javax.xml.transform.TransformerException

    XNumber xnum = new XNumber((double) getCountOfContextNodeList(xctxt));
    // System.out.println("last: "+xnum.num());
    return xnum;
  
public voidfixupVariables(java.util.Vector vars, int globalsSize)
No arguments to process, so this does nothing.

    // no-op
  
public intgetCountOfContextNodeList(com.sun.org.apache.xpath.internal.XPathContext xctxt)
Get the position in the current context node list.

param
xctxt non-null reference to XPath runtime context.
return
The number of nodes in the list.
throws
javax.xml.transform.TransformerException


    // assert(null != m_contextNodeList, "m_contextNodeList must be non-null");
    // If we're in a predicate, then this will return non-null.
    SubContextList iter = m_isTopLevel ? null : xctxt.getSubContextList();

    // System.out.println("iter: "+iter);
    if (null != iter)
      return iter.getLastPos(xctxt);

    DTMIterator cnl = xctxt.getContextNodeList();
    int count;
    if(null != cnl)
    {
      count = cnl.getLength();
      // System.out.println("count: "+count); 
    }
    else
      count = 0;   
    return count;
  
public voidpostCompileStep(com.sun.org.apache.xpath.internal.compiler.Compiler compiler)
Figure out if we're executing a toplevel expression. If so, we can't be inside of a predicate.

    m_isTopLevel = compiler.getLocationPathDepth() == -1;