Sorry for the confusion.

This is the trick I was talking about:

    xercesc::DOMDocument * outDoc =
xercesc::DOMImplementation::getImplementation()->createDocument();
    xalanc::FormatterToXercesDOM  theFormatter(outDoc, 0);

The FormatterToXercesDOM instance can than be passed to the xalanc
transform method. This than transforms the output to an
xercesc::DOMDocument, which you can then manipulate with
appendChild/removeChild/etc.

The code I gave you is a fragment. The only parts of it your interested in
are the object references beginning with the namespaces identifier
"xercesc::*" and "xalanc::*".

The "new DOMDocumentImpl(outDoc);" call is a call to my own implementation
wrapper of the xercesc::DOMDocument class.

Also note that the mTransformer + mStyleSheet are defined as attributes of
my wrapper class:

  xalanc::XalanTransformer                mTransformer;
  const xalanc::XalanCompiledStylesheet * mStyleSheet;

I hope this provides some clarity.

Hans


> Thanks for the reply but..
>
>> The trick your looking for is outlined in transformToDocument method.
>
> Are you referring to:-
>
>       return new DOMDocumentImpl(outDoc); ??
>
> DOMDocumentImpl doesn't appear in the external API (packaged Doxyden),
> and the class in the implementation doesn't have a public constructor
> that matches the above as far as I can see...
>
> public:
>     DOMDocumentImpl(MemoryManager* const manager =
> XMLPlatformUtils::fgMemoryManager);
>     DOMDocumentImpl(const XMLCh*     namespaceURI,     //DOM Level 2
>                     const XMLCh*     qualifiedName,
>                     DOMDocumentType* doctype,
>                     MemoryManager* const manager =
> XMLPlatformUtils::fgMemoryManager);
>
> ...
>
> private:
> ...
>     //
> -----------------------------------------------------------------------
>     // Unimplemented constructors and operators
>     //
> -----------------------------------------------------------------------
>     DOMDocumentImpl(const DOMDocumentImpl &);
>     DOMDocumentImpl & operator = (const DOMDocumentImpl &);
>
> What am I missing ....?
>
>
> -----Original Message-----
> From: Hans Smit [mailto:jcs...@xs4all.nl]
> Sent: 14 August 2009 13:23
> To: xalan-c-users@xml.apache.org
> Subject: RE: Relative newbie question - How to augment XSLT generated
> output?
>
> This may be what your looking for:
>
> NOTE: this is just a fragment of a class I've developed, so if you try
> to
> compile "as-is" you will get errors. The trick your looking for is
> outlined in transformToDocument method.
>
> Just in case your wondering about the "xmlapi" namespace - I developed
> an
> API that wraps xercesc/msxml2/libxml API's into one easy to use
> interface.
> Toggling between vendors is just a matter of flicking a processor
> switch.
> Nice.
>
> [source]
>
> ...
>
>   //--------------------------------------------------------------
>   xmlapi::DOMDocument::ptr      transformToDocument () {
>
>     xercesc::DOMDocument * outDoc =
> xercesc::DOMImplementation::getImplementation()->createDocument();
>     xalanc::FormatterToXercesDOM  theFormatter(outDoc, 0);
>     transform_impl(theFormatter);
>     return new DOMDocumentImpl(outDoc);
>   }
>
>   //--------------------------------------------------------------
>   void                          transform (std::ostream & sstrm, bool
> indent) {
>     transform_impl(sstrm);
>   }
>
> private:
>   //--------------------------------------------------------------
>   template<class Output>
>   void                          transform_impl (Output & out) {
>     int err = 0;
>     xalanc::XercesParserLiaison parserLiaison;
> #ifdef XERCESC_3
>     xalanc::XercesDOMSupport domSupport(parserLiaison);
> #else
>     xalanc::XercesDOMSupport     domSupport;
> #endif
>     if (mInput.get() == NULL) {
>       throw xmlapi::XMLException(EXCEPTION_HERE, "input xml is NULL");
>     }
>     if (mStyleSheet == NULL) {
>       throw xmlapi::XMLException(EXCEPTION_HERE, "compiled styleheet is
> NULL");
>     }
>     bool threadSafe = true;
>     bool buildWrapper = true;
>     xercesc::DOMDocument * xmlDoc =
> dynamic_cast<DOMDocumentImpl*>(mInput.get())->mDoc;
>     xalanc::XalanDocument * xalanDocument =
> parserLiaison.createDocument(xmlDoc, threadSafe, buildWrapper);
>     xalanc::XercesDOMWrapperParsedSource parsedSource (
>       parserLiaison.mapToXercesDocument(xalanDocument),
>       parserLiaison,
>       domSupport,
>       xalanc::XalanDOMString()
>     );
>     err = mTransformer.transform(parsedSource, mStyleSheet, out);
>     if (err) {
>       const char * errMsg = mTransformer.getLastError();
>       if (!errMsg) {
>         errMsg = "Unknown transform exception";
>       }
>       throw xmlapi::XMLException(EXCEPTION_HERE, errMsg);
>     }
>   }
>
> ...
>
> [/source]
>
>
> Kind regards,
>
> Hans
>
>
>
>>>However, you might want to look at the XSLT document function, instead
>>>of generating a result DOM and modifying it.  You can use the
>>>xsl:copy-of instruction to copy an entire document
>>
>> While that sounds like an eminently good suggestion, I need to make
> this
>> change without altering the XSLT workings of this program.
>>
>>> If you want a mutable result, then yes, you have to use the Xerces-C
>> DOM.
>>
>> Ok, thanks so what I'm trying to is possible.  You probably haven't
>> wanted to tell me what is probably plainly obvious to anyone more
>> familiar with these API's, but how do I alter an existing DOM document
> -
>> I've seen and used the content handler to create a new document, but
>> once its 'endDocument' method has been called - can the constructed
>> document be further modified?
>>
>> -----Original Message-----
>> From: David Bertoni [mailto:dbert...@apache.org]
>> Sent: 13 August 2009 19:07
>> To: xalan-c-users@xml.apache.org
>> Subject: Re: Relative newbie question - How to augment XSLT generated
>> output?
>>
>> paul.band...@nomura.com wrote:
>>> I need to be able to augment an XSLT generated document by adding the
>>> contents of another document to it as a child node.  I tried
>> generating
>>> to an XalanSourceTreeDocument but when I invoked addChild an
>>> XalanDOMException was raised with code 7 (modification not allowed).
>> Do
>>> I need to generate to an Xerces DOM instead, using
>> FormatterToXercesDOM
>>> as per one of the examples, and if so what are the steps to add one
>>> document as the child of another XercesDOM - i.e. can I indeed add to
>> a
>>> fully formed document and do I need to clone the nodes from one
>> document
>>> before adding to another?
>> If you want a mutable result, then yes, you have to use the Xerces-C
>> DOM.
>>
>> However, you might want to look at the XSLT document function, instead
>> of generating a result DOM and modifying it.  You can use the
>> xsl:copy-of instruction to copy an entire document anywhere you like
> in
>> the result tree.  It will also be much more efficient than generating
> a
>> Xerces-C DOM document as the result, then appending another document.
>>
>> Dave
>>
>>
>>
>> This e-mail (including any attachments) is confidential, may contain
>> proprietary or privileged information and is intended for the named
>> recipient(s) only. Unintended recipients are prohibited from taking
> action
>> on the basis of information in this e-mail and must delete all copies.
>> Nomura will not accept responsibility or liability for the accuracy or
>> completeness of, or the presence of any virus or disabling code in,
> this
>> e-mail. If verification is sought please request a hard copy. Any
>> reference
>> to the terms of executed transactions should be treated as preliminary
>> only
>> and subject to formal written confirmation by Nomura. Nomura reserves
> the
>> right to monitor e-mail communications through its networks (in
> accordance
>> with applicable laws). No confidentiality or privilege is waived or
> lost
>> by
>> Nomura by any mistransmission of this e-mail. Any reference to
> "Nomura" is
>> a reference to any entity in the Nomura Holdings, Inc. group. Please
> read
>> our Electronic Communications Legal Notice which forms part of this
>> e-mail:
>> http://www.Nomura.com/email_disclaimer.htm
>>
>>
>>
>
>
>
>
>
> This e-mail (including any attachments) is confidential, may contain
> proprietary or privileged information and is intended for the named
> recipient(s) only. Unintended recipients are prohibited from taking action
> on the basis of information in this e-mail and must delete all copies.
> Nomura will not accept responsibility or liability for the accuracy or
> completeness of, or the presence of any virus or disabling code in, this
> e-mail. If verification is sought please request a hard copy. Any
> reference
> to the terms of executed transactions should be treated as preliminary
> only
> and subject to formal written confirmation by Nomura. Nomura reserves the
> right to monitor e-mail communications through its networks (in accordance
> with applicable laws). No confidentiality or privilege is waived or lost
> by
> Nomura by any mistransmission of this e-mail. Any reference to "Nomura" is
> a reference to any entity in the Nomura Holdings, Inc. group. Please read
> our Electronic Communications Legal Notice which forms part of this
> e-mail:
> http://www.Nomura.com/email_disclaimer.htm
>
>
>


Reply via email to