Can anyone tell me if there's any way to add an object (not node or tree fragment) variable to the variable stack from an extension element?
I originally tried to use context.outputToResultTree(context.getStylesheet(), myCreatedObject) an put my extension element inside an <xsl:variable...>, however that turns my java object into a text node on a Document first (the text node has the value of the toString() from my object) rather than passing myCreatedObject to the ElemVariable element as a java object. I'm now looking into doing a similar thing as in ElemVariable.java and adding the object to the stack directly from within my extension element method, from what I can see, this should work: StylesheetRoot root = xslProcessorContext.getStylesheet().getStylesheetRoot(); StylesheetRoot.ComposeState cstate = sroot.getComposeState(); QName name = new QName(name); XObject obj = new XObject(myCreatedObject); int index = cstate.addVariableName(name) - cstate.getGlobalsSize(); xslProcessorContext.getTransformer().getXPathContext().getVarStack().setLocalVariable(index, obj); Now this is similar to what ElemVariable.java does, however StylesheetRoot.ComposeState is package scoped!, so I can't use the above code either :( If anyone knows of a way to put a java object variable onto the variable stack (as an XObject, not a XRTreeFrag) under a given name from within an extension element method I'd really appreciate any pointers you could give. My goals is placing an object into the local variable stack under a given name so that I can reference it, for example in an <xsl:value-of select="java:someMethod($myPreviouslyAddedObject)"/> --- On Fri, 13/11/09, Adam Jenkins <adamjenkinstmpredir...@yahoo.com.au> wrote: > From: Adam Jenkins <adamjenkinstmpredir...@yahoo.com.au> > Subject: Advanced Extension Element Question > To: xalan-j-users@xml.apache.org, xalan-...@xml.apache.org > Received: Friday, 13 November, 2009, 5:53 PM > Hi All, > > I'm just wondering if there is a way to place a java object > (not a tree fragment) into the context output results from > an extension element, and have it stay as an object (and not > have it turned into a Document node). > > Here is the exact use case. I have a custom extension > that creates an object that is used later on throughout my > xslt. The use case I want is: > > <xsl:variable name="somevarname"> > <custom:myobject> > <custom:property name="blah" > value="blah"/> > </custom:myobject> > </xsl:variable> > > The function myObject(XSLProcessorContext, > ElemExtensionCall) on the object mapped to the prefix > 'custom' creates a java object, and places it to the output > tree thus: > > context.outputToResultTree(context.getStylesheet(), > myCreatedObject); > > Now, when I try to reference that later, it's been turned > into a text node on a Document object whos value is the > value of the toString() method for 'myCreatedObject'. > So I think I'm using the wrong method here...and that > perhaps there's a better method other than > outputToResultTree?? > > So I'm guessing xalan <xsl:variable...> tag is > creating a document fragment from my object as best it can. > > So my question is...is there anyway, to pass > myCreatedObject up to the previous <xsl:variable...> > declaration without it being toStringed (another method > somewhere). > > My fallback is to declare a varName attribute on all my > custom extension and put the object on the local variable > stack myself, but that's a pain and looks ugly, I'd prefer > to do it using xsl:variable. > > This is for an open source (large) xalan extension library > to be releases asap. > > Cheers > Adam > > > > __________________________________________________________________________________ > Win 1 of 4 Sony home entertainment packs thanks to > Yahoo!7. > Enter now: http://au.docs.yahoo.com/homepageset/ > __________________________________________________________________________________ Win 1 of 4 Sony home entertainment packs thanks to Yahoo!7. Enter now: http://au.docs.yahoo.com/homepageset/