DTS Application Library  0.2.3
Application library containing referenced objects and interfaces to common libraries
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
XSLT Interface

Utilities for managing XML documents. More...

Files

file  libxslt.c
 XSLT Interface.
 

Data Structures

struct  xslt_doc
 XSLT Document. More...
 
struct  xslt_param
 XSLT Parameter name/value pair. More...
 

Typedefs

typedef struct xslt_doc xslt_doc
 Forward decleration of structure. More...
 

Functions

struct xslt_docxslt_open (const char *xsltfile)
 Open a XSLT file returning reference to it. More...
 
void xslt_addparam (struct xslt_doc *xsltdoc, const char *param, const char *value)
 Add a parameter to the XSLT document. More...
 
void xslt_clearparam (struct xslt_doc *xsltdoc)
 Delete all parameters of a XSLT document. More...
 
void xslt_apply (struct xml_doc *xmldoc, struct xslt_doc *xsltdoc, const char *filename, int comp)
 Apply XSLT document to a XML document. More...
 
void * xslt_apply_buffer (struct xml_doc *xmldoc, struct xslt_doc *xsltdoc)
 Apply XSLT document to a XML document returning result in buffer. More...
 
void xslt_init ()
 Reference the XSLT parser. More...
 
void xslt_close ()
 Release reference to XSLT parser. More...
 

Detailed Description

Utilities for managing XML documents.

Typedef Documentation

typedef struct xslt_doc xslt_doc

Forward decleration of structure.

Definition at line 634 of file dtsapp.h.

Function Documentation

void xslt_addparam ( struct xslt_doc xsltdoc,
const char *  param,
const char *  value 
)

Add a parameter to the XSLT document.

Parameters
xsltdocReference to XSLT document.
paramName of parameter.
valueParameter value.

Definition at line 94 of file libxslt.c.

References addtobucket(), ALLOC_CONST, xslt_param::name, objalloc(), objlock(), objref(), objunlock(), objunref(), xslt_doc::params, and xslt_param::value.

94  {
95  struct xslt_param *xparam;
96  int size;
97 
98  if (!xsltdoc || !xsltdoc->params || !objref(xsltdoc) || !(xparam = objalloc(sizeof(*xparam), free_param))) {
99  return;
100  }
101 
102  size = strlen(value) + 3;
103  ALLOC_CONST(xparam->name, param);
104  xparam->value = malloc(size);
105  snprintf((char *)xparam->value, size, "'%s'", value);
106  objlock(xsltdoc);
107  addtobucket(xsltdoc->params, xparam);
108  objunlock(xsltdoc);
109  objunref(xparam);
110  objunref(xsltdoc);
111 }
int objref(void *data)
Reference a object.
Definition: refobj.c:153
int objlock(void *data)
Lock the reference.
Definition: refobj.c:269
const char * value
value of paramater.
Definition: libxslt.c:33
void * objalloc(int size, objdestroy)
Allocate a referenced lockable object.
Definition: refobj.c:129
const char * name
Name of paramater.
Definition: libxslt.c:31
int objunlock(void *data)
Unlock a reference.
Definition: refobj.c:301
#define ALLOC_CONST(const_var, val)
Macro to assign values to char const.
Definition: dtsapp.h:959
int addtobucket(struct bucket_list *blist, void *data)
Add a reference to the bucketlist.
Definition: refobj.c:428
XSLT Parameter name/value pair.
Definition: libxslt.c:29
int objunref(void *data)
Drop reference held.
Definition: refobj.c:184
struct bucket_list * params
Bucket list of paramaters to apply to the document.
Definition: libxslt.c:25
void xslt_apply ( struct xml_doc xmldoc,
struct xslt_doc xsltdoc,
const char *  filename,
int  comp 
)

Apply XSLT document to a XML document.

Parameters
xmldocReference to XML document.
xsltdocReference to XSLT document.
filenameFile to write the result too.
compCompression level 0-9 [0 = none].

Definition at line 167 of file libxslt.c.

References xslt_doc::doc, objlock(), objunlock(), objunref(), touch(), and xslt_clearparam().

167  {
168  const char **params = NULL;
169  xmlDocPtr res;
170 
171  /* ref's xml/xslt locks xslt IF set*/
172  if (!(params = xslt_params(xmldoc, xsltdoc))) {
173  return;
174  }
175 
176 #ifndef __WIN32__
177  touch(filename, 80, 80);
178 #else
179  touch(filename);
180 #endif
181  objlock(xmldoc);
182  res = xsltApplyStylesheet(xsltdoc->doc, xmldoc->doc, params);
183  xsltSaveResultToFilename(filename, res, xsltdoc->doc, comp);
184  objunlock(xmldoc);
185  objunref(xmldoc);
186  objunlock(xsltdoc);
187 
188  free(params);
189  xmlFreeDoc(res);
190  xslt_clearparam(xsltdoc);
191  objunref(xsltdoc);
192 }
void xslt_clearparam(struct xslt_doc *xsltdoc)
Delete all parameters of a XSLT document.
Definition: libxslt.c:115
int objlock(void *data)
Lock the reference.
Definition: refobj.c:269
void touch(const char *filename, uid_t user, gid_t group)
Create a file and set user and group.
Definition: util.c:484
int objunlock(void *data)
Unlock a reference.
Definition: refobj.c:301
xsltStylesheetPtr doc
Pointer to the document.
Definition: libxslt.c:23
int objunref(void *data)
Drop reference held.
Definition: refobj.c:184
void* xslt_apply_buffer ( struct xml_doc xmldoc,
struct xslt_doc xsltdoc 
)

Apply XSLT document to a XML document returning result in buffer.

Parameters
xmldocReference to XML document.
xsltdocReference to XSLT document.
Returns
Reference to xml_buffer containing the result of the transform.

Definition at line 198 of file libxslt.c.

References xslt_doc::doc, objalloc(), objlock(), objunlock(), objunref(), xml_free_buffer(), and xslt_clearparam().

198  {
199  struct xml_buffer *xmlbuf;
200  const char **params;
201  xmlDocPtr res;
202 
203  if (!(xmlbuf = objalloc(sizeof(*xmlbuf),xml_free_buffer))) {
204  return NULL;
205  }
206 
207  if (!(params = xslt_params(xmldoc, xsltdoc))) {
208  objunref(xmlbuf);
209  return NULL;
210  }
211 
212  objlock(xmldoc);
213  res = xsltApplyStylesheet(xsltdoc->doc, xmldoc->doc, params);
214  xsltSaveResultToString(&xmlbuf->buffer, &xmlbuf->size, res, xsltdoc->doc);
215  objunlock(xmldoc);
216  objunref(xmldoc);
217  objunlock(xsltdoc);
218 
219  free(params);
220  xmlFreeDoc(res);
221  xslt_clearparam(xsltdoc);
222  objunref(xsltdoc);
223 
224  return xmlbuf;
225 }
void xslt_clearparam(struct xslt_doc *xsltdoc)
Delete all parameters of a XSLT document.
Definition: libxslt.c:115
int objlock(void *data)
Lock the reference.
Definition: refobj.c:269
void * objalloc(int size, objdestroy)
Allocate a referenced lockable object.
Definition: refobj.c:129
void xml_free_buffer(void *data)
Reference destructor for xml_buffer.
Definition: libxml2.c:46
int objunlock(void *data)
Unlock a reference.
Definition: refobj.c:301
xsltStylesheetPtr doc
Pointer to the document.
Definition: libxslt.c:23
int objunref(void *data)
Drop reference held.
Definition: refobj.c:184
void xslt_clearparam ( struct xslt_doc xsltdoc)

Delete all parameters of a XSLT document.

Parameters
xsltdocReference to XSLT document.

Definition at line 115 of file libxslt.c.

References create_bucketlist(), objlock(), objunlock(), objunref(), and xslt_doc::params.

Referenced by xslt_apply(), and xslt_apply_buffer().

115  {
116  if (!xsltdoc || !xsltdoc->params) {
117  return;
118  }
119 
120  objlock(xsltdoc);
121  objunref(xsltdoc->params);
122  xsltdoc->params = create_bucketlist(0, xslt_hash);
123  objunlock(xsltdoc);
124 }
void * create_bucketlist(int bitmask, blisthash hash_function)
Definition: refobj.c:356
int objlock(void *data)
Lock the reference.
Definition: refobj.c:269
int objunlock(void *data)
Unlock a reference.
Definition: refobj.c:301
int objunref(void *data)
Drop reference held.
Definition: refobj.c:184
struct bucket_list * params
Bucket list of paramaters to apply to the document.
Definition: libxslt.c:25
void xslt_close ( )

Release reference to XSLT parser.

Note
It is best if the application keeps a reference to the parser before use of XSLT and release it on termination.

Definition at line 241 of file libxslt.c.

References objunref().

241  {
242  if (xslt_has_init_parser) {
243  objunref(xslt_has_init_parser);
244  }
245 }
int objunref(void *data)
Drop reference held.
Definition: refobj.c:184
void xslt_init ( )

Reference the XSLT parser.

Note
It is best if the application keeps a reference to the parser before use of XSLT and release it on termination.

Definition at line 230 of file libxslt.c.

References objalloc(), and objref().

Referenced by xslt_open().

230  {
231  if (!xslt_has_init_parser) {
232  xslt_has_init_parser=objalloc(0, free_parser);
233  } else {
234  objref(xslt_has_init_parser);
235  }
236 }
int objref(void *data)
Reference a object.
Definition: refobj.c:153
void * objalloc(int size, objdestroy)
Allocate a referenced lockable object.
Definition: refobj.c:129
struct xslt_doc* xslt_open ( const char *  xsltfile)

Open a XSLT file returning reference to it.

Parameters
xsltfileXSLT pathname to open.
Returns
Reference to XSLT document.

Definition at line 67 of file libxslt.c.

References create_bucketlist(), xslt_doc::doc, objalloc(), xslt_doc::params, and xslt_init().

67  {
68  struct xslt_doc *xsltdoc;
69 
70  if (!(xsltdoc = objalloc(sizeof(*xsltdoc), free_xsltdoc))) {
71  return NULL;
72  }
73  xslt_init();
74 
75  xsltdoc->doc = xsltParseStylesheetFile((const xmlChar *)xsltfile);
76  xsltdoc->params = create_bucketlist(0, xslt_hash);
77  return xsltdoc;
78 }
void * create_bucketlist(int bitmask, blisthash hash_function)
Definition: refobj.c:356
void * objalloc(int size, objdestroy)
Allocate a referenced lockable object.
Definition: refobj.c:129
void xslt_init()
Reference the XSLT parser.
Definition: libxslt.c:230
xsltStylesheetPtr doc
Pointer to the document.
Definition: libxslt.c:23
XSLT Document.
Definition: libxslt.c:21
struct bucket_list * params
Bucket list of paramaters to apply to the document.
Definition: libxslt.c:25