You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Gary L Peskin <ga...@firstech.com> on 2001/03/01 20:27:52 UTC

Re: [Xalan-J 2] bug fixproposal: problem when returning nodelists in extension class methods.

Renaud --

See below for my comments.

> Renaud Dumeur wrote:
> 
> Hi everyone,
> 
> I had a problem when using extensions and fixed it by modifying
> XRTreeFrag.java and ElemForEach.java (attached).
> 
> I have an extension class in charge of serializing objects so that
> their XML representation can be used from within XSLT templates.
> 
> My extension class looks like:
> 
> class MySerializer {
>  ...
> public NodeList serialize(...);
> ...
> }
> 
> And I use it in XSLT statements such as:
> 
>  <xsl:apply-templates
>     value-of="java:serialize($serializer, ...)"/>
> 
> It used to raised an exception in XObject.java:321 until I added the
> nodeset()
> method in XRTreeFrag to fix this problem:
> 
>   public NodeIterator nodeset() throws
> javax.xml.transform.TransformerException {
>     return asNodeIterator();
>   }
> 
> But after that, I got a ClassCastException at line 411 in
> ElemForEach.java because the  NodeIterator returned by
> XRTreeFrag.nodeset() wasn't implementing the ContextNodeList
> interface.
> This problem was eventually fixed by adding the following fragment at
> line 400 in ElemForEach.java:
> 
> else  if(! (sourceNodes instanceof ContextNodeList))
>  sourceNodes = new NodeSet(sourceNodes);
> 
> I'd really like to have a XALAN expert check its correctness, for I'm
> not sure ElemForEach should be patched.
> Maybe having XRTreeFrag.nodeset() returning a NodeSet would be
> enough...

Unfortunately, we cannot have a nodeset() method in XRTreeFrag as this
would allow Result Tree Fragments to be used as node-sets.  This is not
permitted by the XSLT 1.0 Recommendation.

If you are trying to return a node-set from your serialize extension,
you should return a org.apache.xpath.NodeSet rather than a NodeList.  If
you need help doing this, please post your java code and the
corresponding input XML and XSLT and we'll have a look.

Gary

Re: [Xalan-J 2] bug fixproposal: problem when returning nodelists in extension class methods.

Posted by Renaud Dumeur <rd...@ilog.fr>.
Gary,

see below for my answer.

----- Original Message -----
From: "Gary L Peskin" <ga...@firstech.com>
To: <xa...@xml.apache.org>
Sent: Thursday, March 01, 2001 8:27 PM
Subject: Re: [Xalan-J 2] bug fixproposal: problem when returning nodelists
in extension class methods.


> Renaud --
>
> See below for my comments.
>
> > Renaud Dumeur wrote:
> >
> > Hi everyone,
> >
> > I had a problem when using extensions and fixed it by modifying
> > XRTreeFrag.java and ElemForEach.java (attached).
> >
> > I have an extension class in charge of serializing objects so that
> > their XML representation can be used from within XSLT templates.
> >
> > My extension class looks like:
> >
> > class MySerializer {
> >  ...
> > public NodeList serialize(...);
> > ...
> > }
> >
> > And I use it in XSLT statements such as:
> >
> >  <xsl:apply-templates
> >     value-of="java:serialize($serializer, ...)"/>
> >
> > It used to raised an exception in XObject.java:321 until I added the
> > nodeset()
> > method in XRTreeFrag to fix this problem:
> >
> >   public NodeIterator nodeset() throws
> > javax.xml.transform.TransformerException {
> >     return asNodeIterator();
> >   }
> >
> > But after that, I got a ClassCastException at line 411 in
> > ElemForEach.java because the  NodeIterator returned by
> > XRTreeFrag.nodeset() wasn't implementing the ContextNodeList
> > interface.
> > This problem was eventually fixed by adding the following fragment at
> > line 400 in ElemForEach.java:
> >
> > else  if(! (sourceNodes instanceof ContextNodeList))
> >  sourceNodes = new NodeSet(sourceNodes);
> >
> > I'd really like to have a XALAN expert check its correctness, for I'm
> > not sure ElemForEach should be patched.
> > Maybe having XRTreeFrag.nodeset() returning a NodeSet would be
> > enough...
>
> Unfortunately, we cannot have a nodeset() method in XRTreeFrag as this
> would allow Result Tree Fragments to be used as node-sets.  This is not
> permitted by the XSLT 1.0 Recommendation.
>
That's bad news.  Don't you think it would be reasonable to allow this in
the next XSLT recommendation?

> If you are trying to return a node-set from your serialize extension,
> you should return a org.apache.xpath.NodeSet rather than a NodeList.  If
> you need help doing this, please post your java code and the
> corresponding input XML and XSLT and we'll have a look.
>
Okay, thanks.

        Thanks.

> Gary
>