XalanJ2
  1. XalanJ2
  2. XALANJ-2057

Transformer.setParameter should accept Source as an Object value

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.7
    • Fix Version/s: None
    • Component/s: JAXP
    • Labels:
      None

      Description

      Saxon 8 has a nice feature whereby you can pass a TrAX SAXSource/DOMSource etc. to the Transformer.setParameter method, Saxon converts that source into its internal representation. That is, it will read from the source and build the necessary representation of a node-set. This makes it relatively easy to set parameters whose values are node-sets.

      This is very useful for hooking up Xalan to other object models such as JDOM and XOM. Currently these models can be transformed by wrapping the original input document in a SAXSource. However, node-set parameters do not work the same way. These have to be set by wrapping them in a DOM NodeIterator or NodeList or Node. It would be more consistent and more convenient if setParameter accepted a TrAX Source object as well.

        Activity

        Hide
        elharo added a comment -

        I don't think this would be too hard to do. I haven't even tried compiling this yet, so this is not a patch, but just a couple of notes on how I suspect this could be implemented.

        I think it would take an additional branch in the big if block in XObjectFactory.create(Object val, XPathContext xctxt) that would look something like this:

        else if (val instanceof Source)
        {
        DTM dtm = mgr.getDTM((Source) val, false, null, true, true);

        try

        { int dtmRoot = dtm.getDocument(); DTMAxisIterator iter = dtm.getAxisIterator(Axis.SELF); iter.setStartNode(dtmRoot); DTMIterator iterator = new OneStepIterator(iter, Axis.SELF); iterator.setRoot(dtmRoot, xctxt); result = new XNodeSet(iterator); }

        catch(Exception ex)

        { throw new org.apache.xml.utils.WrappedRuntimeException(ex); }

        }

        I've adapted this by cutting and pasting out of two existing classes (Transformer and XObjectfactory) so that probably won't quite work, and needs some hacking; but the basic idea is just to convert sources into node-sets pretty much the same way they're converted when initially loading a Source into Xalan; and then end up with the same thing we'd end up with if a DTM had been passed in instead of a Source.

        Show
        elharo added a comment - I don't think this would be too hard to do. I haven't even tried compiling this yet, so this is not a patch, but just a couple of notes on how I suspect this could be implemented. I think it would take an additional branch in the big if block in XObjectFactory.create(Object val, XPathContext xctxt) that would look something like this: else if (val instanceof Source) { DTM dtm = mgr.getDTM((Source) val, false, null, true, true); try { int dtmRoot = dtm.getDocument(); DTMAxisIterator iter = dtm.getAxisIterator(Axis.SELF); iter.setStartNode(dtmRoot); DTMIterator iterator = new OneStepIterator(iter, Axis.SELF); iterator.setRoot(dtmRoot, xctxt); result = new XNodeSet(iterator); } catch(Exception ex) { throw new org.apache.xml.utils.WrappedRuntimeException(ex); } } I've adapted this by cutting and pasting out of two existing classes (Transformer and XObjectfactory) so that probably won't quite work, and needs some hacking; but the basic idea is just to convert sources into node-sets pretty much the same way they're converted when initially loading a Source into Xalan; and then end up with the same thing we'd end up with if a DTM had been passed in instead of a Source.
        Hide
        Brian Minchau added a comment -

        Per the JIRA committer meeting March 1, I'm assigning to Henry. This looks like a reasonable improvement, but needs further investigation. The Xalan PMC needs to decide on the fix priority.

        Show
        Brian Minchau added a comment - Per the JIRA committer meeting March 1, I'm assigning to Henry. This looks like a reasonable improvement, but needs further investigation. The Xalan PMC needs to decide on the fix priority.
        Hide
        ggregory@seagullsw.com added a comment -

        Would this work as well when running Xalan in XSLTC mode? That's what we need here.

        Show
        ggregory@seagullsw.com added a comment - Would this work as well when running Xalan in XSLTC mode? That's what we need here.

          People

          • Assignee:
            Henry Zongaro
            Reporter:
            elharo
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:

              Development