Params w/ saxon:transform Extension Function

Help
crumpet75
2007-12-04
2012-10-08
  • crumpet75

    crumpet75 - 2007-12-04

    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:stylesheet xmlns: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:stylesheet xmlns: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>

     
    • Michael Kay

      Michael Kay - 2007-12-04

      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

       
    • crumpet75

      crumpet75 - 2007-12-04

      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

       
      • Michael Kay

        Michael Kay - 2007-12-04

        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

         
        • Michael Kay

          Michael Kay - 2007-12-05

          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

          &lt;xsl:template match=&quot;/&quot;&gt;
            &lt;a/&gt;
              &lt;xsl:message&gt;A=&lt;xsl:value-of select=&quot;$A&quot;/&gt;&lt;/xsl:message&gt;
              &lt;xsl:message&gt;B=&lt;xsl:value-of select=&quot;$B&quot;/&gt;&lt;/xsl:message&gt;
          &lt;/xsl:template&gt;
          

          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:

          &lt;xsl:template match=&quot;/&quot;&gt;
              &lt;xsl:message&gt;Starting transform1&lt;/xsl:message&gt;
              &lt;xsl:apply-templates select=&quot;saxon:transform($transform1,doc('EmptyXML.xml'),$transform1Params)&quot;/&gt;
              &lt;xsl:message&gt;Finished transform1&lt;/xsl:message&gt;
          &lt;/xsl:template&gt;
          

          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

           
    • crumpet75

      crumpet75 - 2007-12-04

      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

       
      • Michael Kay

        Michael Kay - 2007-12-04

        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

         
    • Michael Kay

      Michael Kay - 2007-12-05

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

      Michael Kay

       
    • crumpet75

      crumpet75 - 2007-12-14

      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

       
      • Michael Kay

        Michael Kay - 2007-12-14

        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.

         

Log in to post a comment.