My exslt command-line processor is built using Xalan-C++ 1.11 and Xerces-C++ 3.1.1.
I do not use the old xalan command-line executable. It is based on the old xalan-1.10 distribution. I am working on the currentSVN (1.11). Here is the exslt.c source I am using to generate the new XALAN web pages. If you use exslt.c on a Linux or Unix, you may need to remove or comment out the #include <windows.h>. This exslt program is useful for validating basic xml correctness and does an excelent job with XSLT-1.0 stylesheets. I have commented out the installer I use with various XPath custom extended function libraries. Also included is a Windows command or batch file I use to launch Visual Studio .NET with custom environment variables. I find that the Visual Studio .NET products are very cumbersome when it comes to complex build and system debug environment variable management. I have not tried porting XALAN to Visual Studio .NET 2010, but it works well with .NET 2003, 2005 and 2008. #>Harash Gupta: wrote > Hi All, > > I'm a developer and want to use XALAN for transforming XML files. I've a > doubt whether to go for XALAN command line or shall I write a module using > XALAN-C++ API's? I can understand that using the API's, I can have more > flexibility, but the only thing I want is to transform the XML file and show > error to the users. Therefore, I want to know the difference between them in > terms of the functionalities or the advantages/limitations one has on the > other. > > Please point me to the right direction. > > Thanks! > Harsh Gupta ENJOY! - Steven J. Hathaway =========================================================== Make the following change to resolve XMLCh typedef when using C compiler. This is an un-committed JIRA issue. File: xalan/c/src/xalanc/Include/PlatformDefinitions.hpp #if defined(__cplusplus) # include "xercesc/util/XercesDefs.hpp" #else /* Include autoconf to define XMLCh when XercesDefs is bypassed */ # include "xercesc/util/Xerces_autoconf_config.hpp" # include "xercesc/util/XercesVersion.hpp" #endif =========================================================== == exslt.c command line source file - xalan-c++ (xalanCAPI) =========================================================== /* * Oregon State Police, Law Enforcement Data System * Salem, Oregon * * Copyright 2009-2011 Oregon State Police / LEDS * * Using Apache Xalan/Xerces libraries that are licensed * under the Apache License, Version 2.0 (the "License"). * * You may obtain copies of the Apache license at * * http://www.apache.org/licenses/LICENSE-2.0 * * Since this software is a custom extension to the Xalan * XPATH supported library, and no change is made to the * distributed Xalan/Xerces sources, this software is made * available for incorporating into any product. * * The software contained herein is distributed on an "AS IS" * basis without warranties or conditions of any kind, either * express or implied. */ /* Main Program for 'C' Language based XSLT Transformation with custom * XPath extension cvdate function. */ #include <windows.h> #include <stdio.h> #include <xalanc/XalanTransformer/XalanCAPI.h> /* Declare the Local Xpath Functions Installer * * #include "OspXpath.h" * */ /* Define ISO C functions for deprecated POSIX functions */ #define strdup _strdup XalanHandle xalan; XalanCSSHandle theCSSHandle; XalanPSHandle thePSHandle; #define MAX_XSLT_PARAMS 9 typedef struct XsltParam_str{ char * parm; char * value; } XsltParamStruct; XsltParamStruct XsltParams[ MAX_XSLT_PARAMS +1] = {NULL, NULL}; const char * Usage = "\n\ USAGE = exslt [[-p \"param='value']\" ...] XMLfile [XSLTfile [OUTfile]] \n\n\ param is a top-level parameter name in XSLT stylesheet context \n\ value is the value associated with the parameter, must be quoted \n\ XMLfile is the path to a source XML file to be parsed \n\ XSLTfile is the path to the XSLT stylesheet file to be compiled \n\ OUTfile is the path to the transformed result file \n\n\ If only XMLfile exists, it is parsed and the first fatal error is located. \n\n\ If XSLTfile exists, then it is compiled and the first fatal error is located. \n\n\ Output is generated only if OUTfile is specified. \n"; int main (int argc, char * argv[]) { int args; int rtn; int i, j; char * ptr; char * tmpstr; char * theXMLFileName; char * theXSLFileName; char * theOutFileName; char * err; args=argc; /* Collect the (-p key='value') top-level XSLT parameters */ XsltParams[0].parm = NULL; XsltParams[0].value = NULL; for (i=1, j=0; i<argc; i++) { if (!strcmp(argv[i],"-p")) { i++; if (!argv[i]) { printf("%s",Usage); exit(1); } tmpstr = strdup(argv[i]); ptr = strchr(tmpstr, '='); if (!ptr) { printf("%s",Usage); exit(1); } *ptr++ = '\0'; XsltParams[j].parm = strdup(tmpstr); XsltParams[j].value = strdup(ptr); j++; if (j > MAX_XSLT_PARAMS) { printf("\nERROR: Too Many XSLT Parameters\n%s",Usage); exit(1); } XsltParams[j].parm = NULL; XsltParams[j].value = NULL; free(tmpstr); } else break; } if (argc == 1) { printf("%s",Usage); exit(1); } if ((args-i) >= 1) { theXMLFileName = strdup(argv[i]); } else { printf("\nERROR - XML Filename Not Specified\n"); exit(1); } if ((args-i) >= 2) { theXSLFileName = strdup(argv[i+1]); } if ((args-i) == 3) { theOutFileName = strdup(argv[i+2]); } if ((args-i) > 3) { printf("\nERROR - TOO MANY ARGUMENTS\n%s",Usage); exit(1); } XalanInitialize(); xalan = CreateXalanTransformer(); if (!xalan) { printf("\nERROR - Unable to create Xalan Transformer\n"); exit(1); } else { printf("\nXalan Transformer Created - Success\n"); } /* * Install the local Xpath Functions into XALAN xslt processor. */ /* * OSPXpathInstall(xalan,global); */ rtn = XalanParseSource( theXMLFileName, xalan, &thePSHandle ); if (rtn) { printf("\nERROR - Unable to parse XML File: %s\n", theXMLFileName); err = (char *) XalanGetLastError( xalan ); printf("%s\n", err); exit(1); } else { printf("\nXalan Parse Source - XML Read Success\n"); } /* * Install the Top-Level XSLT Parameters */ for (j=0; XsltParams[j].parm; j++) { XalanSetStylesheetParam( XsltParams[j].parm, XsltParams[j].value, xalan); } if ((args-i) >= 2) { rtn = XalanCompileStylesheet( theXSLFileName, xalan, &theCSSHandle ); if (rtn) { printf("\nERROR - Unable to Compile XSL Stylesheet: %s\n", theXSLFileName); err = (char *) XalanGetLastError( xalan ); printf("%s\n", err); exit(1); } else { printf("\nXalan Compile Stylesheet - Success\n"); } } if ((args-i) == 3) { rtn = XalanTransformToFilePrebuilt( thePSHandle, theCSSHandle, theOutFileName, xalan); if (rtn) { printf("\nERROR - Unable To Translate XML using XSLT\n"); err = (char *) XalanGetLastError( xalan ); printf("%s\n", err); exit(1); } else { printf("\nXalan Transformation Success - To File: %s\n", theOutFileName); } } /* Prepare to Exit */ if ((args-i) >= 2) XalanDestroyCompiledStylesheet( theCSSHandle, xalan ); XalanDestroyParsedSource( thePSHandle, xalan ); /* Uninstall LEMS Local Functions */ OSPXpathUninstall(xalan,global); DeleteXalanTransformer(xalan); exit(0); } // main() ==================================================================== == build-exslt.cmd - Command file to launch Microsoft Visual Studio ==================================================================== @ECHO OFF :: :: Establish clean working environment variables :: SET PATH=%WINDIR%\system32;%WINDIR%;%WINDIR%\Wbem SET INCLUDE= SET LIB= SET LIBPATH= SET SOURCE= :: Common source directory for xalan-src and xerces-src directories SET XROOTDIR=<path to where I install the xerces and xalan sources and runtimes> :: <XROOTDIR>\ :: bin\ exslt.exe :: :: Xalan-C_1_11.dll :: XalanMessages_1_11.dll :: xerces-c_3_1.dll :: :: Xalan-C_1_11D.dll :: XalanMessages_1_11D.dll :: xerces-c_e_1D.dll :: :: include\ LocalMsgData.hpp :: LocalMsgIndex.hpp :: lib\ Xalan-C_1.exp :: Xalan-C_1.lib :: XalanMessages_1_11.exp :: XalanMessages_1_11.lib :: xerces-c_3.lib :: xerces-c_3D.lib :: :: xalan-src\c\src\xalanc\... The Xalan-C++ source tree :: :: xerces-src\src\xrcesc\... The Xerces-C++ source tree :: :: :: The LIBPATH and SOURCE environment variables may not set by the "vcvars32.bat" :: When launching "devenv.exe" /useenv, the values become empty. Therefore we :: should redefine them here for default .NET IDE consistency. :: :: SET LIBPATH=$(FrameWorkDir)$(FrameWorkVersion) SET SOURCE=$(VCInstallDir)atlmfc\src\mfc;$(VCInstallDir)atlmfc\src\atl;$(VCInstallDir)crt\src :: :: Apply the C++ project path definitions from the Visual C++ compiler installation :: This is similar to the default internal definitions of the Visual Studio .NET. :: :: call "%VS71COMNTOOLS%vsvars32.bat" :: call "%VS80COMNTOOLS%vsvars32.bat" call "%VS90COMNTOOLS%vsvars32.bat" :: :: Now to setup the product specific build environment :: :: SET XERCESCROOT=%XROOTDIR%\xerces-src :: SET XALANCROOT=%XROOTDIR%\xalan-src\c SET XERCESCPKGDIR=%XROOTDIR%\XERCESCPKG SET XALANCPKGDIR=%XROOTDIR%\XALANCPKG SET XERCESCROOT=%XERCESCPKGDIR%\include SET XALANCROOT=%XALANCPKGDIR%\include SET INCLUDE=%INCLUDE%;%XERCESCROOT% SET INCLUDE=%INCLUDE%;%XALANCROOT%;%XALANCPKGDIR%\include\Nls\Include SET PATH=%PATH%;%XERCESCPKGDIR%\bin SET PATH=%PATH%;%XALANCPKGDIR%\bin SET LIB=%LIB%;%XERCESCPKGDIR%\lib SET LIB=%LIB%;%XALANCPKGDIR%\lib ::================================================================================= :: :: Here we can validate the standard Visual Studio .NET C++ directory paths :: before we call "devenv.exe" /useenv development evironment. :: Just remove the :: comment codes :: :: echo "--------------------------" :: echo PATH = %PATH% :: echo "--------------------------" :: echo INCLUDE = %INCLUDE% :: echo "--------------------------" :: echo LIB = %LIB% :: echo "--------------------------" :: echo LIBPATH = %LIBPATH% :: echo "--------------------------" :: echo SOURCE = %SOURCE% :: echo "--------------------------" :: :: :: Startup Visual Studio .NET (IDE) with the customized environment variables. :: Note: our custom environment variables $(LEMSDIR) etc. are usable in the :: development environment, but are not visible in the macro table definitions. :: Visual Studio .NET 2005 TeamWorks should be able to make these visible. :: devenv.exe "exslt\exslt.sln" /useenv :: From within Visual Studio .NET you can open Tools->Options->Project->C++ Directories :: to validate the definitions of PATH, INCLUDE, LIB, LIBPATH, and SOURCE. These :: are the environment variables that will be stored in %USERPROFILE% between sessions. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
