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 Phil IPS <ph...@yahoo.com> on 2004/07/22 11:05:54 UTC

[Bug 30229] I reproduced the bug in this "GetVariable.cpp" sample.

I posted the original bug 30229 in the Bugzilla database.

This mail contains a simple sample where the "getVariable()" method is not working the way it is
expected to.

As I do not exactly where I have to post, I prefer posting here.
(please tell me if I am wrong and if I should post somewhere else)


The joined files are :

 + the "GetVariable.cpp" source code,
 + the input "GetVariable.xml" and "GetVariable.xsl" files,
 + I stored the build commands in the "build.sh" file.


System infos :

 + Sun compiler :   "CC: Sun WorkShop 6 update 1 C++ 5.2 2000/09/11"
 + System :         "SunOS msmistral 5.8 Generic_108528-27 sun4u sparc SUNW,UltraAX-i2"



Here are the result I get :


1/ "var1" is a defined stylesheet variable.
The content of the variable is correctly output and the program finish correctly.

$ GetVariable var1

call getVariable()
getVariable() called
variable = "World !"
end of program



2/ "var2" is undefined so my program should print an error.
Instead of this, it seems that the "printVariable()" method returns in the "getVariable()" method
call (the "getVariable() called" message is not printed on the output)

$ GetVariable var2

call getVariable()
end of program


Thanks for having a look and tell me what's happening.


Phil




---------- START OF "GetVariable.cpp" ----------

/*
*********************************************************************
*                                                                   *
*                        GetVariable.cpp                            *
*                                                                   *
*********************************************************************
*/


#include <xalanc/Include/PlatformDefinitions.hpp>

#include <cassert>

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

#include <xercesc/util/PlatformUtils.hpp>
#include <xalanc/XalanTransformer/XalanTransformer.hpp>
#include <xalanc/XSLT/TraceListener.hpp>
#include <xalanc/XSLT/TracerEvent.hpp>
#include <xalanc/XSLT/SelectionEvent.hpp>
#include <xalanc/XSLT/GenerateEvent.hpp>
#include <xalanc/XSLT/StylesheetExecutionContext.hpp>
#include <xalanc/XalanDOM/XalanDOMString.hpp>
#include <xalanc/XPath/XalanQName.hpp>
#include <xalanc/XPath/XalanQNameByReference.hpp>
#include <xalanc/XPath/XObject.hpp>

using namespace std;

XALAN_USING_XERCES(XMLPlatformUtils)
XALAN_USING_XALAN(XalanTransformer)
XALAN_USING_XALAN(TraceListener)
XALAN_USING_XALAN(TracerEvent)
XALAN_USING_XALAN(SelectionEvent)
XALAN_USING_XALAN(GenerateEvent)
XALAN_USING_XALAN(StylesheetExecutionContext)
XALAN_USING_XALAN(XalanDOMString)
XALAN_USING_XALAN(XalanQName)
XALAN_USING_XALAN(XalanQNameByReference)
XALAN_USING_XALAN(XObject)
XALAN_USING_XALAN(XObjectPtr)


/* Derivated user-defined TraceListener class */

class GetVariableTraceListener : public TraceListener
	{
	public:
		
		GetVariableTraceListener(const char *pArg){ m_pArg = pArg; }
	 	~GetVariableTraceListener(){}

		void trace(const TracerEvent &aTracerEvent){}
		void generated(const GenerateEvent &aGenerateEvent){}


		void selected(const SelectionEvent &aSelectionEvent)
			{
			printVariable(XalanQNameByReference(XalanDOMString(m_pArg)), (StylesheetExecutionContext *)
&aSelectionEvent.m_executionContext);
			}


		void printVariable(XalanQName &aXalanQName, StylesheetExecutionContext
*pStylesheetExecutionContext)
			{
			XObjectPtr aXObjectPtr;


			cerr << "call getVariable()" << endl;
			aXObjectPtr = pStylesheetExecutionContext->getVariable(aXalanQName);
			cerr << "getVariable() called" << endl;

			if(aXObjectPtr.null() == false)
				{
				cerr << "variable = \"" << aXObjectPtr->str() << "\"" << endl;
				}
		
			else
				{
				cerr << "error: variable undefined !" << endl;
				}
			}


	private:

		const char *m_pArg;
	};



/* main function */

int main(int argc, char *argv[])
	{
	XMLPlatformUtils::Initialize();
	XalanTransformer::initialize();

	if(argc < 2)
		{
		cerr << "You must type the variable name !" << endl;
		return 1;
		}

	XalanTransformer aXalanTransformer;
	GetVariableTraceListener aGetVariableTraceListener(argv[1]);

	aXalanTransformer.addTraceListener(&aGetVariableTraceListener);
	aXalanTransformer.transform("GetVariable.xml", "GetVariable.xsl", "GetVariable.out");

	cerr << "end of program" << endl;

	XalanTransformer::terminate();
	XMLPlatformUtils::Terminate();
	XalanTransformer::ICUCleanUp();

	return(0);
	}

---------- END OF "GetVariable.cpp" ----------




---------- START OF "GetVariable.xml" ----------

<?xml version="1.0"?>
<root>Hello</root>

---------- END OF "GetVariable.xml" ----------




---------- START OF "GetVariable.xsl" ----------

<?xml version="1.0"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="text"/>

	<xsl:variable name="var1">World !</xsl:variable>

  <xsl:template match="/">
    Hello <xsl:value-of select="$var1"/>
  </xsl:template>

</xsl:stylesheet>

---------- END OF "GetVariable.xsl" ----------




---------- START OF "build.sh" ----------

#!/bin/sh

/soft/workshop/SUNWspro_6/bin/CC -c -g -I. -I/soft/freeware/xalan-1.8-s7/include
-I/soft/freeware/xerces-2.5-s7/include/xercesc -I/soft/freeware/xerces-2.5-s7/include
GetVariable.cpp
/soft/workshop/SUNWspro_6/bin/CC -o GetVariable GetVariable.o -Bdynamic -lxalan-c -Bdynamic
-lxerces-c -Bdynamic -ldl -lsocket -lrt -lresolv -lnsl -lc -lsunmath

---------- END OF "build.sh" ----------



	
		
__________________________________
Do you Yahoo!?
Vote for the stars of Yahoo!'s next ad campaign!
http://advision.webevents.yahoo.com/yahoo/votelifeengine/