You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Adam Jenkins <ma...@adamjenkins.net> on 2021/02/03 03:16:01 UTC

Extension elements accessing variables

Hi Everyone,

I have an old extension element that used to work that I’m dusting off to use again (haven’t used it in years).  It had some code in it that used to evaluate an XPath and return an XObject that gave a reference to a previously declared variable….but now it gives back and XRTreeFrag.  Any idea what I’m doing wrong?  I use the attribute to pass previously created Java objects to my extension element.

Cheers
Adam

    public static XObject getXObject(final String xpathAttributeName, final XSLProcessorContext context, final ElemExtensionCall extensionElement){
        XPathContext xCtx = context.getTransformer().getXPathContext();    
        String selectExpressionString = null;
        boolean namespacePushed = false;
        boolean expressionPushed = false;
        try{   
            selectExpressionString = extensionElement.getAttribute(xpathAttributeName);           
            XPath xpath = new XPath(selectExpressionString, xCtx.getSAXLocator(), extensionElement, XPath.SELECT);
            xCtx.pushNamespaceContext(extensionElement);            
            namespacePushed = true;
            int current = xCtx.getCurrentNode();
            xCtx.pushCurrentNodeAndExpression(current, current);        
            expressionPushed=true;
            Expression expr = xpath.getExpression();
            XObject result = expr.execute(xCtx);
            return result;
        }catch(Throwable t){
            log.error("Error evaluating xpath attribute " + xpathAttributeName + " [" + selectExpressionString + "]", t);
            return null;
        }
        finally
        {            
            if(namespacePushed) xCtx.popNamespaceContext();
            if(expressionPushed) xCtx.popCurrentNodeAndExpression();         
        }          
    }