static Variant HHVM_METHOD(XSLTProcessor, transformToXML, const Object& doc) { auto data = Native::data<XSLTProcessorData>(this_); if (doc.instanceof(s_DOMDocument)) { auto domdoc = Native::data<DOMNode>(doc); data->m_doc = libxml_register_node(xmlCopyDoc ((xmlDocPtr)domdoc->nodep(), /*recursive*/ 1)); xmlDocPtr res = data->apply_stylesheet(); if (res == nullptr) { return false; } xmlChar *mem; int size; if (xsltSaveResultToString(&mem, &size, res, data->m_stylesheet) < 0) { if (mem) { xmlFree(mem); } return false; } String ret = String((char*)mem, size, CopyString); xmlFree(mem); return ret; } return false; }
static void HHVM_METHOD(XSLTProcessor, importStylesheet, const Object& stylesheet) { SYNC_VM_REGS_SCOPED(); auto data = Native::data<XSLTProcessorData>(this_); xmlDocPtr doc = nullptr; if (stylesheet.instanceof(s_DOMDocument)) { auto domdoc = Native::data<DOMNode>(stylesheet); // This doc will be freed by xsltFreeStylesheet. doc = xmlCopyDoc((xmlDocPtr)domdoc->nodep(), /*recursive*/ 1); if (doc == nullptr) { raise_error("Unable to import stylesheet"); } } else if (stylesheet.instanceof(c_SimpleXMLElement::classof())) { auto elem = cast<c_SimpleXMLElement>(stylesheet); // This doc will be freed by xsltFreeStylesheet. doc = xmlNewDoc((const xmlChar*)"1.0"); xmlNodePtr node = xmlCopyNode(elem->nodep(), /*extended*/ 1); if (doc == nullptr || node == nullptr) { raise_error("Unable to import stylesheet"); } xmlDocSetRootElement(doc, node); } else { raise_error("Object must be an instance of DOMDocument or " "SimpleXMLElement"); } if (doc) { data->m_stylesheet = xsltParseStylesheetDoc(doc); if (data->m_stylesheet == nullptr) { xmlFreeDoc(doc); raise_error("Unable to import stylesheet"); } } }
static Variant HHVM_METHOD(XSLTProcessor, transformToDoc, const Object& doc) { auto data = Native::data<XSLTProcessorData>(this_); if (doc.instanceof(s_DOMNode)) { auto domnode = Native::data<DOMNode>(doc); data->m_doc = libxml_register_node(xmlCopyDoc((xmlDocPtr)domnode->nodep(), /*recursive*/ 1)); auto ret = newDOMDocument(false /* construct */); DOMNode* doc_data = Native::data<DOMNode>(ret); doc_data->setNode((xmlNodePtr)data->apply_stylesheet()); return ret; } return false; }
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; }
virtual FileLine* fileline() const { return nodep()->fileline(); }
virtual string name() const { return nodep()->name(); }