14 #include <libxslt/xsltutils.h>
15 #include <libxslt/transform.h>
18 #include "include/priv_xml.h"
23 xsltStylesheetPtr
doc;
36 static void *xslt_has_init_parser = NULL;
38 static void free_xsltdoc(
void *data) {
41 xsltFreeStylesheet(xsltdoc->
doc);
46 static void free_parser(
void *data) {
51 static int32_t xslt_hash(
const void *data,
int key) {
54 const char *hashkey = (key) ? data : xp->
name;
57 ret =
jenhash(hashkey, strlen(hashkey), 0);
59 ret =
jenhash(xp,
sizeof(xp), 0);
70 if (!(xsltdoc =
objalloc(
sizeof(*xsltdoc), free_xsltdoc))) {
75 xsltdoc->
doc = xsltParseStylesheetFile((
const xmlChar *)xsltfile);
80 static void free_param(
void *data) {
83 free((
void *)param->
name);
86 free((
void *)param->
value);
98 if (!xsltdoc || !xsltdoc->
params || !
objref(xsltdoc) || !(xparam =
objalloc(
sizeof(*xparam), free_param))) {
102 size = strlen(value) + 3;
104 xparam->
value = malloc(size);
105 snprintf((
char *)xparam->
value, size,
"'%s'", value);
116 if (!xsltdoc || !xsltdoc->
params) {
127 static const char **xslt_params(
struct xml_doc *xmldoc,
struct xslt_doc *xsltdoc) {
128 const char **params = NULL;
152 params[cnt] = xparam->
name;
154 params[cnt] = xparam->
value;
168 const char **params = NULL;
172 if (!(params = xslt_params(xmldoc, xsltdoc))) {
177 touch(filename, 80, 80);
182 res = xsltApplyStylesheet(xsltdoc->
doc, xmldoc->doc, params);
183 xsltSaveResultToFilename(filename, res, xsltdoc->
doc, comp);
199 struct xml_buffer *xmlbuf;
207 if (!(params = xslt_params(xmldoc, xsltdoc))) {
213 res = xsltApplyStylesheet(xsltdoc->
doc, xmldoc->doc, params);
214 xsltSaveResultToString(&xmlbuf->buffer, &xmlbuf->size, res, xsltdoc->
doc);
231 if (!xslt_has_init_parser) {
232 xslt_has_init_parser=
objalloc(0, free_parser);
234 objref(xslt_has_init_parser);
242 if (xslt_has_init_parser) {
struct xslt_doc * xslt_open(const char *xsltfile)
Open a XSLT file returning reference to it.
void xslt_clearparam(struct xslt_doc *xsltdoc)
Delete all parameters of a XSLT document.
void * create_bucketlist(int bitmask, blisthash hash_function)
int objref(void *data)
Reference a object.
struct xml_doc xml_doc
Forward decleration of structure.
int objlock(void *data)
Lock the reference.
const char * value
value of paramater.
void * xslt_apply_buffer(struct xml_doc *xmldoc, struct xslt_doc *xsltdoc)
Apply XSLT document to a XML document returning result in buffer.
void * objalloc(int size, objdestroy)
Allocate a referenced lockable object.
void xml_free_buffer(void *data)
Reference destructor for xml_buffer.
int bucket_list_cnt(struct bucket_list *blist)
Return number of items in the list.
void * next_bucket_loop(struct bucket_loop *bloop)
Return a reference to the next item in the list this could be the first item.
void xslt_init()
Reference the XSLT parser.
DTS Application library API Include file.
const char * name
Name of paramater.
void xslt_close()
Release reference to XSLT parser.
void touch(const char *filename, uid_t user, gid_t group)
Create a file and set user and group.
int objunlock(void *data)
Unlock a reference.
void xslt_addparam(struct xslt_doc *xsltdoc, const char *param, const char *value)
Add a parameter to the XSLT document.
xsltStylesheetPtr doc
Pointer to the document.
#define jenhash(key, length, initval)
Define jenhash as hashlittle on big endian it should be hashbig.
#define ALLOC_CONST(const_var, val)
Macro to assign values to char const.
int addtobucket(struct bucket_list *blist, void *data)
Add a reference to the bucketlist.
XSLT Parameter name/value pair.
int objunref(void *data)
Drop reference held.
struct bucket_loop * init_bucket_loop(struct bucket_list *blist)
Create a bucket list iterator to safely iterate the list.
struct bucket_list * params
Bucket list of paramaters to apply to the document.
Bucket list, hold hashed objects in buckets.
void xslt_apply(struct xml_doc *xmldoc, struct xslt_doc *xsltdoc, const char *filename, int comp)
Apply XSLT document to a XML document.