Пример #1
0
 /**
  * Perform an XSLT transformation and return the results.
  *
  * @param string $xslt   Name of stylesheet (in application/xsl directory)
  * @param string $xml    XML to transform with stylesheet
  * @param array  $params Associative array of XSLT parameters
  *
  * @return string      Transformed XML
  */
 public static function process($xslt, $xml, $params = [])
 {
     if ($xslt != 'record-marc.xsl') {
         return parent::process($xslt, $xml, $params);
     }
     $style = new DOMDocument();
     $style->load(APPLICATION_PATH . '/module/Swissbib/xsl/' . $xslt);
     $xsl = new XSLTProcessor();
     $xsl->registerPHPFunctions();
     $xsl->importStyleSheet($style);
     $doc = new DOMDocument();
     if ($doc->loadXML($xml)) {
         foreach ($params as $key => $value) {
             $xsl->setParameter('', $key, $value);
         }
         return $xsl->transformToXML($doc);
     }
     return '';
 }
Пример #2
0
 /**
  * Get an XML RDF representation of the data in this record.
  *
  * @return mixed XML RDF data (empty if unsupported or error).
  */
 public function getRDFXML()
 {
     return XSLTProcessor::process('record-rdf-mods.xsl', trim($this->getMarcRecord()->toXML()));
 }
Пример #3
0
 /**
  * Process an SRU response.  Returns either the raw XML string or a
  * SimpleXMLElement based on the contents of the class' raw property.
  *
  * @param string $response SRU response
  *
  * @return string|SimpleXMLElement
  */
 protected function process($response)
 {
     // Send back either the raw XML or a SimpleXML object, as requested:
     $result = XSLTProcessor::process('sru-convert.xsl', $response);
     if (!$result) {
         throw new BackendException(sprintf('Error processing SRU response: %20s', $response));
     }
     return $this->raw ? $result : simplexml_load_string($result);
 }
Пример #4
0
 /**
  * Transforms Collection XML to Desired Format
  *
  * @param string $context     The Context in which the tree is being displayed
  * @param string $mode        The Mode in which the tree is being displayed
  * @param string $hierarchyID The hierarchy to get the tree for
  * @param string $recordID    The currently selected Record (false for none)
  *
  * @return string A HTML List
  */
 protected function transformCollectionXML($context, $mode, $hierarchyID, $recordID)
 {
     $record = $this->getRecordDriver();
     $inHierarchies = $record->getHierarchyTopID();
     $inHierarchiesTitle = $record->getHierarchyTopTitle();
     $hierarchyTitle = $this->getHierarchyName($hierarchyID, $inHierarchies, $inHierarchiesTitle);
     // Set up parameters for XSL transformation
     $params = ['titleText' => $this->translate('collection_view_record'), 'collectionID' => $hierarchyID, 'collectionTitle' => $hierarchyTitle, 'baseURL' => rtrim($this->router->fromRoute('home'), '/'), 'context' => $context, 'recordID' => $recordID];
     // Transform the XML
     $xmlFile = $this->getDataSource()->getXML($hierarchyID);
     $transformation = ucfirst($context) . ucfirst($mode);
     $xslFile = "Hierarchy/{$transformation}.xsl";
     return \VuFind\XSLT\Processor::process($xslFile, $xmlFile, $params);
 }
Пример #5
0
 /**
  * Given a subject term, get related (broader/narrower/alternate) terms.
  * Loosely adapted from Eric Lease Morgan's Term Finder demo (see
  * http://zoia.library.nd.edu/sandbox/term-finder/).  Note that this is
  * intended as a fairly fuzzy search -- $term need not be an exact subject
  * heading; this function will return best guess matches in the 'exact'
  * key, possible broader terms in the 'broader' key and possible narrower
  * terms in the 'narrower' key of the return array.
  *
  * @param string $term       Term to get related terms for.
  * @param string $vocabulary Vocabulary to search (default = LCSH; see OCLC docs
  * for other options).
  * @param int    $maxRecords Max # of records to read from API (more = slower).
  *
  * @return mixed             False on error, otherwise array of related terms,
  * keyed by category.
  */
 public function getRelatedTerms($term, $vocabulary = 'lcsh', $maxRecords = 10)
 {
     // Strip quotes from incoming term:
     $term = str_replace('"', '', $term);
     // Build the request URL:
     $url = "http://tspilot.oclc.org/" . urlencode($vocabulary) . "/?" . "query=oclcts.preferredTerm+%3D+%22" . urlencode($term) . "%22+OR+oclcts.alternativeTerms+%3D+%22" . urlencode($term) . "%22" . "&version=1.1" . "&operation=searchRetrieve" . "&recordSchema=info%3Asrw%2Fschema%2F1%2Fmarcxml-v1.1" . "&maximumRecords=" . intval($maxRecords) . "&startRecord=1" . "&resultSetTTL=300" . "&recordPacking=xml" . "&recordXPath=" . "&sortKeys=recordcount";
     // Get the API response:
     $data = $this->retrieve($url);
     // Extract plain MARCXML from the WorldCat response:
     $marcxml = XSLTProcessor::process('wcterms-marcxml.xsl', $data);
     // Try to parse the MARCXML into a File_MARC object; if this fails,
     // we probably have bad MARCXML, which may indicate an API failure
     // or an empty record set.  Just give up if this happens!
     try {
         $marc = new \File_MARCXML($marcxml, File_MARCXML::SOURCE_STRING);
     } catch (\File_MARC_Exception $e) {
         return false;
     }
     // Initialize arrays:
     $exact = [];
     $broader = [];
     $narrower = [];
     while ($record = $marc->next()) {
         // Get exact terms; only save it if it is not a subset of the requested
         // term.
         $main = $this->getExactTerm($record);
         if ($main && !stristr($term, $main)) {
             $exact[] = $main;
         }
         // Get broader/narrower terms:
         $related = $record->getFields('550');
         foreach ($related as $current) {
             $type = $current->getSubfield('w');
             $value = $current->getSubfield('a');
             if ($type && $value) {
                 $type = (string) $type->getData();
                 $value = (string) $value->getData();
                 if ($type == 'g') {
                     // Don't save exact matches to the user-entered term:
                     if (strcasecmp($term, $value) != 0) {
                         $broader[] = $value;
                     }
                 } else {
                     if ($type == 'h') {
                         // Don't save exact matches to the user-entered term:
                         if (strcasecmp($term, $value) != 0) {
                             $narrower[] = $value;
                         }
                     }
                 }
             }
         }
     }
     // Send back everything we found, sorted and filtered for uniqueness; note
     // that we do NOT sort FAST results since they support relevance ranking.
     // As of this writing, other vocabularies do not support relevance.
     if ($vocabulary !== 'fast') {
         natcasesort($exact);
         natcasesort($broader);
         natcasesort($narrower);
     }
     return ['exact' => array_unique($exact), 'broader' => array_unique($broader), 'narrower' => array_unique($narrower)];
 }
Пример #6
0
 /**
  * Process an SRU response.  Returns either the raw XML string or a
  * SimpleXMLElement based on the contents of the class' raw property.
  *
  * @param string $result SRU response
  *
  * @return string|SimpleXMLElement
  */
 protected function process($result)
 {
     if (substr($result, 0, 5) != '<?xml') {
         throw new \Exception('Cannot Load Results');
     }
     // Send back either the raw XML or a SimpleXML object, as requested:
     $result = XSLTProcessor::process('sru-convert.xsl', $result);
     return $this->raw ? $result : simplexml_load_string($result);
 }