Project

Profile

Help

Params w/ saxon:transform Extension Function

Added by Anonymous over 16 years ago

Legacy ID: #4658492 Legacy Poster: crumpet75 (crumpet75)

Hi, I am looking for clarification or an example of how to pass parameters to the saxon:transform extension function. I have read, http://www.saxonica.com/documentation/extensions/functions/transform.html and I have a useful transform that compilies another transform and applies saxon:transform to numerous documents that does not require params. But I receive an unhelpful message "Error in call to extension function" when I try to pass some params. (Using 9.0.0.2J) Below is an overly simplified example of what I am trying to do. I think my error is related to a misunderstanding about how to construct the $transform1Params variable. Test.xsl ************************ <xsl:stylesheetxmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:saxon="http://saxon.sf.net/" version="2.0"> <!--transform1.xsl--> <xsl:variable name="transform1" select="saxon:compile-stylesheet(doc('transform1.xsl'))"/> <!--Build Parameters to pass to transform1--> <xsl:variable name="transform1Params"> <A>This is a test of the value for param A.</A> <B>This is a test of the value for param B.</B> <!--I want to pass a more complex parameter such as the following, but I receive errors as well...--> <!--<C><item>item1</item><item>item2</item><item>item3</item></C>--> </xsl:variable> <xsl:template match="/"> <xsl:apply-templates select="saxon:transform($transform1,doc('EmptyXML.xml'),$transform1Params)"/> </xsl:template> </xsl:stylesheet> transform1.xsl ********************* <xsl:stylesheetxmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:saxon="http://saxon.sf.net/" version="2.0"> <xsl:param name="A"/> <xsl:param name="B"/> <!--<xsl:param name="C"/>--> <xsl:template match="/"> <xsl:message>A=<xsl:value-of select="$A"/></xsl:message> <xsl:message>B=<xsl:value-of select="$B"/></xsl:message> <!--<xsl:for-each select="$C/item"> <xsl:message>C.item=<xsl:value-of select="."/></xsl:message> </xsl:for-each>--> </xsl:template> </xsl:stylesheet>


Replies (9)

Please register to reply

RE: Params w/ saxon:transform Extension Funct - Added by Anonymous over 16 years ago

Legacy ID: #4658594 Legacy Poster: Michael Kay (mhkay)

You should be able to get a more detailed error message by using the -TJ option on the command line. I'm afraid I can't see from this what you've done wrong. Michael Kay Saxonica

RE: Params w/ saxon:transform Extension Funct - Added by Anonymous over 16 years ago

Legacy ID: #4658642 Legacy Poster: crumpet75 (crumpet75)

Thanks for your suggestion. I tried the -TJ option, but I am still puzzling over what's wrong. The output is below. It seems that A and B are passed correctly, but a NullPointerException occurs before the transform can finish. Any ideas about why this may be? Thanks A=This is a test of the value for param A. B=This is a test of the value for param B. java.lang.NullPointerException at net.sf.saxon.tinytree.TinyBuilder.close(TinyBuilder.java:167) at net.sf.saxon.event.ImplicitResultChecker.close(ImplicitResultChecker. java:69) at net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:90) at net.sf.saxon.event.ComplexContentOutputter.close(ComplexContentOutput ter.java:490) at net.sf.saxon.Controller.transformDocument(Controller.java:1775) at net.sf.saxon.Controller.transform(Controller.java:1559) at net.sf.saxon.functions.Extensions.transform(Extensions.java:1281) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.sf.saxon.functions.ExtensionFunctionCall.invokeMethod(ExtensionFu nctionCall.java:533) at net.sf.saxon.functions.ExtensionFunctionCall.call(ExtensionFunctionCa ll.java:256) at net.sf.saxon.functions.ExtensionFunctionCall.iterate(ExtensionFunctio nCall.java:147) at net.sf.saxon.instruct.ApplyTemplates.apply(ApplyTemplates.java:196) at net.sf.saxon.instruct.ApplyTemplates.processLeavingTail(ApplyTemplate s.java:172) at net.sf.saxon.instruct.Block.processLeavingTail(Block.java:399) at net.sf.saxon.instruct.Template.applyLeavingTail(Template.java:175) at net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTemplates.ja va:343) at net.sf.saxon.Controller.transformDocument(Controller.java:1735) at net.sf.saxon.Controller.transform(Controller.java:1559) at net.sf.saxon.Transform.processFile(Transform.java:1036) at net.sf.saxon.Transform.doTransform(Transform.java:672) at net.sf.saxon.Transform.main(Transform.java:65) Error on line 19 of file:/D:/RVP-DITA/RVP-DITA-1.4/00_xsl/RVP_Validation/test.xs l: Error in call to extension function {public static net.sf.saxon.om.DocumentInf o net.sf.saxon.functions.Extensions.transform(net.sf.saxon.expr.XPathContext,jav ax.xml.transform.Templates,net.sf.saxon.om.NodeInfo,net.sf.saxon.om.SequenceIter ator) throws net.sf.saxon.trans.XPathException}: Exception in extension function java.lang.NullPointerException Transformation failed: Run-time errors were reported

RE: Params w/ saxon:transform Extension Funct - Added by Anonymous over 16 years ago

Legacy ID: #4658692 Legacy Poster: Michael Kay (mhkay)

The NullPointerException is a Saxon bug, I'm afraid. I'd be grateful if you could try to put together a test case so I can reproduce it and fix it. I have a suspicion - just a guess really - that it may be triggered because the output of saxon:transform() is empty. Michael Kay

RE: Params w/ saxon:transform Extension Funct - Added by Anonymous over 16 years ago

Legacy ID: #4658717 Legacy Poster: crumpet75 (crumpet75)

Hi Michael, Thanks again. I'd be happy to put together a test case. (The example test.xsl and transform.xsl should reproduce the issue.) Do you have guidelines on how to submit the test case? (I tried adding content to transform1 so that saxon:transform() wouldn't be empty... but had the same error.) Darcy

RE: Params w/ saxon:transform Extension Funct - Added by Anonymous over 16 years ago

Legacy ID: #4659002 Legacy Poster: Michael Kay (mhkay)

You can mail a test case to me directly (click on my name if you don't know the address), or you can submit it on the support-requests tracker. Michael Kay Saxonica

RE: Params w/ saxon:transform Extension Funct - Added by Anonymous over 16 years ago

Legacy ID: #4660561 Legacy Poster: Michael Kay (mhkay)

It seems my suspicions were right - both transform1 and transform2 produce an empty result tree and this is the immediate cause of the NullPointerException. If you change the transform to something like <xsl:template match="/"> <a/> <xsl:message>A=<xsl:value-of select="$A"/></xsl:message> <xsl:message>B=<xsl:value-of select="$B"/></xsl:message> </xsl:template> then the problem goes away. You then get another problem, which is that you get infinite recursion, but that's a problem in your stylesheet - when you do: <xsl:template match="/"> <xsl:message>Starting transform1</xsl:message> <xsl:apply-templates select="saxon:transform($transform1,doc('EmptyXML.xml'),$transform1Params)"/> <xsl:message>Finished transform1</xsl:message> </xsl:template> then saxon:transform() is going to return a document node, and applying templates to it is going to invoke the same match="/" template again, with no termination. Change the apply-templates to xsl:copy-of to get rid of this. Michael Kay

RE: Params w/ saxon:transform Extension Funct - Added by Anonymous over 16 years ago

Legacy ID: #4660637 Legacy Poster: Michael Kay (mhkay)

I've produced a patch - check the bug tracker for details. Michael Kay

RE: Params w/ saxon:transform Extension Funct - Added by Anonymous over 16 years ago

Legacy ID: #4675576 Legacy Poster: crumpet75 (crumpet75)

Thanks for creating the patch. Your support and response time is really appreciated. I was able to get the latest9.0 branch from SVN. As a follow-up question, is there an Ant Build file to build the source? Thanks Darcy

RE: Params w/ saxon:transform Extension Funct - Added by Anonymous over 16 years ago

Legacy ID: #4675589 Legacy Poster: Michael Kay (mhkay)

There's a build directory in the latest8.9 branch in Subversion which you could use as a starting point. You'll need to change a few parameters, and you'll probably want to get rid of the tasks that compile for .NET.

    (1-9/9)

    Please register to reply