2 <xsl:stylesheet version=
"1.0" xmlns:
xsl=
"http://www.w3.org/1999/XSL/Transform">
3 <xsl:output method=
"text"/>
5 <xsl:template match=
"/">
7 #include
<libxml/parser.h
>
8 #include
<libxml/tree.h
>
9 #include
<libxml/xpath.h
>
10 #include
<libxml/xpathInternals.h
>
13 <xsl:call-template name=
"serializer"/>
14 <xsl:apply-templates select=
"tests/test"/>
17 int main(int argc, char **argv) {

</xsl:text>
18 <xsl:apply-templates select=
"tests/test" mode=
"call"/>
20 /* printf(
"finished.\n"); */
26 <xsl:template match=
"tests/test" mode=
"call">
27 <xsl:text> nsTest_
</xsl:text>
28 <xsl:value-of select=
"@name"/>
29 <xsl:text>();

</xsl:text>
32 <xsl:template name=
"xml-text">
33 <xsl:param name=
"text"/>
34 <xsl:call-template name=
"replace-string">
35 <!-- Substitute #10 for " -->
36 <xsl:with-param name=
"from" select=
"' '"/>
37 <xsl:with-param name=
"to" select=
"'" "'"/>
38 <xsl:with-param name=
"text">
39 <xsl:call-template name=
"replace-string">
40 <!-- Substitute " for \" -->
41 <xsl:with-param name=
"from" select=
"'"'"/>
42 <xsl:with-param name=
"to" select=
"'\"'"/>
43 <xsl:with-param name=
"text">
44 <xsl:call-template name=
"replace-string">
46 <xsl:with-param name=
"from" select=
"'	'"/>
47 <xsl:with-param name=
"to" select=
"''"/>
48 <xsl:with-param name=
"text" select=
"$text"/>
57 <xsl:template match=
"doc" mode=
"define">
58 <xsl:text> xmlDocPtr
</xsl:text>
59 <xsl:value-of select=
"@name"/>
60 <xsl:text>;

</xsl:text>
61 <xsl:text> const char *
</xsl:text>
62 <xsl:value-of select=
"@name"/>
63 <xsl:text>_str =
"</xsl:text>
64 <xsl:call-template name="xml-text
">
65 <xsl:with-param name="text
" select=".
"/>
67 <xsl:text>";

</xsl:text>
70 <xsl:template match=
"expected" mode=
"define">
71 <xsl:text> const char *
</xsl:text>
72 <xsl:text>exp_str =
"</xsl:text>
73 <xsl:call-template name="xml-text
">
74 <xsl:with-param name="text
" select=".
"/>
76 <xsl:text>";

</xsl:text>
79 <xsl:template match=
"doc">
80 <xsl:text> </xsl:text>
81 <xsl:value-of select=
"@name"/>
82 <xsl:text> = xmlReadDoc(BAD_CAST
</xsl:text>
83 <xsl:value-of select=
"@name"/>
84 <xsl:text>_str, NULL, NULL,
0);

</xsl:text>
86 <xsl:apply-templates select=
"following-sibling::*[1]"/>
88 <xsl:text> xmlFreeDoc(
</xsl:text>
89 <xsl:value-of select=
"@name"/>
90 <xsl:text>);

</xsl:text>
93 <xsl:template match=
"xpath">
96 <xsl:template match=
"var" mode=
"define">
97 <xsl:text> xmlNodePtr
</xsl:text>
98 <xsl:value-of select=
"@name"/>
99 <xsl:text>;

</xsl:text>
102 <xsl:template match=
"var">
103 <xsl:if test=
"xpath">
104 <!-- Create XPath context. -->
105 <xsl:text> /* Selecting node
"</xsl:text><xsl:value-of select="@name
"/><xsl:text>". */

</xsl:text>
106 <xsl:text> xp = xmlXPathNewContext(
</xsl:text>
107 <xsl:value-of select=
"xpath/@doc"/>
108 <xsl:text>);

</xsl:text>
109 <!-- Register namespaces. -->
110 <xsl:for-each select=
"xpath/reg-ns">
111 <xsl:text> xmlXPathRegisterNs(xp, BAD_CAST
"</xsl:text>
112 <xsl:value-of select="@prefix
"/>
113 <xsl:text>", BAD_CAST
"</xsl:text>
114 <xsl:value-of select="@ns
"/>
115 <xsl:text>");

</xsl:text>
118 <xsl:text> </xsl:text>
119 <xsl:value-of select=
"@name"/>
120 <xsl:text> = nsSelectNode(xp,
"</xsl:text>
121 <xsl:value-of select="xpath/@select-node
"/>
122 <xsl:text>");

</xsl:text>
123 <xsl:text> xmlXPathFreeContext(xp);

</xsl:text>
125 <xsl:apply-templates select=
"following-sibling::*[1]"/>
128 <xsl:template match=
"reconcile-ns">
129 <xsl:text> /* Reconcile node
"</xsl:text><xsl:value-of select="@ref
"/><xsl:text>". */

</xsl:text>
130 <xsl:text> xmlDOMWrapReconcileNamespaces(NULL,
</xsl:text>
131 <xsl:value-of select=
"@node"/>
132 <xsl:text>,
0);

</xsl:text>
133 <xsl:apply-templates select=
"following-sibling::*[1]"/>
136 <xsl:template match=
"remove">
137 <xsl:text> xmlDOMWrapRemoveNode(NULL,
</xsl:text>
138 <xsl:value-of select=
"@node"/>
139 <xsl:text>-
>doc,
</xsl:text>
140 <xsl:value-of select=
"@node"/>
141 <xsl:text>,
0);

</xsl:text>
142 <xsl:apply-templates select=
"following-sibling::*[1]"/>
145 <xsl:template match=
"adopt">
146 <xsl:text> /* Adopt
"</xsl:text><xsl:value-of select="@node
"/><xsl:text>". */

</xsl:text>
147 <xsl:text> xmlDOMWrapAdoptNode(NULL,
</xsl:text>
148 <xsl:value-of select=
"@node"/>
149 <xsl:text>-
>doc,
</xsl:text>
150 <xsl:value-of select=
"@node"/>
151 <xsl:text>,
</xsl:text>
152 <xsl:value-of select=
"@dest-doc"/>
153 <xsl:text>,
</xsl:text>
155 <xsl:when test=
"@dest-parent">
156 <xsl:value-of select=
"@dest-parent"/>
159 <xsl:text>NULL
</xsl:text>
162 <xsl:text>,
0);

</xsl:text>
163 <xsl:apply-templates select=
"following-sibling::*[1]"/>
166 <xsl:template match=
"append-child">
167 <xsl:text> xmlAddChild(
</xsl:text>
168 <xsl:value-of select=
"@parent"/>
169 <xsl:text>,
</xsl:text>
170 <xsl:value-of select=
"@child"/>
171 <xsl:text>);

</xsl:text>
172 <xsl:apply-templates select=
"following-sibling::*[1]"/>
175 <xsl:template match=
"expected">
176 <xsl:text> /* Serialize
"</xsl:text><xsl:value-of select="@doc
"/><xsl:text>". */

</xsl:text>
177 <xsl:text> result_str = nsSerializeNode(xmlDocGetRootElement(
</xsl:text>
178 <xsl:value-of select=
"@doc"/>
179 <xsl:text>));

</xsl:text>
180 <xsl:text> /* Compare result. */
181 if (! xmlStrEqual(BAD_CAST result_str, BAD_CAST exp_str)) {
183 printf(
"%s\n", (const char *) result_str);
185 printf(
"Expected:\n%s\n", exp_str);
188 xmlFree(result_str);

</xsl:text>
194 <xsl:template match=
"test">
195 <xsl:text>void nsTest_
</xsl:text>
196 <xsl:value-of select=
"@name"/>
198 xmlChar * result_str;
199 xmlXPathContextPtr xp;
200 int memory;

</xsl:text>
201 <xsl:apply-templates select=
"*" mode=
"define"/>
203 memory = xmlMemUsed();
204 xmlInitParser();


</xsl:text>
205 <xsl:apply-templates select=
"child::*[1]"/>
208 memory = xmlMemUsed() - memory;
211 printf(
"## '%s' MEMORY leak: %d\n",
"</xsl:text>
212 <xsl:value-of select="@name
"/>
213 <xsl:text>", memory);
219 <xsl:template name=
"serializer">
222 xmlChar * nsSerializeNode(xmlNodePtr node) {
225 xmlOutputBufferPtr buf;
226 buf = xmlAllocOutputBuffer(NULL);
227 xmlNodeDumpOutput(buf, node-
>doc, node,
0,
0, NULL);
228 xmlOutputBufferFlush(buf);
229 ret = (xmlChar *) buf-
>buffer-
>content;
230 buf-
>buffer-
>content = NULL;
231 (void) xmlOutputBufferClose(buf);
235 xmlNodePtr nsSelectNode(xmlXPathContextPtr xp, const char * xpath) {
236 xmlXPathObjectPtr xpres;
239 xpres = xmlXPathEval(BAD_CAST xpath, xp);
240 ret = xpres-
>nodesetval-
>nodeTab[
0];
241 xmlXPathFreeObject(xpres);
248 <xsl:template name=
"replace-string">
249 <xsl:param name=
"text"/>
250 <xsl:param name=
"from"/>
251 <xsl:param name=
"to"/>
254 <xsl:when test=
"contains($text, $from)">
256 <xsl:variable name=
"before" select=
"substring-before($text, $from)"/>
257 <xsl:variable name=
"after" select=
"substring-after($text, $from)"/>
258 <xsl:variable name=
"prefix" select=
"concat($before, $to)"/>
260 <xsl:value-of select=
"$before"/>
261 <xsl:value-of select=
"$to"/>
262 <xsl:call-template name=
"replace-string">
263 <xsl:with-param name=
"text" select=
"$after"/>
264 <xsl:with-param name=
"from" select=
"$from"/>
265 <xsl:with-param name=
"to" select=
"$to"/>
269 <xsl:value-of select=
"$text"/>