Skip to content

Commit a5c5d19

Browse files
committed
xsltApplyStylesheet
1 parent 4f12cd2 commit a5c5d19

8 files changed

Lines changed: 83 additions & 13 deletions

File tree

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,18 @@ server-revdb: libexternal
131131
###############################################################################
132132
# revXML Targets
133133

134-
.PHONY: libxml revxml server-revxml
134+
.PHONY: libxml libxslt revxml server-revxml
135135

136136
libxml:
137137
$(MAKE) -C ./thirdparty/libxml libxml
138138

139-
revxml: libxml libexternal
139+
libxslt:
140+
$(MAKE) -C ./thirdparty/libxslt libxslt
141+
142+
revxml: libxml libxslt libexternal
140143
$(MAKE) -C ./revxml revxml
141144

142-
server-revxml: libxml libexternal
145+
server-revxml: libxml libxslt libexternal
143146
$(MAKE) -C ./revxml server-revxml
144147

145148
###############################################################################

ide

Submodule ide updated from 935ffa0 to 7dc0b92

prebuilt

revxml/Makefile.revxml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ CUSTOM_DEFINES=
99

1010
CUSTOM_INCLUDES=./src
1111

12-
CUSTOM_LIBS=xml external z
12+
CUSTOM_LIBS=xml xslt external z
1313

1414
CUSTOM_CCFLAGS=
1515

1616
CUSTOM_LDFLAGS=
1717

18-
CUSTOM_DYNAMIC_LIBS=m
18+
CUSTOM_DYNAMIC_LIBS=m rt
1919

2020
include ../rules/library.linux.makefile

revxml/Makefile.server-revxml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ CUSTOM_DEFINES=
99

1010
CUSTOM_INCLUDES=./src ../libxml/include
1111

12-
CUSTOM_LIBS=external xml z
13-
CUSTOM_DYNAMIC_LIBS=m
12+
CUSTOM_LIBS=external xml xslt z
13+
CUSTOM_DYNAMIC_LIBS=m rt
1414

1515
CUSTOM_CCFLAGS=
1616

revxml/src/revxml.cpp

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
2323
#include <revolution/external.h>
2424
#include <revolution/support.h>
2525
#include <libxml/xpath.h>
26+
#include <transform.h>
27+
#include <xsltInternals.h>
28+
#include <xsltutils.h>
2629

2730
#include "cxml.h"
2831

@@ -2590,7 +2593,7 @@ void XML_EvalXPath(char *args[], int nargs, char **retstring, Bool *pass, Bool *
25902593
if (nargs > 2)
25912594
cDelimiter = args[2];
25922595
else
2593-
cDelimiter = "\n";
2596+
cDelimiter = (char *)"\n";
25942597
char *xpaths = XML_ObjectPtr_to_Xpaths(result, cDelimiter);
25952598
if (NULL != xpaths)
25962599
{
@@ -2652,11 +2655,11 @@ void XML_XPathDataFromQuery(char *args[], int nargs, char **retstring, Bool *pas
26522655
if (nargs > 2)
26532656
charDelimiter = args[2];
26542657
else
2655-
charDelimiter = "\n";
2658+
charDelimiter = (char *)"\n";
26562659
if (nargs > 3)
26572660
lineDelimiter = args[3];
26582661
else
2659-
lineDelimiter = "\n";
2662+
lineDelimiter = (char *)"\n";
26602663
char *xpaths = XML_ObjectPtr_to_Data(result, charDelimiter, lineDelimiter);
26612664
if (NULL != xpaths)
26622665
{
@@ -2681,6 +2684,66 @@ void XML_XPathDataFromQuery(char *args[], int nargs, char **retstring, Bool *pas
26812684
*retstring = istrdup(xmlerrors[XMLERR_BADDOCID]);
26822685
}
26832686

2687+
/**
2688+
* XML_xsltApplyStylesheet
2689+
* @pDocID : xml tree id (already parsed)
2690+
* @pStylesheet : stylesheet to apply against the xml document
2691+
* @pParamList : ]optional] delimiter between data elements (default="\n")
2692+
*
2693+
*
2694+
* put xsltApplyStylesheet(tDocID, tStylesheet, tParamList)
2695+
*/
2696+
void XML_xsltApplyStylesheet(char *args[], int nargs, char **retstring, Bool *pass, Bool *error)
2697+
{
2698+
*pass = False;
2699+
*error = False;
2700+
xmlDocPtr xmlDoc, res;
2701+
xsltStylesheetPtr cur = NULL;
2702+
int nbparams = 0;
2703+
const char *params[16 + 1];
2704+
char *result;
2705+
2706+
xmlChar *doc_txt_ptr;
2707+
int doc_txt_len;
2708+
2709+
// XML_NewDocumentFromFile(args, nargs, retstring, pass, error);
2710+
int docID = atoi(args[0]);
2711+
CXMLDocument *xmlDocument = doclist.find(docID);
2712+
if (NULL != xmlDocument)
2713+
{
2714+
xmlDocPtr xmlDoc = xmlDocument->GetDocPtr();
2715+
if (NULL != xmlDoc)
2716+
{
2717+
cur = xsltParseStylesheetFile((const xmlChar *)args[1]);
2718+
if (NULL != cur)
2719+
{
2720+
params[nbparams] = NULL;
2721+
res = xsltApplyStylesheet(cur, xmlDoc, params);
2722+
2723+
// xsltSaveResultToFile(stdout, res, cur);
2724+
xsltSaveResultToString(&doc_txt_ptr, &doc_txt_len, res, cur);
2725+
2726+
// result = (char *)malloc(INTSTRSIZE);
2727+
// sprintf(result,"%ld",res);
2728+
// *retstring = (result != NULL ? istrdup(result) : (char *)calloc(1,1));
2729+
*retstring = istrdup((char *)doc_txt_ptr);
2730+
// free(result);
2731+
2732+
xsltFreeStylesheet(cur);
2733+
xmlFreeDoc(res);
2734+
// xmlFreeDoc(doc);
2735+
2736+
xsltCleanupGlobals();
2737+
xmlCleanupParser();
2738+
}
2739+
else
2740+
*retstring = istrdup(xmlerrors[XMLERR_BADDOCID]);
2741+
}
2742+
}
2743+
else
2744+
*retstring = istrdup(xmlerrors[XMLERR_BADDOCID]);
2745+
}
2746+
26842747
EXTERNAL_BEGIN_DECLARATIONS("revXML")
26852748
EXTERNAL_DECLARE_FUNCTION("revXMLinit", XML_Init)
26862749
EXTERNAL_DECLARE_FUNCTION("revXML_version", REVXML_Version)
@@ -2747,6 +2810,9 @@ EXTERNAL_BEGIN_DECLARATIONS("revXML")
27472810
// MDW-2013-06-22: [[ RevXmlXPath ]]
27482811
EXTERNAL_DECLARE_FUNCTION("revXMLEvaluateXPath", XML_EvalXPath)
27492812
EXTERNAL_DECLARE_FUNCTION("revXMLDataFromXPathQuery", XML_XPathDataFromQuery)
2813+
2814+
// MDW-2013-06-22: [[ RevXmlXslt ]]
2815+
EXTERNAL_DECLARE_FUNCTION("xsltApplyStylesheet", XML_xsltApplyStylesheet)
27502816
EXTERNAL_END_DECLARATIONS
27512817

27522818

rules/common.linux.makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ GLOBAL_INCLUDES=\
2222
$(SOLUTION_DIR)/thirdparty/libpq/include \
2323
$(SOLUTION_DIR)/thirdparty/libsqlite/include \
2424
$(SOLUTION_DIR)/thirdparty/libxml/include \
25+
$(SOLUTION_DIR)/thirdparty/libxslt/include/libxslt \
2526
$(SOLUTION_DIR)/thirdparty/libz/include \
2627
$(SOLUTION_DIR)/thirdparty/libzip/include \
2728
$(SOLUTION_DIR)/thirdparty/libopenssl/include \

thirdparty

0 commit comments

Comments
 (0)