本文整理汇总了C++中xsltApplyStylesheet函数的典型用法代码示例。如果您正苦于以下问题:C++ xsltApplyStylesheet函数的具体用法?C++ xsltApplyStylesheet怎么用?C++ xsltApplyStylesheet使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xsltApplyStylesheet函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: xsltApplyStylesheet
bool XSLTUtils::XSLTTransform(std::string& output)
{
const char *params[16+1];
params[0] = NULL;
m_xmlOutput = xsltApplyStylesheet(m_xsltStylesheet, m_xmlInput, params);
if (!m_xmlOutput)
{
CLog::Log(LOGDEBUG, "XSLT: xslt transformation failed");
return false;
}
xmlChar *xmlResultBuffer = NULL;
int xmlResultLength = 0;
int res = xsltSaveResultToString(&xmlResultBuffer, &xmlResultLength, m_xmlOutput, m_xsltStylesheet);
if (res == -1)
{
xmlFree(xmlResultBuffer);
return false;
}
output.append((const char *)xmlResultBuffer, xmlResultLength);
xmlFree(xmlResultBuffer);
return true;
}
示例2: transform
/*
* call-seq:
* transform(document, params = [])
*
* Apply an XSLT stylesheet to an XML::Document.
* +params+ is an array of strings used as XSLT parameters.
* returns Nokogiri::XML::Document
*
* Example:
*
* doc = Nokogiri::XML(File.read(ARGV[0]))
* xslt = Nokogiri::XSLT(File.read(ARGV[1]))
* puts xslt.transform(doc, ['key', 'value'])
*
*/
static VALUE transform(int argc, VALUE* argv, VALUE self)
{
VALUE xmldoc, paramobj ;
xmlDocPtr xml ;
xmlDocPtr result ;
xsltStylesheetPtr ss ;
const char** params ;
int param_len, j ;
rb_scan_args(argc, argv, "11", &xmldoc, ¶mobj);
if (paramobj == Qnil) { paramobj = rb_ary_new2(0) ; }
Data_Get_Struct(xmldoc, xmlDoc, xml);
Data_Get_Struct(self, xsltStylesheet, ss);
param_len = NUM2INT(rb_funcall(paramobj, rb_intern("length"), 0));
params = calloc((size_t)param_len+1, sizeof(char*));
for (j = 0 ; j < param_len ; j++) {
VALUE entry = rb_ary_entry(paramobj, j);
const char * ptr = StringValuePtr(entry);
params[j] = ptr;
}
params[param_len] = 0 ;
result = xsltApplyStylesheet(ss, xml, params);
free(params);
return Nokogiri_wrap_xml_document(0, result) ;
}
示例3: transform
/*
* call-seq:
* transform(document, params = [])
*
* Apply an XSLT stylesheet to an XML::Document.
* +params+ is an array of strings used as XSLT parameters.
* returns Nokogiri::XML::Document
*
* Example:
*
* doc = Nokogiri::XML(File.read(ARGV[0]))
* xslt = Nokogiri::XSLT(File.read(ARGV[1]))
* puts xslt.transform(doc, ['key', 'value'])
*
*/
static VALUE transform(int argc, VALUE* argv, VALUE self)
{
VALUE xmldoc, paramobj ;
xmlDocPtr xml ;
xmlDocPtr result ;
xsltStylesheetPtr ss ;
const char** params ;
int param_len, j ;
rb_scan_args(argc, argv, "11", &xmldoc, ¶mobj);
if (NIL_P(paramobj)) { paramobj = rb_ary_new2(0) ; }
Data_Get_Struct(xmldoc, xmlDoc, xml);
Data_Get_Struct(self, xsltStylesheet, ss);
param_len = RARRAY_LEN(paramobj);
params = calloc((size_t)param_len+1, sizeof(char*));
for (j = 0 ; j < param_len ; j++) {
VALUE entry = rb_ary_entry(paramobj, j);
const char * ptr = StringValuePtr(entry);
params[j] = ptr;
}
params[param_len] = 0 ;
result = xsltApplyStylesheet(ss, xml, params);
free(params);
if (!result) rb_raise(rb_eRuntimeError, "could not perform xslt transform on document");
return Nokogiri_wrap_xml_document(0, result) ;
}
示例4: quote_nbsp
QString XSL::process(const QString &my_xml)
{
QString my_xsl;
/* Petr Cimprich, Sablot developer:
is predefined in HTML but not in XML
... use Unicode numerical entity instead:  */
my_xsl = quote_nbsp(my_xml);
xmlDocPtr doc = xmlParseMemory(my_xsl.toUtf8(), my_xsl.toUtf8().length());
if (doc == NULL){
string s;
s = static_cast<string>(my_xsl.toLocal8Bit());
log(L_WARN, "Parse XML error: %s", s.c_str());
return QString::null;
}
const char *params[1];
params[0] = NULL;
xmlDocPtr res = xsltApplyStylesheet(d->styleSheet, doc, params);
if (res == NULL){
log(L_WARN, "Apply stylesheet errror");
xmlFreeDoc(doc);
return QString::null;
}
xmlFreeDoc(doc);
xmlOutputBufferPtr buf = xmlAllocOutputBuffer(NULL);
xsltSaveResultTo(buf, res, d->styleSheet);
xmlFreeDoc(res);
QString result = QString::fromUtf8((char*)(buf->buffer->content));
xmlOutputBufferClose(buf);;
return result;
}
示例5: main
int main( int argc, char *argv[] )
{
if( argc != 3 ) {
std::cerr << "usage: testlibxslt1 <XSLT file> <XML file>" << std::endl;
return 1;
}
LIBXML_TEST_VERSION
xsltStylesheetPtr script = xsltParseStylesheetFile( ( const xmlChar *)argv[1] );
xmlDocPtr doc = xmlParseFile( argv[2] );
const char *params[1] = { NULL };
xmlDocPtr res = xsltApplyStylesheet( script, doc, params );
xmlChar *resTxt;
int resLen;
xsltSaveResultToString( &resTxt, &resLen, res, script );
std::cout << resTxt;
xmlFreeDoc( res );
xmlFreeDoc( doc );
xsltFreeStylesheet( script );
xsltCleanupGlobals( );
xmlCleanupParser( );
return 0;
}
示例6: xsltParseStylesheetFile
Xsltproc::ReturnValue Xsltproc::execute()
{
Xsltproc::ReturnValue retval = Xsltproc::Success;
try
{
if( freopen(mErrorFilename.toUtf8().data(),"w",stderr) == NULL ) throw Xsltproc::GenericFailure;
mStylesheet = xsltParseStylesheetFile( (const xmlChar*)mStyleSheetFilename.toUtf8().data() );
if(mStylesheet == 0) throw Xsltproc::InvalidStylesheet;
mXml = xmlParseFile( (const char*)mXmlFilename.toUtf8().data() );
if(mXml == 0) throw Xsltproc::InvalidXmlFile;
mOutput = xsltApplyStylesheet(mStylesheet, mXml, (const char**)mParams);
if(mOutput == 0) throw Xsltproc::GenericFailure;
FILE *foutput = 0;
foutput = fopen(mOutputFilename.toUtf8().data(),"w");
if( foutput == 0 ) throw Xsltproc::CouldNotOpenOutput;
xsltSaveResultToFile(foutput, mOutput, mStylesheet);
fclose(foutput);
}
catch(Xsltproc::ReturnValue e)
{
retval = e;
}
fclose(stderr);
freeResources();
return retval;
}
示例7: xsltSetLoaderFunc
DocumentImpl* XSLTProcessorImpl::transformDocument(DocumentImpl* doc)
{
// FIXME: Right now we assume |doc| is unparsed, but if it has been parsed we will need to serialize it
// and then feed that resulting source to libxslt.
m_resultOutput = "";
if (!m_stylesheet || !m_stylesheet->document()) return 0;
globalSheet = m_stylesheet;
xsltSetLoaderFunc(stylesheetLoadFunc);
xsltStylesheetPtr sheet = m_stylesheet->compileStyleSheet();
globalSheet = 0;
xsltSetLoaderFunc(0);
if (!sheet) return 0;
m_stylesheet->clearDocuments();
// Get the parsed source document.
xmlDocPtr sourceDoc = (xmlDocPtr)doc->transformSource();
xmlDocPtr resultDoc = xsltApplyStylesheet(sheet, sourceDoc, NULL);
DocumentImpl* result = documentFromXMLDocPtr(resultDoc, sheet);
xsltFreeStylesheet(sheet);
return result;
}
示例8: main
int main(int argc, char **argv) {
xsltStylesheetPtr stylesheet = NULL;
xmlDocPtr doc, res;
char* stylesheetfile;
char* infile;
char *outfile;
if (argc!=4) {
printf("XSLT Transform\n2009 by thom using libxml2\nUsage:\n\txslt-transform <stylesheet> <infile> <outfile>\n");
exit(1);
}
stylesheetfile = argv[1];
infile = argv[2];
outfile = argv[3];
xmlSubstituteEntitiesDefault(1);
xmlLoadExtDtdDefaultValue = 1;
stylesheet = xsltParseStylesheetFile(BAD_CAST stylesheetfile);
doc = xmlParseFile(infile);
res = xsltApplyStylesheet(stylesheet, doc, 0);
printf("use \"%s\" to transform \"%s\" to \"%s\" ...\n", stylesheetfile, infile, outfile);
xsltSaveResultToFilename(outfile, res, stylesheet, 0);
xsltFreeStylesheet(stylesheet);
xmlFreeDoc(res);
xmlFreeDoc(doc);
xsltCleanupGlobals();
xmlCleanupParser();
printf("\tDone.\n");
exit(0);
}
示例9: parse
std::string parse(const std::string& xml, const std::string& name, const std::string& url, const std::string& html, const std::string& htmlheader, std::vector<std::pair<std::string, std::string> >& attaches) {
std::string ret("");
std::string pp = getParserPath(url);
xsltStylesheetPtr xslt = xsltParseStylesheetFile(BAD_CAST pp.c_str());
htmlDocPtr doc = NULL;
static std::string encoding("gb18030");
std::string mimetype = getMIMEType(htmlheader, html);
if (!mimetype.empty() && mimetype == "text/xml") {
doc = html.empty() ? NULL : xmlReadDoc(BAD_CAST html.c_str(), NULL, encoding.c_str(), XML_PARSE_RECOVER);
} else {
doc = html.empty() ? NULL : htmlParseDoc(BAD_CAST html.c_str(), encoding.c_str());
}
if (doc != NULL) {
const char *params[7] = {0};
size_t n_param = 0;
params[n_param] = NULL;
xmlDocPtr res = xsltApplyStylesheet(xslt, doc, params);
//free_xslt_params(params, n_param);
if (res != NULL) {
xmlChar *s = NULL;
int len = 0;
if (xsltSaveResultToString(&s, &len, res, xslt) >= 0) {
ret.assign((const char *)s, len);
xmlFree(s);
}
xmlFreeDoc(res);
}
xmlFreeDoc(doc);
}
return ret;
}
示例10: xsltTransformToFile
ReturnCode xsltTransformToFile(xmlDocPtr doc, const char *xslFilename, const char *outputFilename) {
xmlDocPtr res;
xsltStylesheetPtr style;
if( (xslFilename == NULL) || (outputFilename == NULL) ) {
printMsg(MESSAGETYPE_ERROR, "xsltTransformToFile: Null pointer error");
return FAILED;
}
style = xsltParseStylesheetFile ((const xmlChar *) xslFilename);
if (style == NULL) {
printMsg(MESSAGETYPE_ERROR, "xsltTransformToFile: Could not parse XSLT file: %s", xslFilename);
return FAILED;
}
res = xsltApplyStylesheet(style, doc, NULL);
if(res == NULL){
printMsg(MESSAGETYPE_ERROR, "xsltTransformToFile: Problem applying stylesheet");
return FAILED;
}
xsltSaveResultToFilename(outputFilename, res, style, 0);
xmlFreeDoc(res);
xsltFreeStylesheet(style);
return SUCCESS;
}
示例11: xmlReadMemory
string XMLFunctions::xslt(string &data, string &style, ServerInterface &srvInterface) {
xmlDocPtr doc; /* the resulting document tree */
xmlDocPtr styeSheet; /* the resulting document tree */
xsltStylesheetPtr ssPtr;
const char *params[1];
int nbparams = 0;
params[nbparams] = NULL;
doc = xmlReadMemory(data.c_str(), data.size(), "noname.xml", NULL, 0);
// xmlNode *root_element = NULL;
// root_element = xmlDocGetRootElement(doc);
// print_element_names(root_element);
styeSheet = xmlReadMemory(style.c_str(), style.length(), "noname.xml", NULL, 0);
ssPtr = xsltParseStylesheetDoc (styeSheet);
xmlDocPtr result = xsltApplyStylesheet(ssPtr, doc, params);
xmlChar * resultString;
int stringLen;
xsltSaveResultToString(&resultString, &stringLen, result, ssPtr);
return string((char*) resultString);
}
示例12: exml_transform_fd_write
/**
* Write the transformed xml document out to a file descriptor.
* @param xml The xml document
* @param xsl The xml stylesheet
* @param params The transform parameters
* @param fd The source xml input descriptor
* @return @c TRUE if successful, @c FALSE if an error occurs.
* @ingroup EXML_XSLT_Group
*/
int exml_transform_fd_write( EXML *xml, EXML_XSL *xsl, const char *params[],
int fd )
{
int ret;
xmlDocPtr res, doc;
CHECK_PARAM_POINTER_RETURN("xml", xml, FALSE);
CHECK_PARAM_POINTER_RETURN("xsl", xsl, FALSE);
exml_doc_write(xml, &doc);
res = xsltApplyStylesheet(xsl->cur, doc, params);
xmlFreeDoc(doc);
if( !res ) {
return FALSE;
}
ret = xsltSaveResultToFd(fd, res, xsl->cur);
xmlFreeDoc(res);
xsltCleanupGlobals();
if( ret < 0 )
return FALSE;
return TRUE;
}
示例13: xmlDocGetRootElement
static xmlDoc *test_xslt_transforms(xmlDoc *doc, GError **error)
{
struct xslt_files *info = xslt_files;
xmlDoc *transformed;
xsltStylesheetPtr xslt = NULL;
xmlNode *root_element = xmlDocGetRootElement(doc);
char *attribute;
while ((info->root) && (strcasecmp(root_element->name, info->root) != 0)) {
info++;
}
if (info->root) {
attribute = xmlGetProp(xmlFirstElementChild(root_element), "name");
if (attribute) {
if (strcasecmp(attribute, "subsurface") == 0) {
free((void *)attribute);
return doc;
}
free((void *)attribute);
}
xmlSubstituteEntitiesDefault(1);
xslt = get_stylesheet(info->file);
if (xslt == NULL) {
parser_error(error, _("Can't open stylesheet (%s)/%s"), xslt_path, info->file);
return doc;
}
transformed = xsltApplyStylesheet(xslt, doc, NULL);
xmlFreeDoc(doc);
xsltFreeStylesheet(xslt);
return transformed;
}
return doc;
}
示例14: xsltFileName
void Docbook2XhtmlGeneratorJob::run()
{
UMLDoc* umlDoc = UMLApp::app()->document();
xsltStylesheetPtr cur = NULL;
xmlDocPtr doc, res;
const char *params[16 + 1];
int nbparams = 0;
params[nbparams] = NULL;
umlDoc->writeToStatusBar(i18n("Exporting to XHTML..."));
QString xsltFileName(KGlobal::dirs()->findResource("appdata", QLatin1String("docbook2xhtml.xsl")));
uDebug() << "XSLT file is'" << xsltFileName << "'";
QFile xsltFile(xsltFileName);
xsltFile.open(QIODevice::ReadOnly);
QString xslt = QString::fromLatin1(xsltFile.readAll());
uDebug() << "XSLT is'" << xslt << "'";
xsltFile.close();
QString localXsl = KGlobal::dirs()->findResource("data", QLatin1String("ksgmltools2/docbook/xsl/html/docbook.xsl"));
uDebug() << "Local xsl is'" << localXsl << "'";
if (!localXsl.isEmpty())
{
localXsl = QLatin1String("href=\"file://") + localXsl + QLatin1String("\"");
xslt.replace(QRegExp(QLatin1String("href=\"http://[^\"]*\"")), localXsl);
}
KTemporaryFile tmpXsl;
tmpXsl.setAutoRemove(false);
tmpXsl.open();
QTextStream str (&tmpXsl);
str << xslt;
str.flush();
xmlSubstituteEntitiesDefault(1);
xmlLoadExtDtdDefaultValue = 1;
uDebug() << "Parsing stylesheet " << tmpXsl.fileName();
cur = xsltParseStylesheetFile((const xmlChar *)tmpXsl.fileName().toLatin1().constData());
uDebug() << "Parsing file " << m_docbookUrl.path();
doc = xmlParseFile((const char*)(m_docbookUrl.path().toUtf8()));
uDebug() << "Applying stylesheet ";
res = xsltApplyStylesheet(cur, doc, params);
KTemporaryFile tmpXhtml;
tmpXhtml.setAutoRemove(false);
tmpXhtml.open();
uDebug() << "Writing HTML result to temp file: " << tmpXhtml.fileName();
xsltSaveResultToFd(tmpXhtml.handle(), res, cur);
xsltFreeStylesheet(cur);
xmlFreeDoc(res);
xmlFreeDoc(doc);
xsltCleanupGlobals();
xmlCleanupParser();
emit xhtmlGenerated(tmpXhtml.fileName());
}
示例15: Transform
void Transform(const TxmlDocHolder& srcDoc, TBuffer& dest, const TXslParams& params) {
//xmlXIncludeProcessFlags(srcDoc.Get(), XSLT_PARSE_OPTIONS);
if (!srcDoc)
ythrow yexception() << "source xml is not valid: " << ErrorMessage;
TxmlDocHolder res(xsltApplyStylesheet(Stylesheet.Get(), srcDoc.Get(), ~TParamsArray(params).Array)); // no params
ENSURE(!!res, "Failed to apply xslt!");
SaveResult(res.Get(), Stylesheet.Get(), dest);
}