Hi,
   
   I modified the XalanTransform sample app that comes with the distribution
of xalan 1.2 c++ in order to accept a DOM Document as input just as it's
explained on the basic usage patterns section on the xalan website, but it
doesn't work, I get the error:

An exception occured! Type:RuntimeException, Message:The primary document
entity could not be opened. Id={null}


here is the source:

#include <util/PlatformUtils.hpp>
#include <parsers/DOMParser.hpp>
#include <dom/DOM_Node.hpp>
#include <Include/PlatformDefinitions.hpp>
#include <util/PlatformUtils.hpp>
#include <XalanTransformer/XalanTransformer.hpp>
#include <XercesParserLiaison/XercesDOMSupport.hpp>
#include <XercesParserLiaison/XercesParserLiaison.hpp>
#include <XalanDOM/XalanDocument.hpp>
//#include <XalanTransformer/XalanTransformer.hpp>



#if defined(XALAN_OLD_STREAM_HEADERS)
#include <iostream.h>
#include <strstream.h>
#else
#include <iostream>
#include <strstream>
#endif



int
main(
                        int                              argc,
                        const char*              argv[])
{
#if !defined(XALAN_NO_NAMESPACES)
        using std::ostrstream;
        using std::cout;
        using std::cerr;
    using std::endl;
#endif

    if (argc < 3 || argc > 4)
        {
                cerr << "Usage: XalanTransform XMLFileName XSLFileName
[OutFileName]" << endl;
                return -1;
        }

        // Call the static initializer for Xerces.
        XMLPlatformUtils::Initialize();

    // Initialize Xalan.
    XalanTransformer::initialize();

        DOMParser  theParser;
// You MUST instruct the Xerces DOMParser NOT to create a DOM_XMLDecNode
// in the DOM to represent the XML declaration. See "Limitations" below.
theParser.setToCreateXMLDeclTypeNode(false);
theParser.parse("foo.xml");
const DOM_Document theDOM = theParser.getDocument();

// Set up a XercesParserLiaison and use it to wrap the DOM_Document
// in a XalanDocument.
XercesDOMSupport   theDOMSupport;
XercesParserLiaison     theParserLiaison(theDOMSupport);
XalanDocument* theDoc = theParserLiaison.createDocument(theDOM);

// Use the XalanDocument to create an XSLTInputSource object, which
// you can then use in a transformation.
XSLTInputSource         theInputSource(theDoc);

    // Create a XalanTransformer.
        XalanTransformer theXalanTransformer;

    int                         theResult = 0;

    if (argc == 4)
        {
        // Do the transform.
        theResult = theXalanTransformer.transform(argv[1], argv[2],
argv[3]);
        
        if(theResult != 0)
            {
                    cerr << "XalanError: \n" <<
theXalanTransformer.getLastError();
            }
    }
    else
    {
        // Do the transform.
        theResult = theXalanTransformer.transform(theInputSource, argv[2],
cout);
        
        if(theResult != 0)
            {
                    cerr << "XalanError: \n" <<
theXalanTransformer.getLastError();
            }
    }

    // Terminate Xalan.
        XalanTransformer::terminate();

        // Call the static terminator for Xerces.
        XMLPlatformUtils::Terminate();

        return theResult;
}



I hardcoded foo.xml as the xml file to be parsed and I use foo.xsl as the
stylesheet.

foo.xml

<?xml version="1.0"?>
<vxml>
 this is a test
</vxml>



foo.xsl

<?xml version="1.0"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
  <xsl:output doctype-public="-//Nuance/DTD VoiceXML 1.0b//EN"
              doctype-system="http://www.nuance.com/????/nvxml0_9_3.dtd"/>
    
  <xsl:template match="vxml">
     <vx> this really is a test </vx>
  </xsl:template>

</xsl:stylesheet>

Reply via email to