You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xalan.apache.org by Simon Scott <Si...@trilliumsoftware.com> on 2010/07/21 23:40:35 UTC
Extension function to return document fragment nodeset
Hi
Hope this isn't a stupid question.
Using Xalan 1.10/Xerces 2.7, I need to implement an extension function that returns a nodeset. The nodeset needs to be a document fragment, comprising text nodes (which my function needs to create) and (copies of?) existing source document nodes that are given as input args to the function.
I'm really struggling to find how to do this. Using BorrowReturnMutableNodeRefList I've been able to return the pre-existing input nodes, but I can't find how to create the new text nodes. I've reviewed FunctionNodeset.cpp and an archived message from David Bertoni that suggests building a DOM with Xerces and then using XercesDocumentWrapper and XNodeSetBase. That seems to me to be the right track, but I need to return a DocumentFragment, for which I presumably need a XercesDocumentFragmentWrapper, which is a class that doesn't seem to exist.
Am I on the right lines, or missing a much easier way? If I'm going in the right direction, why isn't there a XercesDocumentFragmentWrapper? Is it possible to build one myself, or is there some reason why it can't be built?
Many thanks for any assistance,
Simon Scott
Re: Extension function to return document fragment nodeset
Posted by David Bertoni <db...@apache.org>.
On 7/21/2010 2:40 PM, Simon Scott wrote:
> Hi
>
> Hope this isn't a stupid question.
>
> Using Xalan 1.10/Xerces 2.7, I need to implement an extension function
> that returns a nodeset. The nodeset needs to be a document fragment,
> comprising text nodes (which my function needs to create) and (copies
> of?) existing source document nodes that are given as input args to the
> function.
>
> I'm really struggling to find how to do this. Using
> BorrowReturnMutableNodeRefList I've been able to return the pre-existing
> input nodes, but I can't find how to create the new text nodes. I've
> reviewed FunctionNodeset.cpp and an archived message from David Bertoni
> that suggests building a DOM with Xerces and then using
> XercesDocumentWrapper and XNodeSetBase. That seems to me to be the right
> track, but I need to return a DocumentFragment, for which I presumably
> need a XercesDocumentFragmentWrapper, which is a class that doesn't seem
> to exist.
>
> Am I on the right lines, or missing a much easier way? If I'm going in
> the right direction, why isn't there a XercesDocumentFragmentWrapper? Is
> it possible to build one myself, or is there some reason why it can't be
> built?
This is tricky to do, mostly because Xalan's source tree implementation
wasn't designed for randomly creating nodes. On the other hand, Xalan
itself does create result tree fragments, so you could look at the code
to see how it's done.
Take a look at
StylesheetExecutionContextDefault::beginCreateXResultTreeFrag() and
StylesheetExecutionContextDefault::beginCreateXResultTreeFrag as a
starting point. You might want to execute a stylesheet that generates a
result tree fragment and debug the code to see how it works.
You should also look at the DocumentBuilder sample application which is
a tutorial in generating an instance of the source tree.
The fundamental limitation is that you must create the instance using
SAX-like events, rather than DOM-like "create" and "insert" calls.
Please respond back if you have more questions.
Dave