Created
June 12, 2017 20:55
-
-
Save svelleweetakealot/952e80c1480206312113e320eebbdbd5 to your computer and use it in GitHub Desktop.
xslt lib example in go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
/* | |
#cgo pkg-config: libxslt | |
#include <string.h> | |
#include <libxml/xmlmemory.h> | |
#include <libxml/debugXML.h> | |
#include <libxml/HTMLtree.h> | |
#include <libxml/xmlIO.h> | |
#include <libxml/DOCBparser.h> | |
#include <libxml/xinclude.h> | |
#include <libxml/catalog.h> | |
#include <libxslt/xslt.h> | |
#include <libxslt/xsltInternals.h> | |
#include <libxslt/transform.h> | |
#include <libxslt/xsltutils.h> | |
static void usage(const char *name) { | |
printf("Usage: %s [options] stylesheet file [file ...]\n", name); | |
printf(" --param name value : pass a (parameter,value) pair\n"); | |
} | |
extern int xmlLoadExtDtdDefaultValue; | |
static void init(const char* stylesheet, const char* document) { | |
xsltStylesheetPtr cur = NULL; | |
xmlDocPtr doc, res; | |
xmlSubstituteEntitiesDefault(1); | |
xmlLoadExtDtdDefaultValue = 1; | |
cur = xsltParseStylesheetFile((const xmlChar*) stylesheet); | |
doc = xmlParseFile(document); | |
res = xsltApplyStylesheet(cur, doc, NULL); | |
xsltSaveResultToFile(stdout, res, cur); | |
xsltFreeStylesheet(cur); | |
xmlFreeDoc(res); | |
xmlFreeDoc(doc); | |
xsltCleanupGlobals(); | |
xmlCleanupParser(); | |
} | |
*/ | |
import "C" | |
import ( | |
"os" | |
) | |
func main() { | |
if len(os.Args) < 3 { | |
C.usage(C.CString(os.Args[0])) | |
} | |
C.init(C.CString(os.Args[1]), C.CString(os.Args[2])) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'd problems to build in ubuntu. I solved by installing the next packages.
When it built prompts the next warning
Deleting line 10 there were no warnings
There was a panic when it run without args
Just added a return after usage
I ran a example with xsltproc to compare the result an was the same.