Skip to content

Commit b22bbf9

Browse files
committed
Merge branch 'xslt' of https://github.com/mwieder/livecode into feature-revxml_xslt
2 parents 36fb99d + 5aea227 commit b22bbf9

8 files changed

Lines changed: 603 additions & 10 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ libxslt:
142142
revxml: libxml libxslt libexternal
143143
$(MAKE) -C ./revxml revxml
144144

145-
server-revxml: libxml libexternal
145+
server-revxml: libxml libxslt libexternal
146146
$(MAKE) -C ./revxml server-revxml
147147

148148
###############################################################################
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<doc>
2+
<legacy_id></legacy_id>
3+
<name>xsltApplyStylesheet</name>
4+
<type>function</type>
5+
6+
<syntax>
7+
<example>xsltApplyStylesheet xmlDocID, xsltStylesheetID</example>
8+
</syntax>
9+
10+
<synonyms>
11+
</synonyms>
12+
13+
<summary></summary>
14+
15+
<examples>
16+
<example>put xsltApplyStylesheet(tDocID, tStylesheetID) into tProcessedData</example>
17+
</examples>
18+
19+
<history>
20+
<introduced version="6.2">6.2</introduced>
21+
<deprecated version=""></deprecated>
22+
<removed version=""></removed>
23+
24+
<experimental version=""></experimental>
25+
<nonexperimental version=""></nonexperimental>
26+
</history>
27+
28+
<objects>
29+
</objects>
30+
31+
<platforms>
32+
<mac/>
33+
<windows/>
34+
<linux/>
35+
<ios/>
36+
<android/>
37+
<windows_mobile/>
38+
<linux_mobile/>
39+
</platforms>
40+
41+
<classes>
42+
<desktop/>
43+
<server/>
44+
<web/>
45+
<mobile/>
46+
</classes>
47+
48+
<security>
49+
</security>
50+
51+
52+
<classification>
53+
<category>XML</category>
54+
</classification>
55+
56+
<references>
57+
<function tag="revXMLEvaluateXpath">revXMLEvaluateXpath</function>
58+
<function tag="revCreateXMLTree">revXMLCreateTree</function>
59+
<function tag="revCreateXMLTreeFromFile">revXMLCreateTreeFromFile</function>
60+
<function tag="xsltApplyStylesheetFile">xsltApplyStylesheetFile</function>
61+
<function tag="xsltLoadStylesheet">xsltLoadStylesheet</function>
62+
<function tag="xsltLoadStylesheetFromFile">xsltLoadStylesheetFromFile</function>
63+
</references>
64+
65+
<description>The xsltApplyStylesheet function returns the data set resulting from applying the xslt document against the specified xml document. For instance, given xml data of<p></p><p>&lt;sales&gt;&#13;</p><p> &lt;division id="North"&gt;&#13;</p><p> &lt;revenue&gt;10&lt;/revenue&gt;&#13;</p><p> &lt;growth&gt;9&lt;/growth&gt;&#13;</p><p> &lt;bonus&gt;7&lt;/bonus&gt;&#13;</p><p> &lt;/division&gt;&#13;</p><p> &lt;division id="South"&gt;&#13;</p><p> &lt;revenue&gt;4&lt;/revenue&gt;&#13;</p><p> &lt;growth&gt;3&lt;/growth&gt;&#13;</p><p> &lt;bonus&gt;4&lt;/bonus&gt;&#13;</p><p> &lt;/division&gt;&#13;</p><p> &lt;division id="West"&gt;&#13;</p><p> &lt;revenue&gt;6&lt;/revenue&gt;&#13;</p><p> &lt;growth&gt;-1.5&lt;/growth&gt;&#13;</p><p> &lt;bonus&gt;2&lt;/bonus&gt;&#13;</p><p> &lt;/division&gt;&#13;</p><p>&lt;/sales&gt;</p><p></p><p>and an xslt document of</p><p></p><p>&lt;html xsl:version="1.0"&#13;</p><p> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&#13;</p><p> lang="en"&gt;&#13;</p><p> &lt;head&gt;&#13;</p><p> &lt;title&gt;Sales Results By Division&lt;/title&gt;&#13;</p><p> &lt;/head&gt;&#13;</p><p> &lt;body&gt;&#13;</p><p> &lt;table border="1"&gt;&#13;</p><p> &lt;tr&gt;&#13;</p><p> &lt;th&gt;Division&lt;/th&gt;&#13;</p><p> &lt;th&gt;Revenue&lt;/th&gt;&#13;</p><p> &lt;th&gt;Growth&lt;/th&gt;&#13;</p><p> &lt;th&gt;Bonus&lt;/th&gt;&#13;</p><p> &lt;/tr&gt;&#13;</p><p> &lt;xsl:for-each select="sales/division"&gt;&#13;</p><p> &lt;!-- order the result by revenue --&gt;&#13;</p><p> &lt;xsl:sort select="revenue"&#13;</p><p> data-type="number"&#13;</p><p> order="descending"/&gt;&#13;</p><p> &lt;tr&gt;&#13;</p><p> &lt;td&gt;&#13;</p><p> &lt;em&gt;&lt;xsl:value-of select="@id"/&gt;&lt;/em&gt;&#13;</p><p> &lt;/td&gt;&#13;</p><p> &lt;td&gt;&#13;</p><p> &lt;xsl:value-of select="revenue"/&gt;&#13;</p><p> &lt;/td&gt;&#13;</p><p> &lt;td&gt;&#13;</p><p> &lt;!-- highlight negative growth in red --&gt;&#13;</p><p> &lt;xsl:if test="growth &amp;lt; 0"&gt;&#13;</p><p> &lt;xsl:attribute name="style"&gt;&#13;</p><p> &lt;xsl:text&gt;color:red&lt;/xsl:text&gt;&#13;</p><p> &lt;/xsl:attribute&gt;&#13;</p><p> &lt;/xsl:if&gt;&#13;</p><p> &lt;xsl:value-of select="growth"/&gt;&#13;</p><p> &lt;/td&gt;&#13;</p><p> &lt;td&gt;&#13;</p><p> &lt;xsl:value-of select="bonus"/&gt;&#13;</p><p> &lt;/td&gt;&#13;</p><p> &lt;/tr&gt;&#13;</p><p> &lt;/xsl:for-each&gt;&#13;</p><p> &lt;/table&gt;&#13;</p><p> &lt;/body&gt;&#13;</p><p>&lt;/html&gt;</p><p></p><p>You would end up with</p><p></p><p>&lt;html lang="en"&gt;</p><p>&lt;head&gt;</p><p>&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;</p><p>&lt;title&gt;Sales Results By Division&lt;/title&gt;</p><p>&lt;/head&gt;</p><p>&lt;body&gt;&lt;table border="1"&gt;</p><p>&lt;tr&gt;</p><p>&lt;th&gt;Division&lt;/th&gt;</p><p>&lt;th&gt;Revenue&lt;/th&gt;</p><p>&lt;th&gt;Growth&lt;/th&gt;</p><p>&lt;th&gt;Bonus&lt;/th&gt;</p><p>&lt;/tr&gt;</p><p>&lt;tr&gt;</p><p>&lt;td&gt;&lt;em&gt;North&lt;/em&gt;&lt;/td&gt;</p><p>&lt;td&gt;10&lt;/td&gt;</p><p>&lt;td&gt;9&lt;/td&gt;</p><p>&lt;td&gt;7&lt;/td&gt;</p><p>&lt;/tr&gt;</p><p>&lt;tr&gt;</p><p>&lt;td&gt;&lt;em&gt;West&lt;/em&gt;&lt;/td&gt;</p><p>&lt;td&gt;6&lt;/td&gt;</p><p>&lt;td style="color:red"&gt;-1.5&lt;/td&gt;</p><p>&lt;td&gt;2&lt;/td&gt;</p><p>&lt;/tr&gt;</p><p>&lt;tr&gt;</p><p>&lt;td&gt;&lt;em&gt;South&lt;/em&gt;&lt;/td&gt;</p><p>&lt;td&gt;4&lt;/td&gt;</p><p>&lt;td&gt;3&lt;/td&gt;</p><p>&lt;td&gt;4&lt;/td&gt;</p><p>&lt;/tr&gt;</p><p>&lt;/table&gt;&lt;/body&gt;</p><p>&lt;/html&gt;</p></description>
66+
</doc>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<doc>
2+
<legacy_id></legacy_id>
3+
<name>xsltApplyStylesheetFromFile</name>
4+
<type>function</type>
5+
6+
<syntax>
7+
<example>xsltApplyStylesheetFromFile xmlDocID, pathToXSLTFile</example>
8+
</syntax>
9+
10+
<synonyms>
11+
</synonyms>
12+
13+
<summary></summary>
14+
15+
<examples>
16+
<example><p>put xsltApplyStylesheetFromFile(tDocID, "getData.xml") into tProcessedData</p><p>put xsltApplyStylesheetFromFile(tDocID, tFilePath) into tProcessedData</p></example>
17+
</examples>
18+
19+
<history>
20+
<introduced version="6.2">6.2</introduced>
21+
<deprecated version=""></deprecated>
22+
<removed version=""></removed>
23+
24+
<experimental version=""></experimental>
25+
<nonexperimental version=""></nonexperimental>
26+
</history>
27+
28+
<objects>
29+
</objects>
30+
31+
<platforms>
32+
<mac/>
33+
<windows/>
34+
<linux/>
35+
<ios/>
36+
<android/>
37+
<windows_mobile/>
38+
<linux_mobile/>
39+
</platforms>
40+
41+
<classes>
42+
<desktop/>
43+
<server/>
44+
<web/>
45+
<mobile/>
46+
</classes>
47+
48+
<security>
49+
</security>
50+
51+
52+
<classification>
53+
<category>XML</category>
54+
</classification>
55+
56+
<references>
57+
<function tag="revXMLEvaluateXpath">revXMLEvaluateXpath</function>
58+
<function tag="revCreateXMLTree">revXMLCreateTree</function>
59+
<function tag="revCreateXMLTreeFromFile">revXMLCreateTreeFromFile</function>
60+
<function tag="xsltApplyStylesheetFile">xsltApplyStylesheetFile</function>
61+
<function tag="xsltLoadStylesheet">xsltLoadStylesheet</function>
62+
<function tag="xsltLoadStylesheetFromFile">xsltLoadStylesheetFromFile</function>
63+
</references>
64+
65+
<description>The xsltApplyStylesheetFromFile function returns the data set resulting from applying the xslt document in the specified file against the specified xml document. For instance, given xml data of<p></p><p>&lt;sales&gt;</p><p> &lt;division id="North"&gt;</p><p> &lt;revenue&gt;10&lt;/revenue&gt;</p><p> &lt;growth&gt;9&lt;/growth&gt;</p><p> &lt;bonus&gt;7&lt;/bonus&gt;</p><p> &lt;/division&gt;</p><p> &lt;division id="South"&gt;</p><p> &lt;revenue&gt;4&lt;/revenue&gt;</p><p> &lt;growth&gt;3&lt;/growth&gt;</p><p> &lt;bonus&gt;4&lt;/bonus&gt;</p><p> &lt;/division&gt;</p><p> &lt;division id="West"&gt;</p><p> &lt;revenue&gt;6&lt;/revenue&gt;</p><p> &lt;growth&gt;-1.5&lt;/growth&gt;</p><p> &lt;bonus&gt;2&lt;/bonus&gt;</p><p> &lt;/division&gt;</p><p>&lt;/sales&gt;</p><p></p><p>and a file containing xslt data of</p><p></p><p>&lt;html xsl:version="1.0"</p><p> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"</p><p> lang="en"&gt;</p><p> &lt;head&gt;</p><p> &lt;title&gt;Sales Results By Division&lt;/title&gt;</p><p> &lt;/head&gt;</p><p> &lt;body&gt;</p><p> &lt;table border="1"&gt;</p><p> &lt;tr&gt;</p><p> &lt;th&gt;Division&lt;/th&gt;</p><p> &lt;th&gt;Revenue&lt;/th&gt;</p><p> &lt;th&gt;Growth&lt;/th&gt;</p><p> &lt;th&gt;Bonus&lt;/th&gt;</p><p> &lt;/tr&gt;</p><p> &lt;xsl:for-each select="sales/division"&gt;</p><p> &lt;!-- order the result by revenue --&gt;</p><p> &lt;xsl:sort select="revenue"</p><p> data-type="number"</p><p> order="descending"/&gt;</p><p> &lt;tr&gt;</p><p> &lt;td&gt;</p><p> &lt;em&gt;&lt;xsl:value-of select="@id"/&gt;&lt;/em&gt;</p><p> &lt;/td&gt;</p><p> &lt;td&gt;</p><p> &lt;xsl:value-of select="revenue"/&gt;</p><p> &lt;/td&gt;</p><p> &lt;td&gt;</p><p> &lt;!-- highlight negative growth in red --&gt;</p><p> &lt;xsl:if test="growth &lt; 0"&gt;</p><p> &lt;xsl:attribute name="style"&gt;</p><p> &lt;xsl:text&gt;color:red&lt;/xsl:text&gt;</p><p> &lt;/xsl:attribute&gt;</p><p> &lt;/xsl:if&gt;</p><p> &lt;xsl:value-of select="growth"/&gt;</p><p> &lt;/td&gt;</p><p> &lt;td&gt;</p><p> &lt;xsl:value-of select="bonus"/&gt;</p><p> &lt;/td&gt;</p><p> &lt;/tr&gt;</p><p> &lt;/xsl:for-each&gt;</p><p> &lt;/table&gt;</p><p> &lt;/body&gt;</p><p>&lt;/html&gt;</p><p></p><p>You would end up with</p><p></p><p>&lt;html lang="en"&gt;</p><p>&lt;head&gt;</p><p>&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;</p><p>&lt;title&gt;Sales Results By Division&lt;/title&gt;</p><p>&lt;/head&gt;</p><p>&lt;body&gt;&lt;table border="1"&gt;</p><p>&lt;tr&gt;</p><p>&lt;th&gt;Division&lt;/th&gt;</p><p>&lt;th&gt;Revenue&lt;/th&gt;</p><p>&lt;th&gt;Growth&lt;/th&gt;</p><p>&lt;th&gt;Bonus&lt;/th&gt;</p><p>&lt;/tr&gt;</p><p>&lt;tr&gt;</p><p>&lt;td&gt;&lt;em&gt;North&lt;/em&gt;&lt;/td&gt;</p><p>&lt;td&gt;10&lt;/td&gt;</p><p>&lt;td&gt;9&lt;/td&gt;</p><p>&lt;td&gt;7&lt;/td&gt;</p><p>&lt;/tr&gt;</p><p>&lt;tr&gt;</p><p>&lt;td&gt;&lt;em&gt;West&lt;/em&gt;&lt;/td&gt;</p><p>&lt;td&gt;6&lt;/td&gt;</p><p>&lt;td style="color:red"&gt;-1.5&lt;/td&gt;</p><p>&lt;td&gt;2&lt;/td&gt;</p><p>&lt;/tr&gt;</p><p>&lt;tr&gt;</p><p>&lt;td&gt;&lt;em&gt;South&lt;/em&gt;&lt;/td&gt;</p><p>&lt;td&gt;4&lt;/td&gt;</p><p>&lt;td&gt;3&lt;/td&gt;</p><p>&lt;td&gt;4&lt;/td&gt;</p><p>&lt;/tr&gt;</p><p>&lt;/table&gt;&lt;/body&gt;</p><p>&lt;/html&gt;</p></description>
66+
</doc>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<doc>
2+
<legacy_id></legacy_id>
3+
<name>xsltLoadStylesheet</name>
4+
<type>function</type>
5+
6+
<syntax>
7+
<example>xsltLoadStylesheet stylesheetXML</example>
8+
</syntax>
9+
10+
<synonyms>
11+
</synonyms>
12+
13+
<summary>The xsltLoadStylesheet function loads an xslt stylesheet into memory from xml data so that it can be applied to xml data using the xsltApplyStylesheet function. It returns an xslt stylesheet id.</summary>
14+
15+
<examples>
16+
<example><p>put xsltLoadStylesheet(field "fldXSLT") into tStylesheetID</p><p>put xsltApplyStylesheet(tXMLData, tStylesheetID) into tProcessedData</p><p>xsltFreeStylesheet tStylesheetID</p></example>
17+
</examples>
18+
19+
<history>
20+
<introduced version="6.2">6.2</introduced>
21+
<deprecated version=""></deprecated>
22+
<removed version=""></removed>
23+
24+
<experimental version=""></experimental>
25+
<nonexperimental version=""></nonexperimental>
26+
</history>
27+
28+
<objects>
29+
</objects>
30+
31+
<platforms>
32+
<mac/>
33+
<windows/>
34+
<linux/>
35+
<ios/>
36+
<android/>
37+
<windows_mobile/>
38+
<linux_mobile/>
39+
</platforms>
40+
41+
<classes>
42+
<desktop/>
43+
<server/>
44+
<web/>
45+
<mobile/>
46+
</classes>
47+
48+
<security>
49+
</security>
50+
51+
52+
<classification>
53+
<category>XML</category>
54+
</classification>
55+
56+
<references>
57+
<function tag="revXMLEvaluateXpath">revXMLEvaluateXpath</function>
58+
<function tag="revCreateXMLTree">revXMLCreateTree</function>
59+
<function tag="revCreateXMLTreeFromFile">revXMLCreateTreeFromFile</function>
60+
<function tag="xsltApplyStylesheet">xsltApplyStylesheet</function>
61+
<function tag="xsltApplyStylesheetFromFile">xsltApplyStylesheetFromFile</function>
62+
<function tag="xsltLoadStylesheetFromFile">xsltLoadStylesheetFromFile</function>
63+
<command tag=""></command>
64+
</references>
65+
66+
<description>The xsltLoadStylesheet function loads an xslt stylesheet into memory from xml data so that it can be applied to xml data using the xsltApplyStylesheet function. It returns an xslt stylesheet id.</description>
67+
</doc>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<doc>
2+
<legacy_id></legacy_id>
3+
<name>xsltLoadStylesheetFromFile</name>
4+
<type>function</type>
5+
6+
<syntax>
7+
<example>xsltLoadStylesheetFromFile pathToFile</example>
8+
</syntax>
9+
10+
<synonyms>
11+
</synonyms>
12+
13+
<summary>The xsltLoadStylesheetFromFile function loads an xslt stylesheet into memory from a file so that it can be applied to xml data using the xsltApplyStylesheet function. It returns an xslt stylesheet id.</summary>
14+
15+
<examples>
16+
<example><p>put xsltLoadStylesheetFromFile(tFilePath) into tStylesheetID</p><p>put xsltApplyStylesheet(tXMLData, tStylesheetID) into tProcessedData</p><p>xsltFreeStylesheet tStylesheetID</p></example>
17+
</examples>
18+
19+
<history>
20+
<introduced version="6.2">6.2</introduced>
21+
<deprecated version=""></deprecated>
22+
<removed version=""></removed>
23+
24+
<experimental version=""></experimental>
25+
<nonexperimental version=""></nonexperimental>
26+
</history>
27+
28+
<objects>
29+
</objects>
30+
31+
<platforms>
32+
<mac/>
33+
<windows/>
34+
<linux/>
35+
<ios/>
36+
<android/>
37+
<windows_mobile/>
38+
<linux_mobile/>
39+
</platforms>
40+
41+
<classes>
42+
<desktop/>
43+
<server/>
44+
<web/>
45+
<mobile/>
46+
</classes>
47+
48+
<security>
49+
</security>
50+
51+
52+
<classification>
53+
<category>XML</category>
54+
</classification>
55+
56+
<references>
57+
<function tag="revXMLEvaluateXpath">revXMLEvaluateXpath</function>
58+
<function tag="revCreateXMLTree">revXMLCreateTree</function>
59+
<function tag="revCreateXMLTreeFromFile">revXMLCreateTreeFromFile</function>
60+
<function tag="xsltApplyStylesheet">xsltApplyStylesheet</function>
61+
<function tag="xsltApplyStylesheetFromFile">xsltApplyStylesheetFromFile</function>
62+
<function tag="xsltLoadStylesheetFromFile">xsltLoadStylesheetFromFile</function>
63+
<command tag=""></command>
64+
</references>
65+
66+
<description>The xsltLoadStylesheetFromFile function loads an xslt stylesheet into memory from a file so that it can be applied to xml data using the xsltApplyStylesheet function. It returns an xslt stylesheet id.</description>
67+
</doc>

revxml/src/cxml.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
1919
#include <libxml/HTMLparser.h>
2020
// MDW-2013-07-09: [[ RevXmlXPath ]]
2121
#include <libxml/xpath.h>
22+
// MDW-2013-09-03: [[ RevXmlXslt ]]
23+
#include <xsltInternals.h>
24+
#include <xsltutils.h>
2225

2326
#include <errno.h>
2427
#include <stdio.h>
@@ -61,7 +64,10 @@ extern void CB_elementData(const char *data, int length);
6164
class CXMLDocument
6265
{
6366
public:
64-
CXMLDocument() {id = ++idcounter; doc = NULL;}
67+
CXMLDocument() {Init();}
68+
// MDW-2013-09-03: [[ RevXmlXslt ]] new constructors
69+
CXMLDocument(xmlXPathContextPtr id) {Init(); xpathContext = id;}
70+
CXMLDocument(xsltStylesheetPtr id) {Init(); xsltID = id;}
6571
~CXMLDocument() {Free();}
6672
inline Bool isinited() {return doc != NULL;}
6773
Bool Read(char *data, unsigned long tlength, Bool wellformed);
@@ -76,7 +82,8 @@ Bool GetRootElement(CXMLElement *telement);
7682
xmlDocPtr GetDocPtr() {return doc;}
7783
// MDW-2013-07-09: [[ RevXmlXPath ]]
7884
xmlXPathContextPtr GetXPathContext() {return xpathContext;}
79-
void SetXPathContext(xmlXPathContextPtr ctx) {xpathContext=ctx;}
85+
// MDW-2013-09-03: [[ RevXmlXslt ]]
86+
xsltStylesheetPtr GetXsltContext() {return xsltID;}
8087
Bool AddDTD(char *data, unsigned long tlength);
8188
Bool ValidateDTD(char *data, unsigned long tlength);
8289
char *GetError() {return errorbuf;}
@@ -98,8 +105,12 @@ static unsigned int idcounter;
98105
unsigned int id;
99106
static char errorbuf[256];
100107
xmlDocPtr doc;
108+
private:
109+
void Init() {id = ++idcounter; doc = NULL; xpathContext = NULL; xsltID = NULL;}
101110
// MDW-2013-07-09: [[ RevXmlXPath ]]
102111
xmlXPathContextPtr xpathContext;
112+
// MDW-2013-09-03: [[ RevXmlXslt ]]
113+
xsltStylesheetPtr xsltID;
103114
};
104115

105116
class CXMLElement

0 commit comments

Comments
 (0)