Pass Object as parameter to XsltTransformer
Added by Anonymous over 15 years ago
Legacy ID: #7089364 Legacy Poster: Talmage (qnox)
Is it possible to pass an arbitrary object to the XsltTransformer object? Ie: MyObject myObj = new MyObject(); XsltTransformer trans = exp.load(); trans.setParameter("obj", myObj); I am not sure what to wrap myObj in to make it an XdmValue, as required by the method signature. Once that is done am I correct in my method of referring to this object? <?xml version="1.0"?> <xsl:transform version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:myobj='java:my.package.MyObject' xmlns:jt="http://saxon.sf.net/java-type"> <xsl:param name="obj" required="yes" as="jt:my.package.MyObject"/> <xsl:template match="/"> <res xmlns="test"> <xsl:value-of select="myobj:test($obj,('a','b','c'))"/> </res> </xsl:template> </xsl:transform>
Replies (2)
RE: Pass Object as parameter to XsltTransformer - Added by Anonymous over 15 years ago
Legacy ID: #7092598 Legacy Poster: Michael Kay (mhkay)
As far as I can see, there's no direct way of doing this in the s9api interface. I would suggest defining a subclass of XdmAtomicValue, called say XdmExternalObject; it will then have access to the protected method setValue() which you can call with an argument new net.sf.saxon.value.ObjectValue(myObj) Michael Kay http://www.saxonica.com/
RE: Pass Object as parameter to XsltTransformer - Added by Anonymous over 15 years ago
Legacy ID: #7092646 Legacy Poster: Michael Kay (mhkay)
Sorry, there is a direct way of doing it, which I overlooked. There's a static factory method in ItemTypeFactory: ItemTypeFactory.getExternalObject(myObj) I agree it's not the obvious place to look! Michael Kay http://www.saxonica.com/
Please register to reply