本文整理汇总了PHP中XsltProcessor::transformToDoc方法的典型用法代码示例。如果您正苦于以下问题:PHP XsltProcessor::transformToDoc方法的具体用法?PHP XsltProcessor::transformToDoc怎么用?PHP XsltProcessor::transformToDoc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XsltProcessor
的用法示例。
在下文中一共展示了XsltProcessor::transformToDoc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: transform
/**
* Simple XSLT transformation function
*
* @param mixed $xml DOMDocument or string containing xml
* @param string $strXsltPath Relative file path to xslt document. Will look in both library location and
* local app location for documents, and combine them so local overrides library
* templates, if neccesary.
* @param array $arrParams [optional] array of parameters to pass to stylesheet
* @param bool $bolDoc [optional] return result as DOMDocument (default false)
* @param array $arrInclude [optional] additional stylesheets that should be included in the transform
* @return mixed newly formatted document as string or DOMDocument
* @static
*/
public static function transform($xml, $strXsltPath, $arrParams = null, $bolDoc = false, $arrInclude = array())
{
if ($strXsltPath == "") {
throw new Exception("no stylesheet supplied");
}
if (is_string($xml)) {
// load xml document from string
$objXml = new DOMDocument();
$objXml->loadXML($xml);
$xml = $objXml;
}
$objXsl = self::generateBaseXsl($strXsltPath, $arrInclude);
// create XSLT Processor
$objProcessor = new XsltProcessor();
$objProcessor->registerPhpFunctions();
if ($arrParams != null) {
// add in parameters
foreach ($arrParams as $key => $value) {
$objProcessor->setParameter(null, $key, $value);
}
}
// transform
$objXsl = $objProcessor->importStylesheet($objXsl);
if ($bolDoc == true) {
return $objProcessor->transformToDoc($xml);
} else {
return $objProcessor->transformToXml($xml);
}
}
示例2: transform
/**
* Simple, dynamic xsl transform
*/
protected function transform($xml, $path_to_xsl, $output_type = null, array $params = array(), array $import_array = array(), $to_string = true)
{
if ($path_to_xsl == "") {
throw new \Exception("no stylesheet supplied");
}
// make sure we have a domdocument
if (is_string($xml)) {
$xml = Parser::convertToDOMDocument($xml);
}
// create xslt processor
$processor = new \XsltProcessor();
$processor->registerPhpFunctions();
// add parameters
foreach ($params as $key => $value) {
$processor->setParameter(null, $key, $value);
}
// add stylesheet
$xsl = $this->generateBaseXsl($path_to_xsl, $import_array, $output_type);
$processor->importStylesheet($xsl);
// transform
if ($to_string == true) {
return $processor->transformToXml($xml);
} else {
return $processor->transformToDoc($xml);
}
}
示例3: execute
/**
* Execute render process
* @param string $templatePath
* @param \DOMDocument $source
* @param array $parameters
* @return string
*/
public function execute($templatePath, \DOMDocument $source, array $parameters = array())
{
$xsl = new \DomDocument();
$xsl->load($templatePath);
$processor = new \XsltProcessor();
$processor->importStylesheet($xsl);
$outputDom = $processor->transformToDoc($source);
if ($parameters['output.type'] && $parameters['output.type'] == 'xml') {
$result = $outputDom->saveXML();
} else {
$result = $outputDom->saveHTML();
}
return $result;
}
示例4: xsltTransform
private function xsltTransform($xmlStr, $xslFile, $toDom = false)
{
$doc = new DOMDocument();
$doc->substituteEntities = TRUE;
// $doc->resolveExternals = TRUE;
$doc->load($xslFile);
$proc = new XsltProcessor();
$proc->importStylesheet($doc);
$doc->loadXML($xmlStr);
if ($toDom) {
return $proc->transformToDoc($doc);
} else {
return $proc->transformToXml($doc);
}
}
示例5: resList
/**
* Return a formatted html list of resources associated with a given
* tag.
*
* The caller should check the $tr->status variable to see if the
* query was successful. On anything but a 200 or 304, this method
* returns nothing, but it would generally be useful to have a
* warning for 204 (no resources yet for this tag) or 404 (tag not
* found).
*
* @return string html for a list of resources referenced by the
* given tag.
*
*
*/
public function resList()
{
if (strlen($this->xml) == 0) {
$this->getData();
// args ?
}
if ($this->is_valid()) {
$xsl = new DOMDocument();
$xsl->load($this->loc->xsl_dir . "public_resourcelist.xsl");
$proc = new XsltProcessor();
$xsl = $proc->importStylesheet($xsl);
// possibly cached DOM
$taglist = $proc->transformToDoc($this->xml_DOM());
$this->html = $taglist->saveXML();
return $this->html;
}
}
示例6: outputXML
function outputXML($projectList)
{
$dom = new DOMDocument('1.0');
$dom->formatOutput = true;
//header("Content-Type: text/plain");
$root = $dom->createElement('SVNDump');
$dom->appendChild($root);
foreach ($projectList as &$project) {
$this->addProjectNode($dom, $root, $project);
}
$xsl = new DOMDocument('1.0');
$xsl->load("cs242_portfolio.xsl");
$proc = new XsltProcessor();
$xsl = $proc->importStylesheet($xsl);
$newdom = $proc->transformToDoc($dom);
echo $newdom->saveHTML();
//echo $dom->saveXML();
}
示例7: transform
public function transform($xsl_file = null, $xml_data = null)
{
CI()->benchmark->mark('xsl_transform (' . $xsl_file . ')_start');
set_error_handler(array('XSL_Transform', 'handleError'));
$xsl = new DOMDocument('1.0', 'UTF-8');
$xsl->load($this->_getXSL($xsl_file));
$inputdom = new DomDocument('1.0', 'UTF-8');
$inputdom->loadXML($this->_getXML($xml_data));
$proc = new XsltProcessor();
$proc->importStylesheet($xsl);
$proc->registerPhpFunctions($this->_allowedFunctions());
// $result = $proc->transformToXML($inputdom);
$proc->setParameter('', 'ISAJAX', CI()->is_ajax);
$result_doc = $proc->transformToDoc($inputdom);
$result = $result_doc->saveXML();
restore_error_handler();
// Strip out any <?xml stuff at top out output
$result = preg_replace('/\\<\\?xml.+\\?\\>/', '', $result, 1);
CI()->benchmark->mark('xsl_transform (' . $xsl_file . ')_end');
return $result;
}
示例8: buildCloud
/**
* Retreives and formats a tag cloud for the current page. The html
* remains available in $this->html. If html data is already
* present, simply returns that.
*
* @param $url string (Optional) The url (or id) for which a cloud should be
* made. Default is to use the current page.
* @param $max_tags integer (Optional). Defaults to 0, meaning get all
* the tags.
*
* @returns string The html cloud that is built.
*/
public function buildCloud($url = '', $max_tags = 0, $cloudtype = '')
{
if ($this->html) {
return $this->html;
}
if (!$this->xml) {
$this->getData($url ? $url : $this->url, $max_tags, $cloudtype);
}
if ($this->is_valid()) {
$xsl = new DOMDocument();
$xsl->load($this->loc->xsl_dir . "publiccloud.xsl");
$proc = new XsltProcessor();
$xsl = $proc->importStylesheet($xsl);
// setting url format so that it is not hard coded in the xsl.
$proc->setParameter('', 'tagviewbase', $this->loc->server_web_path . 'tagview.php?tag=');
//using cloud->xml_DOM() because this data might have been cached already.
$cloud = $proc->transformToDoc($this->xml_DOM());
$this->html = $cloud->saveXML();
}
return $this->html;
}
示例9: compile
private function compile($templateName, $block = '')
{
$paths = $this->getPaths($templateName, $block);
$templatePath = $paths[0];
$stylePath = $paths[1];
if (!empty($templatePath) and !empty($stylePath)) {
if (!$this->isCompiled($templateName)) {
$xsl = new DomDocument();
$xsl->load($stylePath);
$inputdom = new DomDocument();
$inputdom->load($templatePath);
$proc = new XsltProcessor();
$xsl = $proc->importStylesheet($xsl);
/* transform and output the xml document */
$newdom = $proc->transformToDoc($inputdom);
$data = $newdom->saveHTML();
$data = str_replace('phpvar:', '<?php echo $', $data);
$data = str_replace(':phpvar', '; ?>', $data);
file_put_contents(__ALIEN_TEMPLATESDIR . "/compiled/{$templateName}.php", $data);
return __ALIEN_TEMPLATESDIR . "/compiled/{$templateName}.php";
}
}
}
示例10: DomDocument
<?php
$xsl = new DomDocument();
$xsl->load("style.xslt");
$inputdom = new DomDocument();
$inputdom->load("doc.xml");
$proc = new XsltProcessor();
$xsl = $proc->importStylesheet($xsl);
/* transform and output the xml document */
$newdom = $proc->transformToDoc($inputdom);
echo $newdom->saveXML();
示例11: getXPath
public function getXPath($entry, $XSLTfilename = NULL, $fetch_associated_counts = NULL)
{
$entry_xml = new XMLElement('entry');
$data = $entry->getData();
$fields = array();
$entry_xml->setAttribute('id', $entry->get('id'));
//Add date created and edited values
$date = new XMLElement('system-date');
$date->appendChild(General::createXMLDateObject(DateTimeObj::get('U', $entry->get('creation_date')), 'created'));
$date->appendChild(General::createXMLDateObject(DateTimeObj::get('U', $entry->get('modification_date')), 'modified'));
$entry_xml->appendChild($date);
//Reflect Workspace and Siteroot params
$workspace = new XMLElement('workspace', URL . '/workspace');
$root = new XMLElement('root', URL);
// Add associated entry counts
if ($fetch_associated_counts == 'yes') {
$associated = $entry->fetchAllAssociatedEntryCounts();
if (is_array($associated) and !empty($associated)) {
foreach ($associated as $section_id => $count) {
$section = SectionManager::fetch($section_id);
if ($section instanceof Section === false) {
continue;
}
$entry_xml->setAttribute($section->get('handle'), (string) $count);
}
}
}
// Add fields:
foreach ($data as $field_id => $values) {
if (empty($field_id)) {
continue;
}
$field = FieldManager::fetch($field_id);
$field->appendFormattedElement($entry_xml, $values, false, null, $entry->get('id'));
}
$xml = new XMLElement('data');
$xml->appendChild($entry_xml);
$xml->appendChild($workspace);
$xml->appendChild($root);
// Build some context
$section = SectionManager::fetch($entry->get('section_id'));
$params = new XMLElement('params');
$params->appendChild(new XMLElement('section-handle', $section->get('handle')));
$params->appendChild(new XMLElement('entry-id', $entry->get('id')));
$xml->prependChild($params);
$dom = new DOMDocument();
$dom->strictErrorChecking = false;
$dom->loadXML($xml->generate(true));
if (!empty($XSLTfilename)) {
$XSLTfilename = UTILITIES . '/' . preg_replace(array('%/+%', '%(^|/)../%'), '/', $XSLTfilename);
if (file_exists($XSLTfilename)) {
$XSLProc = new XsltProcessor();
$xslt = new DomDocument();
$xslt->load($XSLTfilename);
$XSLProc->importStyleSheet($xslt);
// Set some context
$XSLProc->setParameter('', array('section-handle' => $section->get('handle'), 'entry-id' => $entry->get('id')));
$temp = $XSLProc->transformToDoc($dom);
if ($temp instanceof DOMDocument) {
$dom = $temp;
}
}
}
$xpath = new DOMXPath($dom);
if (version_compare(phpversion(), '5.3', '>=')) {
$xpath->registerPhpFunctions();
}
return $xpath;
}
示例12: google
/**
* create google sitemap
*
* @return void
* @author Andy Bennett
*/
public function google()
{
$xsl_path = Kohana::find_file('xsl', 'sitemap', TRUE, 'xsl');
/* load the xml file and stylesheet as domdocuments */
$xsl = new DomDocument();
$xsl->load($xsl_path);
$inputdom = new DomDocument();
$inputdom->loadXML($this->sitemap_string);
/* create the processor and import the stylesheet */
$proc = new XsltProcessor();
$proc->importStyleSheet($xsl);
$proc->setParameter('', 'siteurl', url::base());
/* transform and output the xml document */
$newdom = $proc->transformToDoc($inputdom);
print $newdom->saveXML();
}
示例13: parseContent
/**
* internal function
* uses an xsl to parse the sparql xml returned from the ITQL query
*
*
* @param $content String
*/
function parseContent($content, $pid, $dsId, $collection, $pageNumber = null)
{
$path = drupal_get_path('module', 'Fedora_Repository');
global $base_url;
$collection_pid = $pid;
//we will be changing the pid later maybe
//module_load_include('php', ''Fedora_Repository'', 'ObjectHelper');
$objectHelper = $this;
$parsedContent = NULL;
$contentModels = $objectHelper->get_content_models_list($pid);
$isCollection = false;
//if this is a collection object store the $pid in the session as it will come in handy
//after a purge or ingest to return to the correct collection.
if (!empty($contentModels)) {
foreach ($contentModels as $contentModel) {
if ($contentModel == 'epistemetec:albumCModel' || $contentModel == 'epistemetec:compilationCModel' || $contentModel == 'epistemetec:videotecaCModel' || $contentModel == 'epistemetec:collectionCModel') {
$_SESSION['fedora_collection'] = $pid;
$isCollection = true;
}
}
}
//get a list of datastream for this object
$datastreams = $this->get_formatted_datastream_list($pid, $contentModels);
//$label=$content;
$collectionName = $collection;
if (!$pageNumber) {
$pageNumber = 1;
}
if (!isset($collectionName)) {
$collectionName = variable_get('fedora_repository_name', 'Collection');
}
$xslContent = $this->getXslContent($pid, $path);
//get collection list and display using xslt-------------------------------------------
if (isset($content) && $content != false) {
$input = new DomDocument();
$input->loadXML(trim($content));
$results = $input->getElementsByTagName('result');
if ($results->length > 0) {
try {
$proc = new XsltProcessor();
$proc->setParameter('', 'collectionPid', $collection_pid);
$proc->setParameter('', 'collectionTitle', $collectionName);
$proc->setParameter('', 'baseUrl', $base_url);
$proc->setParameter('', 'path', $base_url . '/' . $path);
$proc->setParameter('', 'hitPage', $pageNumber);
$proc->registerPHPFunctions();
$xsl = new DomDocument();
$xsl->loadXML($xslContent);
//php xsl does not seem to work with namespaces so removing it below
//I may have just been being stupid here
// $content = str_ireplace('xmlns="http://www.w3.org/2001/sw/DataAccess/rf1/result"', '', $content);
$xsl = $proc->importStylesheet($xsl);
$newdom = $proc->transformToDoc($input);
$objectList = $newdom->saveXML();
//is the xml transformed to html as defined in the xslt associated with the collection object
if (!$objectList) {
throw new Exception("Invalid XML.");
}
} catch (Exception $e) {
drupal_set_message(t($e->getMessage()), 'error');
return '';
}
}
} else {
drupal_set_message(t("No Objects in this Collection or bad query."));
}
//--------------------------------------------------------------------------------
//show the collections datastreams
if ($results->length > 0 || $isCollection == true) {
// if(strlen($objectList)>22||$contentModel=='Collection'||$contentModel=='Community'){//length of empty dom still equals 22 because of <table/> etc
$collectionPolicyExists = $objectHelper->getMimeType($pid, 'COLLECTION_POLICY');
//drupal_set_message($collectionPolicyExists, 'error');
if (user_access(ObjectHelper::$INGEST_FEDORA_OBJECTS) && $collectionPolicyExists) {
if (!empty($collectionPolicyExists) && strcasecmp($collectionPolicyExists, 'application/zip')) {
$ingestObject = '<a title="' . t('Ingest a New object into ') . $collectionName . ' ' . $collection_pid . '" href="' . base_path() . 'fedora/ingestObject/' . $collection_pid . '/' . $collectionName . '"><img hspace = "8" src="' . $base_url . '/' . $path . '/images/ingest.png" alt="' . t('Ingest Object') . '"></a>';
}
} else {
$ingestObject = ' ';
}
$datastreams .= $ingestObject;
$collection_fieldset = array('#title' => t('Collection Description'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#value' => $datastreams);
$collectionListOut = theme('fieldset', $collection_fieldset);
$object_list_fieldset = array('#title' => t('Items in this Collection'), '#collapsible' => TRUE, '#collapsed' => FALSE, '#value' => isset($objectList) ? $objectList : '');
$objectListOut = theme('fieldset', $object_list_fieldset);
} else {
//$collectionName='';
$collection_fieldset = array('#title' => "", '#collapsible' => TRUE, '#collapsed' => FALSE, '#value' => $datastreams);
$collectionListOut = theme('fieldset', $collection_fieldset);
$objectListOut = '';
//no collection objects to show so don't show field set
}
return "<STRONG>" . $collectionName . "</STRONG>" . ' <br />' . $collectionListOut . '<br />' . $objectListOut;
}
示例14: folksoClient
<div id="container">
<?php
if ($_GET['tag']) {
$tagthing = strip_tags(substr($_GET['tag'], 0, 255));
$fc = new folksoClient('localhost', $loc->server_web_path . 'tag.php', 'get');
$fc->set_getfields(array('folksotag' => $tagthing, 'folksofancy' => '1'));
$reslist = $fc->execute();
if ($fc->query_resultcode() == 200) {
$resources = new DOMDocument();
$resources->loadXML($reslist);
$xsl = new DOMDocument();
$xsl->load($loc->xsl_dir . "resourcelist.xsl");
$proc = new XsltProcessor();
$xsl = $proc->importStylesheet($xsl);
$form = $proc->transformToDoc($resources);
print $form->saveXML();
} else {
print $fc->query_resultcode();
}
}
?>
<div id="pagebottom">
<form action="resourceview.php" method="get">
<p>
Entrer un uri ou un identifiant de resource déjà présente dans la base
</p>
<p>
<input type="text" name="tagthing" maxlength="3" size="3"></input>
</p>
<p>
示例15: loadDataModels
/**
* Returns all matching XML schema files and loads them into data models for
* class.
*/
protected function loadDataModels()
{
$schemas = array();
$totalNbTables = 0;
$dataModelFiles = $this->getSchemas();
$defaultPlatform = $this->getGeneratorConfig()->getConfiguredPlatform();
// Make a transaction for each file
foreach ($dataModelFiles as $schema) {
$dmFilename = $schema->getPathName();
$this->log('Processing: ' . $schema->getFileName());
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->load($dmFilename);
$this->includeExternalSchemas($dom, $schema->getPath());
// normalize (or transform) the XML document using XSLT
if ($this->getGeneratorConfig()->get()['generator']['schema']['transform'] && $this->xsl) {
$this->log('Transforming ' . $dmFilename . ' using stylesheet ' . $this->xsl->getPath());
if (!class_exists('\\XSLTProcessor')) {
$this->log('Could not perform XLST transformation. Make sure PHP has been compiled/configured to support XSLT.');
} else {
// normalize the document using normalizer stylesheet
$xslDom = new \DOMDocument('1.0', 'UTF-8');
$xslDom->load($this->xsl->getAbsolutePath());
$xsl = new \XsltProcessor();
$xsl->importStyleSheet($xslDom);
$dom = $xsl->transformToDoc($dom);
}
}
// validate the XML document using XSD schema
if ($this->validate && $this->xsd) {
$this->log(' Validating XML using schema ' . $this->xsd->getPath());
if (!$dom->schemaValidate($this->xsd->getAbsolutePath())) {
throw new EngineException(sprintf("XML schema file (%s) does not validate. See warnings above for reasons validation failed (make sure error_reporting is set to show E_WARNING if you don't see any).", $dmFilename), $this->getLocation());
}
}
$xmlParser = new SchemaReader($defaultPlatform, $this->dbEncoding);
$xmlParser->setGeneratorConfig($this->getGeneratorConfig());
$schema = $xmlParser->parseString($dom->saveXML(), $dmFilename);
$nbTables = $schema->getDatabase(null, false)->countTables();
$totalNbTables += $nbTables;
$this->log(sprintf(' %d tables processed successfully', $nbTables));
$schema->setName($dmFilename);
$schemas[] = $schema;
}
$this->log(sprintf('%d tables found in %d schema files.', $totalNbTables, count($dataModelFiles)));
if (empty($schemas)) {
throw new BuildException('No schema files were found (matching your schema fileset definition).');
}
foreach ($schemas as $schema) {
// map schema filename with database name
$this->dataModelDbMap[$schema->getName()] = $schema->getDatabase(null, false)->getName();
}
if (count($schemas) > 1 && $this->getGeneratorConfig()->get()['generator']['packageObjectModel']) {
$schema = $this->joinDataModels($schemas);
$this->dataModels = array($schema);
} else {
$this->dataModels = $schemas;
}
foreach ($this->dataModels as &$schema) {
$schema->doFinalInitialization();
}
$this->dataModelsLoaded = true;
}