dbertoni    02/05/10 14:54:12

  Added:       c/samples/ParsedSourceWrappers ParsedSourceWrappers.cpp
                        ParsedSourceWrappers.dsp foo.xml foo.xsl
  Log:
  Initial revision.
  
  Revision  Changes    Path
  1.1                  
xml-xalan/c/samples/ParsedSourceWrappers/ParsedSourceWrappers.cpp
  
  Index: ParsedSourceWrappers.cpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  #include <cassert>
  #if defined(XALAN_OLD_STREAM_HEADERS)
  #include <iostream.h>
  #include <strstream.h>
  #else
  #include <iostream>
  #include <strstream>
  #endif
  
  
  
  #include <xercesc/framework/URLInputSource.hpp>
  #include <xercesc/parsers/DOMParser.hpp>
  #include <xercesc/util/PlatformUtils.hpp>
  
  
  
  #include <PlatformSupport/URISupport.hpp>
  
  
  
  #include <XercesParserLiaison/XercesParserLiaison.hpp>
  #include <XercesParserLiaison/XercesDOMSupport.hpp>
  
  
  
  #include <XalanSourceTree/XalanSourceTreeDOMSupport.hpp>
  #include <XalanSourceTree/XalanSourceTreeParserLiaison.hpp>
  
  
  
  #include <XalanTransformer/XalanTransformer.hpp>
  #include <XalanTransformer/XercesDOMWrapperParsedSource.hpp>
  #include <XalanTransformer/XalanSourceTreeWrapperParsedSource.hpp>
  
  
  
  int
  transformXercesDOM(
                        XalanTransformer&                               
theTransformer,
                        const XalanDOMString&                   theURI,
                        const XalanCompiledStylesheet*  theStylesheet,
                        const XSLTResultTarget&                 theResultTarget)
  {
        const URLInputSource    theInputSource(theURI.c_str());
  
        DOMParser                               theParser;
  
        theParser.parse(theInputSource);
  
        DOM_Document                    theDocument = theParser.getDocument();
  
        XercesParserLiaison             theParserLiaison;
        XercesDOMSupport                theDOMSupport;
  
        XercesDOMWrapperParsedSource    theWrapper(theDocument, 
theParserLiaison, theDOMSupport, theURI);
  
        return theTransformer.transform(
                                                theWrapper,
                                                theStylesheet,
                                                theResultTarget);
  }
  
  
  
  int
  transformXalanSourceTree(
                        XalanTransformer&                               
theTransformer,
                        const XalanDOMString&                   theURI,
                        const XalanCompiledStylesheet*  theStylesheet,
                        const XSLTResultTarget&                 theResultTarget)
  {
        const URLInputSource                    theInputSource(theURI.c_str());
  
        XalanSourceTreeParserLiaison    theParserLiaison;
        XalanSourceTreeDOMSupport               theDOMSupport(theParserLiaison);
  
        XalanDocument* const    theDocument = 
theParserLiaison.parseXMLStream(theInputSource, theURI);
  
        XalanSourceTreeDocument* const  theSourceTreeDocument = 
theParserLiaison.mapDocument(theDocument);
        assert(theSourceTreeDocument != 0);
  
        XalanSourceTreeWrapperParsedSource      
theWrapper(theSourceTreeDocument, theParserLiaison, theDOMSupport, theURI);
  
        return theTransformer.transform(
                                                theWrapper,
                                                theStylesheet,
                                                theResultTarget);
  }
  
  
  
  int
  transform()
  {
  #if !defined(XALAN_NO_NAMESPACES)
        using std::cout;
        using std::cerr;
      using std::endl;
  #endif
  
        int             theResult = -1;
  
        try
        {
                // Create a XalanTransformer.
                XalanTransformer        theTransformer;
  
                const XSLTInputSource   theStylesheetInputSource("foo.xsl");
  
                // Let's compile the stylesheet and re-use it...
                const XalanCompiledStylesheet*          theStylesheet = 0;
  
                if (theTransformer.compileStylesheet(theStylesheetInputSource, 
theStylesheet) != 0)
                {
                        cerr << "An error occurred compiling the stylesheet: "
                                 << theTransformer.getLastError()
                                 << endl;
                }
                else
                {
                        assert(theStylesheet != 0);
  
                        const XalanDOMString    theInputFile("foo.xml");
  
                        const XalanDOMString    
theURI(URISupport::getURLStringFromString(theInputFile));
  
                        const XSLTResultTarget  theResultTarget(&cout);
  
                        theResult = transformXercesDOM(theTransformer, theURI, 
theStylesheet, theResultTarget);
  
                        if (theResult == 0)
                        {
                                cout << endl;
  
                                theResult = 
transformXalanSourceTree(theTransformer, theURI, theStylesheet, 
theResultTarget);
                        }
  
                        if (theResult != 0)
                        {
                                cerr << "Transformation failed: " << 
theTransformer.getLastError() << endl;
                        }
                }
        }
        catch(...)
        {
                cerr << "An unknown error occurred!" << endl;
        }
  
        return theResult;
  }
  
  // This sample shows how existing Xerces DOM_Document instances and 
XalanSourceTreeDocument
  // instances can be wrapped to use as input for to an instance of 
XalanTransformer.
  int
  main(
                        int                              argc,
                        const char*              /* argv */[])
  {
  #if !defined(XALAN_NO_NAMESPACES)
        using std::cout;
        using std::cerr;
      using std::endl;
  #endif
  
        int             theResult = -1;
  
      if (argc != 1)
        {
                cerr << "Usage: ParsedSourceWrappers" << endl;
        }
        else
        {
                try
                {
                        // Call the static initializer for Xerces.
                        XMLPlatformUtils::Initialize();
  
                        // Initialize Xalan.
                        XalanTransformer::initialize();
  
                        theResult = transform();
  
                        // Terminate Xalan.
                        XalanTransformer::terminate();
  
                        // Call the static terminator for Xerces.
                        XMLPlatformUtils::Terminate();
                }
                catch(...)
                {
                        cerr << "Initialization failed!" << endl;
                }
        }
  
        return theResult;
  }
  
  
  
  1.1                  
xml-xalan/c/samples/ParsedSourceWrappers/ParsedSourceWrappers.dsp
  
  Index: ParsedSourceWrappers.dsp
  ===================================================================
  # Microsoft Developer Studio Project File - Name="ParsedSourceWrappers" - 
Package Owner=<4>
  # Microsoft Developer Studio Generated Build File, Format Version 6.00
  # ** DO NOT EDIT **
  
  # TARGTYPE "Win32 (x86) Console Application" 0x0103
  
  CFG=ParsedSourceWrappers - Win32 Debug
  !MESSAGE This is not a valid makefile. To build this project using NMAKE,
  !MESSAGE use the Export Makefile command and run
  !MESSAGE 
  !MESSAGE NMAKE /f "ParsedSourceWrappers.mak".
  !MESSAGE 
  !MESSAGE You can specify a configuration when running NMAKE
  !MESSAGE by defining the macro CFG on the command line. For example:
  !MESSAGE 
  !MESSAGE NMAKE /f "ParsedSourceWrappers.mak" CFG="ParsedSourceWrappers - 
Win32 Debug"
  !MESSAGE 
  !MESSAGE Possible choices for configuration are:
  !MESSAGE 
  !MESSAGE "ParsedSourceWrappers - Win32 Release" (based on "Win32 (x86) 
Console Application")
  !MESSAGE "ParsedSourceWrappers - Win32 Debug" (based on "Win32 (x86) Console 
Application")
  !MESSAGE 
  
  # Begin Project
  # PROP AllowPerConfigDependencies 0
  # PROP Scc_ProjName ""
  # PROP Scc_LocalPath ""
  CPP=cl.exe
  RSC=rc.exe
  
  !IF  "$(CFG)" == "ParsedSourceWrappers - Win32 Release"
  
  # PROP BASE Use_MFC 0
  # PROP BASE Use_Debug_Libraries 0
  # PROP BASE Output_Dir "Release"
  # PROP BASE Intermediate_Dir "Release"
  # PROP BASE Target_Dir ""
  # PROP Use_MFC 0
  # PROP Use_Debug_Libraries 0
  # PROP Output_Dir "..\..\Build\Win32\VC6\Release"
  # PROP Intermediate_Dir "..\..\Build\Win32\VC6\Release\ParsedSourceWrappers"
  # PROP Ignore_Export_Lib 0
  # PROP Target_Dir ""
  # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D 
"_MBCS" /YX /FD /c
  # ADD CPP /nologo /MD /W4 /GR /GX /O2 /Ob2 /I "..\..\..\..\xml-xerces\c\src" 
/I "..\..\src" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /c
  # SUBTRACT CPP /YX
  # ADD BASE RSC /l 0x409 /d "NDEBUG"
  # ADD RSC /l 0x409 /d "NDEBUG"
  BSC32=bscmake.exe
  # ADD BASE BSC32 /nologo
  # ADD BSC32 /nologo
  LINK32=link.exe
  # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib 
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib 
odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib 
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib 
odbccp32.lib /nologo /subsystem:console /machine:I386
  # ADD LINK32 ..\..\..\..\xml-xerces\c\Build\Win32\VC6\Release\xerces-c_1.lib 
/nologo /subsystem:console /machine:I386
  
  !ELSEIF  "$(CFG)" == "ParsedSourceWrappers - Win32 Debug"
  
  # PROP BASE Use_MFC 0
  # PROP BASE Use_Debug_Libraries 1
  # PROP BASE Output_Dir "Debug"
  # PROP BASE Intermediate_Dir "Debug"
  # PROP BASE Target_Dir ""
  # PROP Use_MFC 0
  # PROP Use_Debug_Libraries 1
  # PROP Output_Dir "..\..\Build\Win32\VC6\Debug"
  # PROP Intermediate_Dir "..\..\Build\Win32\VC6\Debug\ParsedSourceWrappers"
  # PROP Ignore_Export_Lib 0
  # PROP Target_Dir ""
  # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D 
"_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
  # ADD CPP /nologo /MDd /W4 /Gm /GR /GX /Zi /Od /I 
"..\..\..\..\xml-xerces\c\src" /I "..\..\src" /D "WIN32" /D "_DEBUG" /D 
"_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
  # ADD BASE RSC /l 0x409 /d "_DEBUG"
  # ADD RSC /l 0x409 /d "_DEBUG"
  BSC32=bscmake.exe
  # ADD BASE BSC32 /nologo
  # ADD BSC32 /nologo
  LINK32=link.exe
  # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib 
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib 
odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib 
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib 
odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
  # ADD LINK32 ..\..\..\..\xml-xerces\c\Build\Win32\VC6\Debug\xerces-c_1D.lib 
/nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
  
  !ENDIF 
  
  # Begin Target
  
  # Name "ParsedSourceWrappers - Win32 Release"
  # Name "ParsedSourceWrappers - Win32 Debug"
  # Begin Group "Source Files"
  
  # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
  # Begin Source File
  
  SOURCE=.\ParsedSourceWrappers.cpp
  # End Source File
  # End Group
  # Begin Group "Header Files"
  
  # PROP Default_Filter "h;hpp;hxx;hm;inl"
  # End Group
  # Begin Group "Resource Files"
  
  # PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
  # End Group
  # End Target
  # End Project
  
  
  
  1.1                  xml-xalan/c/samples/ParsedSourceWrappers/foo.xml
  
  Index: foo.xml
  ===================================================================
  <?xml version="1.0"?>
  <doc>
    <a name="value">a text</a>
    <b name="value">b text</b>
    <c name="value">c text</c>
    <d name="value">d text</d>
    <e name="value">e text</e>
  </doc>
  
  
  
  1.1                  xml-xalan/c/samples/ParsedSourceWrappers/foo.xsl
  
  Index: foo.xsl
  ===================================================================
  <?xml version="1.0"?> 
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
version="1.0">
  
  <xsl:template match="node() | @*">
    <xsl:copy>
        <xsl:apply-templates select="node() | @*"/>
    </xsl:copy>
  </xsl:template>
  
  </xsl:stylesheet>
  
  
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to