Example: lr_xml_transform
The following example transforms an XML string, xml_input, using the XSL specification, stylesheet, and saves the transformation into the parameter, Result.
Both xml_input and stylesheet are char strings and are converted to parameter format using lr_save_string. After lr_xml_transform is invoked, the output parameter which contains the formatted data, Result, is evaluated using lr_eval_string.
#include "as_web.h"
char *xml_input =
"<?xml version=\"1.0\" ?>"
"<sales>"
"<summary>"
"<heading>Acme Organization</heading>"
"<subhead>IT Management Report</subhead>"
"<description>Report by Department</description>"
"</summary>"
"</sales>";
char *stylesheet =
"<?xml version=\"1.0\"?>"
"<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">"
"<xsl:output method=\"html\"/>"
"<xsl:template match=\"/\">"
"<HTML>"
"<HEAD>"
"<TITLE><xsl:value-of select=\"//summary/heading\"/></TITLE>"
"</HEAD>"
"<BODY>"
"<h1><xsl:value-of select=\"//summary/heading\"/></h1>"
"<h2><xsl:value-of select=\"//summary/subhead\"/></h2>"
"<p><xsl:value-of select=\"//summary/description\"/></p>"
"</BODY>"
"</HTML>"
"</xsl:template>"
"</xsl:stylesheet>";
Action() {
lr_save_string(xml_input, "XML_Input_Param"); // Save to a parameter
lr_save_string(stylesheet, "XML_StyleSheet_Param");// Save to a parameter
lr_xml_transform("XML={XML_Input_Param}", "ResultParam=Result",
"Stylesheet={XML_StyleSheet_Param}", LAST );
lr_output_message(lr_eval_string("String after transformation: {Result}"));
return 0;
}
Example: Output:
Action.c(39): String after transformation: <HTML>
<HEAD>
<TITLE>Acme Organization</TITLE>
</HEAD>
<BODY>
<h1>Acme Organization</h1>
<h2>IT Management Report</h2>
<p>Report by Department.</p>
</BODY>
</HTML>