/** * For support of literal objects in xpaths. * * @param xctxt The XPath execution context. * @return This object. * @throws javax.xml.transform.TransformerException */ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException { if (!m_doneEval) { this.m_transformer .getMsgMgr() .error( xctxt.getSAXLocator(), XSLTErrorResources.ER_REFERENCING_ITSELF, new Object[] {((ElemVariable) this.object()).getName().getLocalName()}); } VariableStack vars = xctxt.getVarStack(); // These three statements need to be combined into one operation. int currentFrame = vars.getStackFrame(); //// vars.setStackFrame(m_varStackPos); ElemVariable velem = (ElemVariable) m_obj; try { m_doneEval = false; if (-1 != velem.m_frameSize) vars.link(velem.m_frameSize); XObject var = velem.getValue(m_transformer, m_context); m_doneEval = true; return var; } finally { // These two statements need to be combined into one operation. // vars.setStackFrame(currentFrame); if (-1 != velem.m_frameSize) vars.unlink(currentFrame); } }
/** * Get a variable based on it's qualified name. This is for external use only. * * @param xctxt The XPath context, which must be passed in order to lazy evaluate variables. * @param qname The qualified name of the variable. * @return The evaluated value of the variable. * @throws javax.xml.transform.TransformerException */ public XObject getVariableOrParam(XPathContext xctxt, org.apache.xml.utils.QName qname) throws javax.xml.transform.TransformerException { org.apache.xml.utils.PrefixResolver prefixResolver = xctxt.getNamespaceContext(); // Get the current ElemTemplateElement, which must be pushed in as the // prefix resolver, and then walk backwards in document order, searching // for an xsl:param element or xsl:variable element that matches our // qname. If we reach the top level, use the StylesheetRoot's composed // list of top level variables and parameters. if (prefixResolver instanceof org.apache.xalan.templates.ElemTemplateElement) { org.apache.xalan.templates.ElemVariable vvar; org.apache.xalan.templates.ElemTemplateElement prev = (org.apache.xalan.templates.ElemTemplateElement) prefixResolver; if (!(prev instanceof org.apache.xalan.templates.Stylesheet)) { while (!(prev.getParentNode() instanceof org.apache.xalan.templates.Stylesheet)) { org.apache.xalan.templates.ElemTemplateElement savedprev = prev; while (null != (prev = prev.getPreviousSiblingElem())) { if (prev instanceof org.apache.xalan.templates.ElemVariable) { vvar = (org.apache.xalan.templates.ElemVariable) prev; if (vvar.getName().equals(qname)) return getLocalVariable(xctxt, vvar.getIndex()); } } prev = savedprev.getParentElem(); } } vvar = prev.getStylesheetRoot().getVariableOrParamComposed(qname); if (null != vvar) return getGlobalVariable(xctxt, vvar.getIndex()); } throw new javax.xml.transform.TransformerException( XSLMessages.createXPATHMessage( XPATHErrorResources.ER_VAR_NOT_RESOLVABLE, new Object[] {qname.toString()})); // "Variable not resolvable: " + qname); }