1
0
mirror of https://gitlab.gnome.org/GNOME/libxslt synced 2025-07-31 02:43:06 +03:00

applied a patch from Ralf Mattes providing style.saveResultToString()

* python/libxslt-python-api.xml python/libxslt.c
  python/libxsltclass.txt python/tests/basic.py: applied a patch
  from Ralf Mattes providing style.saveResultToString()
Daniel
This commit is contained in:
Daniel Veillard
2002-08-25 15:04:00 +00:00
parent c1d306b3c3
commit f015c8f98c
6 changed files with 67 additions and 6 deletions

View File

@ -1,3 +1,9 @@
Sun Aug 25 17:01:40 CEST 2002 Daniel Veillard <daniel@veillard.com>
* python/libxslt-python-api.xml python/libxslt.c
python/libxsltclass.txt python/tests/basic.py: applied a patch
from Ralf Mattes providing style.saveResultToString()
Fri Aug 23 13:53:50 CEST 2002 Daniel Veillard <daniel@veillard.com> Fri Aug 23 13:53:50 CEST 2002 Daniel Veillard <daniel@veillard.com>
* configure.in: preparing release 1.0.20 * configure.in: preparing release 1.0.20

View File

@ -1,14 +1,14 @@
<MACRO> <MACRO>
<NAME>LIBXSLT_DOTTED_VERSION</NAME> <NAME>LIBXSLT_DOTTED_VERSION</NAME>
#define LIBXSLT_DOTTED_VERSION "1.0.19" #define LIBXSLT_DOTTED_VERSION "1.0.20"
</MACRO> </MACRO>
<MACRO> <MACRO>
<NAME>LIBXSLT_VERSION</NAME> <NAME>LIBXSLT_VERSION</NAME>
#define LIBXSLT_VERSION 10019 #define LIBXSLT_VERSION 10020
</MACRO> </MACRO>
<MACRO> <MACRO>
<NAME>LIBXSLT_VERSION_STRING</NAME> <NAME>LIBXSLT_VERSION_STRING</NAME>
#define LIBXSLT_VERSION_STRING "10019" #define LIBXSLT_VERSION_STRING "10020"
</MACRO> </MACRO>
<MACRO> <MACRO>
<NAME>WITH_XSLT_DEBUG</NAME> <NAME>WITH_XSLT_DEBUG</NAME>
@ -1580,15 +1580,15 @@ void
</FUNCTION> </FUNCTION>
<MACRO> <MACRO>
<NAME>LIBXSLT_DOTTED_VERSION</NAME> <NAME>LIBXSLT_DOTTED_VERSION</NAME>
#define LIBXSLT_DOTTED_VERSION "1.0.19" #define LIBXSLT_DOTTED_VERSION "1.0.20"
</MACRO> </MACRO>
<MACRO> <MACRO>
<NAME>LIBXSLT_VERSION</NAME> <NAME>LIBXSLT_VERSION</NAME>
#define LIBXSLT_VERSION 10019 #define LIBXSLT_VERSION 10020
</MACRO> </MACRO>
<MACRO> <MACRO>
<NAME>LIBXSLT_VERSION_STRING</NAME> <NAME>LIBXSLT_VERSION_STRING</NAME>
#define LIBXSLT_VERSION_STRING "10019" #define LIBXSLT_VERSION_STRING "10020"
</MACRO> </MACRO>
<MACRO> <MACRO>
<NAME>WITH_XSLT_DEBUG</NAME> <NAME>WITH_XSLT_DEBUG</NAME>

View File

@ -5,6 +5,12 @@
</file> </file>
</files> </files>
<symbols> <symbols>
<function name='xsltSaveResultToString' file='python'>
<info>Have the stylesheet serialize the result of a transformation to a python string</info>
<return type='char *' info='The result document as a string' />
<arg name='style' type='xsltStylesheetPtr' info='a parsed XSLT stylesheet'/>
<arg name='result' type='xmlDocPtr' info='The result document'/>
</function>
<function name='xsltApplyStylesheet' file='python'> <function name='xsltApplyStylesheet' file='python'>
<info>Apply the stylesheet to the document</info> <info>Apply the stylesheet to the document</info>
<return type='xmlDocPtr' info="the result document or NULL in case of error"/> <return type='xmlDocPtr' info="the result document or NULL in case of error"/>

View File

@ -251,6 +251,49 @@ libxslt_xsltApplyStylesheet(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
return(py_retval); return(py_retval);
} }
PyObject *
libxslt_xsltSaveResultToString(PyObject *self, PyObject *args) {
PyObject *py_retval; /* our final return value, a python string */
xmlChar *buffer;
xmlChar *tmp;
int size = 0;
int emitted = 0;
xmlDocPtr result;
PyObject *pyobj_result;
xsltStylesheetPtr style;
PyObject *pyobj_style;
if (!PyArg_ParseTuple(args, (char *)"OO:xsltSaveResultToString", &pyobj_style, &pyobj_result))
goto FAIL;
result = (xmlDocPtr) PyxmlNode_Get(pyobj_result);
style = (xsltStylesheetPtr) Pystylesheet_Get(pyobj_style);
/* FIXME: We should probably add more restrictive error checking
* and raise an error instead of "just" returning NULL.
* FIXME: Documentation and code for xsltSaveResultToString diff
* -> emmitted will never be positive non-null.
*/
emitted = xsltSaveResultToString(&buffer, &size, result, style);
if(!buffer || emitted < 0)
goto FAIL;
/* We haven't tested the aberrant case of a transformation that
* renders to an empty string. For now we try to play it save.
*/
if(size)
{
buffer[size] = '\0';
py_retval = PyString_FromString((char *) buffer);
xmlFree(buffer);
}
else
py_retval = PyString_FromString("");
return(py_retval);
FAIL:
return(0);
}
/************************************************************************ /************************************************************************
* * * *
* Error message callback * * Error message callback *

View File

@ -184,6 +184,7 @@ Class stylesheet()
# functions from module python # functions from module python
applyStylesheet() applyStylesheet()
saveResultToString()
# functions from module transform # functions from module transform
newTransformContext() newTransformContext()

View File

@ -1,4 +1,5 @@
#!/usr/bin/python -u #!/usr/bin/python -u
import sys
import libxml2 import libxml2
import libxslt import libxslt
@ -11,6 +12,10 @@ style = libxslt.parseStylesheetDoc(styledoc)
doc = libxml2.parseFile("test.xml") doc = libxml2.parseFile("test.xml")
result = style.applyStylesheet(doc, None) result = style.applyStylesheet(doc, None)
style.saveResultToFilename("foo", result, 0) style.saveResultToFilename("foo", result, 0)
stringval = style.saveResultToString(result)
if (len(stringval) != 68):
print "Error in saveResultToString"
sys.exit(255)
style.freeStylesheet() style.freeStylesheet()
doc.freeDoc() doc.freeDoc()
result.freeDoc() result.freeDoc()