dbertoni    01/06/12 12:14:00

  Added:       c/samples/XalanTransformerCallback foo.xml foo.xsl
                        XalanTransformerCallback.cpp
                        XalanTransformerCallback.dsp
  Log:
  Initial revision.
  
  Revision  Changes    Path
  1.1                  xml-xalan/c/samples/XalanTransformerCallback/foo.xml
  
  Index: foo.xml
  ===================================================================
  <?xml version="1.0"?>
  <!DOCTYPE si>
  <s1 title="s1 foo">
    <s2 title="Foo">
      <p>Hello</p>
    </s2>
  </s1>
  
  
  1.1                  xml-xalan/c/samples/XalanTransformerCallback/foo.xsl
  
  Index: foo.xsl
  ===================================================================
  <?xml version="1.0"?>
  
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
    <xsl:output method="html" indent="yes"/>
      
    <xsl:template match="/">
      <xsl:apply-templates/>
    </xsl:template>
  
    <xsl:template match="s1">
      <html>
        <head><title><xsl:value-of select="@title"/></title></head>
        <body  bgcolor="#ffffff" text="#000000">
          <xsl:apply-templates select="s2"/>
        </body>
      </html>
    </xsl:template>
  
    <xsl:template match="s2">
      <table width="100%" border="0" cellspacing="0" cellpadding="4">
        <tr>
          <td bgcolor="#006699">
            <font color="#ffffff" size="+1">
              <b><xsl:value-of select="@title"/></b>
            </font>
          </td>
        </tr>
      </table>
      <xsl:apply-templates/>
      <br/>
    </xsl:template>
  
    <xsl:template match="p">
      <p><xsl:apply-templates/></p>
    </xsl:template>
  
    <xsl:template match="note">
      <table border="0" width="100%">
        <tr>
          <td width="20">&#160;</td>
          <td bgcolor="#88aacc">
            <font size="-1"><i>NOTE: <xsl:apply-templates/></i></font>
          </td>
          <td width="20">&#160;</td>
        </tr>
      </table>
    </xsl:template>
    
    <xsl:template match="ul">
      <ul><xsl:apply-templates/></ul>
    </xsl:template>
  
    <xsl:template match="ol">
      <ol><xsl:apply-templates/></ol>
    </xsl:template>
    
    <xsl:template match="gloss">
      <dl><xsl:apply-templates/></dl>
    </xsl:template>
     <!-- <term> contains a single-word, multi-word or symbolic 
         designation which is regarded as a technical term. --> 
    <xsl:template match="term">
      <dfn><xsl:apply-templates/></dfn>
    </xsl:template>
  
    <xsl:template match="label" priority="1">
      <dt><xsl:apply-templates/></dt>
    </xsl:template>
  
    <xsl:template match="item" priority="2">
      <dd>
        <xsl:apply-templates/>
      </dd>
    </xsl:template>
  
    <xsl:template match="table">
      <p align="center"><table border="0"><xsl:apply-templates/></table></p>
    </xsl:template>
  
    <xsl:template match="source">
      <table border="0" width="100%">
        <tr>
          <td width="20">&#160;</td>
          <td bgcolor="#88aacc"><pre><xsl:apply-templates/></pre></td>
          <td width="20">&#160;</td>
        </tr>
      </table>
    </xsl:template>
  
    <xsl:template match="li">
      <li><xsl:apply-templates/></li>
    </xsl:template>
  
    <xsl:template match="tr">
      <tr><xsl:apply-templates/></tr>
    </xsl:template>
  
    <xsl:template match="th">
      <td bgcolor="#006699" align="center">
        <font color="#ffffff"><b><xsl:apply-templates/></b></font>
      </td>
    </xsl:template>
  
    <xsl:template match="td">
      <td bgcolor="#88aacc"><xsl:apply-templates/>&#160;</td>
    </xsl:template>
  
    <xsl:template match="tn">
      <td>&#160;</td>
    </xsl:template>
  
    <xsl:template match="em">
      <b><xsl:apply-templates/></b>
    </xsl:template>
  
    <xsl:template match="ref">
      <i><xsl:apply-templates/></i>
    </xsl:template>
  
    <xsl:template match="code">
      <code><xsl:apply-templates/></code>
    </xsl:template>
  
    <xsl:template match="br">
      <br/>
    </xsl:template>
  
  
    <xsl:template match="jump">
      <a href="{@href}" target="_top"><xsl:apply-templates/></a>
    </xsl:template>  
  
    <xsl:template match="anchor">
      <a name="{@id}"> </a>
    </xsl:template>
  
    <xsl:template match="img">
      <img src="{@src}" align="right" border="0" vspace="4" hspace="4"/>
    </xsl:template>
    
  </xsl:stylesheet>
  
  
  1.1                  
xml-xalan/c/samples/XalanTransformerCallback/XalanTransformerCallback.cpp
  
  Index: XalanTransformerCallback.cpp
  ===================================================================
  #include <util/PlatformUtils.hpp>
  
  
  
  #include <XalanTransformer/XalanTransformer.hpp>
  
  
  
  #include <cstdio>
  
  #if defined(XALAN_OLD_STREAM_HEADERS)
  #include <iostream.h>
  #else
  #include <iostream>
  #endif
  
  
  
  // This is a simple class that illustrates how XalanTransformer's "callback" API
  // is used.  This example just abstracts writing data to a FILE*, but other
  // actions are possible.
  class CallbackHandler
  {
  public:
  
        CallbackHandler(FILE*   theFile) :
                m_file(theFile)
        {
                assert(m_file != 0);
        }
  
        unsigned long
        write(
                        const char*             theData,
                        unsigned long   theLength)
        {
                return fwrite(theData, sizeof(char), theLength, m_file);
        }
  
        void
        flush()
        {
                fflush(m_file);
        }
  
  private:
  
        FILE* const             m_file;
  };
  
  
  
  extern "C"
  {
  
  // This is the write callback function, which casts the handle
  // to the appropriate type, then calls the write() member function
  // on the CallbackHandler class.
  unsigned long
  writeCallback(
                        const char*             theData,
                        unsigned long   theLength,
                        void*                   theHandle)
  {
  #if defined(XALAN_OLD_STYLE_CASTS)
        return ((CallbackHandler*)theHandle)->write(theData, theLength)
  #else
        return reinterpret_cast<CallbackHandler*>(theHandle)->write(theData, 
theLength);
  #endif
  }
  
  // This is the fluxh callback function, which casts the handle
  // to the appropriate type, then calls the flush() member function
  // on the CallbackHandler class.
  void
  flushCallback(void*   theHandle)
  {
  #if defined(XALAN_OLD_STYLE_CASTS)
        ((CallbackHandler*)theHandle)->flush()
  #else
        reinterpret_cast<CallbackHandler*>(theHandle)->flush();
  #endif
  }
  
  };
  
  
  
  int
  doTransform(
                        const char*             theXMLFile,
                        const char*             theXSLFile,
                        FILE*                   theOutputFile)
  {
  #if !defined(XALAN_NO_NAMESPACES)
        using std::cerr;
      using std::endl;
  #endif
  
      // Create a XalanTransformer.
        XalanTransformer        theXalanTransformer;
  
        // Do the transform.
        CallbackHandler         theHandler(theOutputFile);
  
        // Do the transform.
        const int       theResult = theXalanTransformer.transform(
                                        theXMLFile,
                                        theXSLFile,
                                        &theHandler,
                                        writeCallback,
                                        flushCallback);
          
        if(theResult != 0)
        {
                cerr << "XalanError: " << theXalanTransformer.getLastError() << endl;
        }
  
        return theResult;
  }
  
  
  
  int
  main(
                        int                              argc,
                        const char*              argv[])
  {
  #if !defined(XALAN_NO_NAMESPACES)
        using std::cerr;
      using std::endl;
  #endif
  
      if (argc < 3 || argc > 4)
        {
                cerr << "Usage: XalanTransformerCallback XMLFileName XSLFileName 
[OutFileName]" << endl;
  
                return -1;
        }
  
        // Call the static initializer for Xerces.
        XMLPlatformUtils::Initialize();
  
      // Initialize Xalan.
      XalanTransformer::initialize();
  
      int                               theResult = 0;
  
      if (argc == 3)
        {
                // No output file, so use stdout...
                theResult = doTransform(argv[1], argv[2], stdout);
      }
      else
      {
                // Ooutput file specified, so try to open it...
                FILE* const     theOutputFile = fopen(argv[3], "w");
  
                if (theOutputFile == 0)
                {
                        cerr << "Error: " << "Unable to open output file " << argv[3] 
<< endl;
                }
                else
                {
                        theResult = doTransform(argv[1], argv[2], theOutputFile);
  
                        fclose(theOutputFile);
                }
      }
  
      // Terminate Xalan.
        XalanTransformer::terminate();
  
        // Call the static terminator for Xerces.
        XMLPlatformUtils::Terminate();
  
        return theResult;
  }
  
  
  
  1.1                  
xml-xalan/c/samples/XalanTransformerCallback/XalanTransformerCallback.dsp
  
  Index: XalanTransformerCallback.dsp
  ===================================================================
  # Microsoft Developer Studio Project File - Name="XalanTransformerCallback" - 
Package Owner=<4>
  # Microsoft Developer Studio Generated Build File, Format Version 6.00
  # ** DO NOT EDIT **
  
  # TARGTYPE "Win32 (x86) Console Application" 0x0103
  
  CFG=XalanTransformerCallback - 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 "XalanTransformerCallback.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 "XalanTransformerCallback.mak" CFG="XalanTransformerCallback - 
Win32 Debug"
  !MESSAGE 
  !MESSAGE Possible choices for configuration are:
  !MESSAGE 
  !MESSAGE "XalanTransformerCallback - Win32 Release" (based on "Win32 (x86) Console 
Application")
  !MESSAGE "XalanTransformerCallback - 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)" == "XalanTransformerCallback - 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\XalanTransformerCallback"
  # 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)" == "XalanTransformerCallback - 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\XalanTransformerCallback"
  # 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 "XalanTransformerCallback - Win32 Release"
  # Name "XalanTransformerCallback - Win32 Debug"
  # Begin Group "Source Files"
  
  # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
  # Begin Source File
  
  SOURCE=.\XalanTransformerCallback.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
  
  
  

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

Reply via email to