code: protected ElemTemplateElement getPrevElementWithinContext(ElemTemplateElement elem)
    {
    	ElemTemplateElement prev = elem.getPreviousSiblingElem();
    	if(null == prev)
    		prev = elem.getParentElem();
    	if(null != prev)
    	{
    	  int type = prev.getXSLToken();
    	  if((Constants.ELEMNAME_FOREACH == type) || 
    	     (Constants.ELEMNAME_TEMPLATE == type) ||
    	     (Constants.ELEMNAME_STYLESHEET == type))
    	  {
    	  	prev = null;
    	  }
    	}
    	return prev;
    }
docs: Get the previous sibling or parent of the given template, stopping at
  xsl:for-each, xsl:template, or xsl:stylesheet.
  
  @param elem Should be non-null template element.
  @return previous sibling or parent, or null if previous is xsl:for-each,
  xsl:template, or xsl:stylesheet.