Hi Everyone,
I have a custom extension element that returns a value (a spring context that
stores a large cache of constants). I enclosed it in a variable thinking the
returned object would be set into the variable for use later however it’s
storing an XRTreeFrag (the children themselves) into the VariableStack.
You’ll see what I’m trying to do below. Does anyone have any idea of a better
way to accomplish this?
Cheers
Adam
<xsl:template match="/">
<xsl:variable name="test1">
<spring:context base="CLASSPATH">
<spring:resource
location="/net/adamjenkins/sxe/spring/spring-config.xml"/>
</spring:context>
</xsl:variable>
<mockelement:run select="$test1”/>
public class Spring{
public AbstractApplicationContext context(XSLProcessorContext context,
ElemExtensionCall extensionElement){
//returns the spring context
}
}
public class MockElement {
public void run(XSLProcessorContext context, ElemExtensionCall
extensionElement) throws TransformerException {
System.out.println("running");
XPathContext xCtx = context.getTransformer().getXPathContext();
String selectExpressionString = null;
boolean namespacePushed = false;
boolean expressionPushed = false;
try{
selectExpressionString = extensionElement.getAttribute("select");
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);
//If I set the variable using select=“ “ I get back an XObject with
the correct variable for “result"
//if I set the variable using an extension element as above I get
back an XRTreeFrag object
}catch(Throwable t){
t.printStackTrace();
}
finally
{
if(namespacePushed) xCtx.popNamespaceContext();
if(expressionPushed) xCtx.popCurrentNodeAndExpression();
}
}
}