Пример #1
0
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;
}
Пример #2
0
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);
}
Пример #3
0
/**
 * Write the transformed xml document out to a file.
 * @param   xml The xml document
 * @param   xsl The xml stylesheet
 * @param   params The transform parameters
 * @param   filename The source xml input descriptor
 * @return  @c TRUE if successful, @c FALSE if an error occurs.
 * @ingroup EXML_XSLT_Group
 */
int exml_transform_file_write( EXML *xml, EXML_XSL *xsl, const char *params[],
                               char *filename, int compression )
{
	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 = xsltSaveResultToFilename(filename, res, xsl->cur, compression);

	xmlFreeDoc(res);

	xsltCleanupGlobals();

	if( ret < 0 )
		return FALSE;

	return TRUE;
}
Пример #4
0
Variant c_XSLTProcessor::t_transformtouri(const Object& doc,
                                          const String& uri) {
  if (doc.instanceof(c_DOMDocument::classof())) {
    c_DOMDocument *domdoc = doc.getTyped<c_DOMDocument>();
    m_doc = xmlCopyDoc ((xmlDocPtr)domdoc->m_node, /*recursive*/ 1);

    String translated = xslt_get_valid_file_path(uri);
    if (translated.empty()) {
      raise_warning("Invalid URI");
      return false;
    }

    xmlDocPtr res = apply_stylesheet ();
    if (res == nullptr) {
      return false;
    }

    int bytes = xsltSaveResultToFilename(translated.data(),
                                         res,
                                         m_stylesheet,
                                         /*compression*/ 0);
    xmlFreeDoc(res);

    if (bytes == -1) {
      return false;
    }

    return bytes;
  }

  return false;
}
Пример #5
0
static Variant HHVM_METHOD(XSLTProcessor, transformToURI,
                           const Object& doc,
                           const String& uri) {
  auto data = Native::data<XSLTProcessorData>(this_);

  if (doc.instanceof(DOMDocument::getClass())) {
    DOMDocument *domdoc = Native::data<DOMDocument>(doc.get());
    data->m_doc = xmlCopyDoc ((xmlDocPtr)domdoc->m_node, /*recursive*/ 1);

    String translated = libxml_get_valid_file_path(uri);
    if (translated.empty()) {
      raise_warning("Invalid URI");
      return false;
    }

    xmlDocPtr res = data->apply_stylesheet ();
    if (res == nullptr) {
      return false;
    }

    int bytes = xsltSaveResultToFilename(translated.data(),
                                         res,
                                         data->m_stylesheet,
                                         /*compression*/ 0);
    xmlFreeDoc(res);

    if (bytes == -1) {
      return false;
    }

    return bytes;
  }

  return false;
}
Пример #6
0
gint
xml_tree_model_save_xsl (xmlTreeModel *model, gchar *filename)
{
	g_return_val_if_fail (XML_IS_TREE_MODEL(model), -1);
	g_return_val_if_fail (model->xmldoc != NULL, -1);
	
	return xsltSaveResultToFilename(filename, model->xmldoc, model->xsldoc, 0);
	
}
Пример #7
0
/**********************************************************************
print_xml_filename_to_filename_using_stylesheet

Print the contents of an XML file to another file applying an 
XSLT stylesheet.

Returns TRUE if successful, FALSE otherwise.
**********************************************************************/
BOOLEAN_T print_xml_filename_to_filename_using_stylesheet(
    char* input_file_path,        /* path to XML input file IN */
    char* stylesheet_file_path,   /* path to MEME XSL stylesheet IN */
    char* output_file_path        /* path to HTML output file IN */
) {

  xsltStylesheetPtr stylesheet = NULL;
  xmlDocPtr input_doc = NULL;
  xmlDocPtr output_doc = NULL;
  const int PERFORM_ENTITY_SUBST = 1;

  xmlSubstituteEntitiesDefault(PERFORM_ENTITY_SUBST);
  xmlLoadExtDtdDefaultValue = 0;
  exsltRegisterAll();

  stylesheet = xsltParseStylesheetFile((const xmlChar *) stylesheet_file_path);
  if (!stylesheet) {
    fprintf(stderr, "Unable to parse stylesheet %s.\n", stylesheet_file_path);
    return FALSE;
  }
  input_doc = xmlParseFile(input_file_path);
  if (!input_doc) {
    fprintf(stderr, "Unable to parse input file %s.\n", input_file_path);
    return FALSE;
  }
  output_doc = xsltApplyStylesheet(stylesheet, input_doc, NULL);
  if (!output_doc) {
    fprintf(
      stderr, 
      "Unable to apply stylsheet %s to input from file %s.\n", 
      stylesheet_file_path,
      input_file_path
    );
    return FALSE;
  }
  int result = xsltSaveResultToFilename(output_file_path, output_doc, stylesheet, 0);
  if (result == -1) {
    fprintf(
      stderr, 
      "Unable to save result of applying stylesheet %s to %s.\n", 
      stylesheet_file_path, 
      output_file_path
    );
  }

  xsltFreeStylesheet(stylesheet);
  xmlFreeDoc(output_doc);
  xmlFreeDoc(input_doc);
  xsltCleanupGlobals();
  xmlCleanupParser();

  return TRUE;

} /* print_xml_file_html */
Пример #8
0
void transform(fs::path xslt, std::string inputfile, std::string outputfile)
{
    auto stylesheet = xsltParseStylesheetFile(BAD_CAST xslt.c_str());
    auto doc = xmlParseFile(inputfile.c_str());

    const char *params = NULL;
    auto result = xsltApplyStylesheet(stylesheet, doc, &params);
    xsltSaveResultToFilename(outputfile.c_str(), result, stylesheet, 0);

    xmlFreeDoc(doc);
    xmlFreeDoc(result);
    xsltFreeStylesheet(stylesheet);
}
Пример #9
0
void
XSLT::save(Inkscape::Extension::Output */*module*/, SPDocument *doc, gchar const *filename)
{
    /* TODO: Should we assume filename to be in utf8 or to be a raw filename?
     * See JavaFXOutput::save for discussion. */
    g_return_if_fail(doc != NULL);
    g_return_if_fail(filename != NULL);

    Inkscape::XML::Node *repr = doc->getReprRoot();

    std::string tempfilename_out;
    int tempfd_out = 0;
    try {
        tempfd_out = Inkscape::IO::file_open_tmp(tempfilename_out, "ink_ext_XXXXXX");
    } catch (...) {
        /// \todo Popup dialog here
        return;
    }

    if (!sp_repr_save_rebased_file(repr->document(), tempfilename_out.c_str(), SP_SVG_NS_URI,
                                   doc->getBase(), filename)) {
        throw Inkscape::Extension::Output::save_failed();
    }

    xmlDocPtr svgdoc = xmlParseFile(tempfilename_out.c_str());
    close(tempfd_out);
    if (svgdoc == NULL) {
        return;
    }

    const char * params[1];
    params[0] = NULL;

    xmlDocPtr newdoc = xsltApplyStylesheet(_stylesheet, svgdoc, params);
    //xmlSaveFile(filename, newdoc);
    int success = xsltSaveResultToFilename(filename, newdoc, _stylesheet, 0);

    xmlFreeDoc(newdoc);
    xmlFreeDoc(svgdoc);

    xsltCleanupGlobals();
    xmlCleanupParser();

    if (success < 1) {
        throw Inkscape::Extension::Output::save_failed();
    }

    return;
}
Пример #10
0
int main(int argc, char* argv[]) {

  char* usage = "xsltpro_lite <xslt filename> <xml input filename> <output filename>\n";

  if (argc != 4) {
    fprintf(stderr, "%s", usage);
    exit(0);
  }

  char* stylesheet_file_path = argv[1]; // Path to XSLT stylesheet
  char* input_file_path = argv[2];      // Path to XML input file IN
  char* output_file_path = argv[3];      // Path to XML input file IN

  xsltStylesheetPtr stylesheet = NULL;
  xmlDocPtr input_doc = NULL;
  xmlDocPtr output_doc = NULL;
  const int PERFORM_ENTITY_SUBST = 1;
  xmlSubstituteEntitiesDefault(PERFORM_ENTITY_SUBST);
  xmlLoadExtDtdDefaultValue = 0;
  exsltRegisterAll();
  stylesheet = xsltParseStylesheetFile((xmlChar *) stylesheet_file_path);
  if (! stylesheet) {
    fprintf(stderr, "Couldn't parse stylesheet file %s\n", stylesheet_file_path);
    exit(1);
  }
  input_doc = xmlParseFile(input_file_path);
  if (! stylesheet) {
    fprintf(stderr, "Couldn't parse input file %s\n", input_file_path);
    exit(1);
  }
  output_doc = xsltApplyStylesheet(stylesheet, input_doc, NULL);
  if (! output_doc) {
    fprintf(stderr, "Couldn't apply stylesheet %s to input file %s\n",
      stylesheet_file_path, input_file_path);
    exit(1);
  }
  xsltSaveResultToFilename(output_file_path, output_doc, stylesheet, 0);
  xmlFreeDoc(output_doc);
  xmlFreeDoc(input_doc);
  xsltFreeStylesheet(stylesheet);

  exit(0);

}; 
Пример #11
0
static Variant HHVM_METHOD(XSLTProcessor, transformToURI,
                           const Object& doc,
                           const String& uri) {
  auto data = Native::data<XSLTProcessorData>(this_);

  if (!FileUtil::checkPathAndWarn(uri, "XSLTProcessor::transformToUri", 2)) {
    return false;
  }

  if (doc.instanceof(s_DOMDocument)) {
    auto domdoc = Native::data<DOMNode>(doc);
    data->m_doc =
      libxml_register_node(xmlCopyDoc ((xmlDocPtr)domdoc->nodep(),
                                       /*recursive*/ 1));

    String translated = libxml_get_valid_file_path(uri);
    if (translated.empty()) {
      raise_warning("Invalid URI");
      return false;
    }

    xmlDocPtr res = data->apply_stylesheet ();
    if (res == nullptr) {
      return false;
    }

    int bytes = xsltSaveResultToFilename(translated.data(),
                                         res,
                                         data->m_stylesheet,
                                         /*compression*/ 0);
    xmlFreeDoc(res);

    if (bytes == -1) {
      return false;
    }

    return bytes;
  }

  return false;
}
Пример #12
0
/**********************************************************************
print_meme_file_html

Print MEME results in HTML format.
Format XML as HTML using a stylesheet and an XSLT
**********************************************************************/
extern void print_meme_file_html(
    char* stylesheet_file_path,   /* path to MEME XSL stylesheet IN */
    char* input_file_path,        /* path to XML input file IN */
    char* output_file_path        /* path to HTML output file IN */
) {
  xsltStylesheetPtr stylesheet = NULL;
  xmlDocPtr input_doc = NULL;
  xmlDocPtr output_doc = NULL;
  const int PERFORM_ENTITY_SUBST = 1;
  xmlSubstituteEntitiesDefault(PERFORM_ENTITY_SUBST);
  xmlLoadExtDtdDefaultValue = 0;
  exsltRegisterAll();
  stylesheet = xsltParseStylesheetFile((const xmlChar *) stylesheet_file_path);
  input_doc = xmlParseFile(input_file_path);
  output_doc = xsltApplyStylesheet(stylesheet, input_doc, NULL);
  xsltSaveResultToFilename(output_file_path, output_doc, stylesheet, 0);
  xmlFreeDoc(output_doc);
  xmlFreeDoc(input_doc);
  xsltFreeStylesheet(stylesheet);

} /* print_meme_file_html */
Пример #13
0
int xmi_xmso_to_xmsi_xslt(char *xmsofile, char *xmsifile , char *outputfile  ) {

	xsltStylesheetPtr cur = NULL;
	xmlDocPtr doc, res;
	xmlParserCtxtPtr ctx;
	const char *params[1] = {NULL};
	xmlXPathContextPtr xpathCtx; 
	xmlXPathObjectPtr xpathObj;

#ifdef G_OS_WIN32
	xmlChar *xsltfile;

	if (xmi_registry_win_query(XMI_REGISTRY_WIN_XMSO2XMSI,(char **) &xsltfile) == 0)
		return 0;
#elif defined(MAC_INTEGRATION)
	xmlChar *xsltfile;

	if (xmi_resources_mac_query(XMI_RESOURCES_MAC_XMSO2XMSI,(char **) &xsltfile) == 0)
		return 0;
#else
	const xmlChar xsltfile[] = XMI_XMSO2XMSI_XSLT;
#endif

	xsltInit();

	cur = xsltParseStylesheetFile(xsltfile);
	if (cur == NULL)
		return 0;
#if defined(G_OS_WIN32) || defined (MAC_INTEGRATION)
	free(xsltfile);
#endif

	if ((ctx=xmlNewParserCtxt()) == NULL) {
		fprintf(stderr,"xmlNewParserCtxt error\n");
		return 0;
	}

	if ((doc = xmlCtxtReadFile(ctx,xmsofile,NULL,XML_PARSE_DTDVALID | XML_PARSE_NOBLANKS | XML_PARSE_DTDATTR)) == NULL) {
		fprintf(stderr,"xmlCtxtReadFile error for %s\n",xmsofile);
		xmlFreeParserCtxt(ctx);
		return 0;
	}	

	if (ctx->valid == 0) {
		fprintf(stderr,"Error validating %s\n",xmsofile);
		xmlFreeDoc(doc);
		return 0;
	}
	xmlFreeParserCtxt(ctx);

	res = xsltApplyStylesheet(cur, doc, params);
	if (res == NULL)
		return 0;

	if (outputfile != NULL) {
    		xpathCtx = xmlXPathNewContext(res);
        	if(xpathCtx == NULL) {
	        	fprintf(stderr,"Error: unable to create new XPath context\n");
		        return 0;
		}
		xpathObj = xmlXPathEvalExpression((const xmlChar *) "/xmimsim/general/outputfile", xpathCtx);
		    if(xpathObj == NULL) {
		        fprintf(stderr,"Error: unable to evaluate xpath expression \"%s\"\n","xmimsim/general/outputfile" );
			xmlXPathFreeContext(xpathCtx); 
			return 0;
		}
		update_xpath_nodes(xpathObj->nodesetval, (const xmlChar *) outputfile);
		xmlXPathFreeObject(xpathObj);
	        xmlXPathFreeContext(xpathCtx);
	}


	xsltSaveResultToFilename(xmsifile, res, cur, 0);

	xsltFreeStylesheet(cur);
	xmlFreeDoc(res);
	xmlFreeDoc(doc);

        xsltCleanupGlobals();

	return 1;

}
Пример #14
0
int xmi_xmso_to_htm_xslt(char *xmsofile, char *xmsifile, unsigned convoluted) {

	xsltStylesheetPtr cur = NULL;
	xmlDocPtr doc, res;
	xmlParserCtxtPtr ctx;
	const char *params[3];
	char catalog[] = XMI_CATALOG;
	xmlXPathContextPtr xpathCtx; 
	xmlXPathObjectPtr xpathObj;

	char parm_name[] = "type1";
        char s_convoluted[] = "'convoluted'";
        char s_unconvoluted[] = "'unconvoluted'";

#ifdef G_OS_WIN32
	xmlChar *xsltfile;

	if (xmi_registry_win_query(XMI_REGISTRY_WIN_XMSO2HTM,(char **) &xsltfile) == 0)
		return 0;
#elif defined(MAC_INTEGRATION)
	xmlChar *xsltfile;

	if (xmi_resources_mac_query(XMI_RESOURCES_MAC_XMSO2HTM,(char **) &xsltfile) == 0)
		return 0;
#else
	const xmlChar xsltfile[] = XMI_XMSO2HTM_XSLT;
#endif



	xsltInit();

	params[0] = parm_name;
        if ( convoluted )
         params[1] = s_convoluted;
        else
         params[1] = s_unconvoluted;
        params[2] = NULL;

       	//fprintf(stdout, "parm 0 = %s \n", params[0] ); 
	//fprintf(stdout, "parm 1 = %s \n", params[1] );
	//fprintf(stdout, "parm 2 = %s \n", params[2] );  

	cur = xsltParseStylesheetFile(xsltfile);
	if (cur == NULL)
		return 0;

#if defined(G_OS_WIN32) || defined (MAC_INTEGRATION)
	free(xsltfile);
#endif


	if ((ctx=xmlNewParserCtxt()) == NULL) {
		fprintf(stderr,"xmlNewParserCtxt error\n");
		return 0;
	}

	if ((doc = xmlCtxtReadFile(ctx,xmsofile,NULL,XML_PARSE_DTDVALID | XML_PARSE_NOBLANKS | XML_PARSE_DTDATTR)) == NULL) {
		fprintf(stderr,"xmlCtxtReadFile error for %s\n",xmsofile);
		xmlFreeParserCtxt(ctx);
		return 0;
	}	

	if (ctx->valid == 0) {
		fprintf(stderr,"Error validating %s\n",xmsofile);
		xmlFreeDoc(doc);
		return 0;
	}
	xmlFreeParserCtxt(ctx);

	res = xsltApplyStylesheet(cur, doc, params);
	if (res == NULL)
		return 0;

	xsltSaveResultToFilename(xmsifile, res, cur, 0);

	xsltFreeStylesheet(cur);
	xmlFreeDoc(res);
	xmlFreeDoc(doc);

        xsltCleanupGlobals();

	return 1;

}
Пример #15
0
/**
 * Saves the result to filename
 */
void CXSLTransform::Save(CString filename)
{
	if (m_Result)
		xsltSaveResultToFilename(filename, m_Result, m_Style, 0);
}