/** * Parses the style configuration from the SimpleXMLElement object. * * @param \SimpleXMLElement $xml * @return \Geissler\CSL\Style\Style */ public function readXml(\SimpleXMLElement $xml) { // store "global" configuration options in the context object Container::getContext()->addStyle('initializeWithHyphen', true); Container::getContext()->addStyle('demoteNonDroppingParticle', 'display-and-sort'); foreach ($xml->attributes() as $name => $value) { switch ($name) { case 'class': Container::getContext()->addStyle('class', (string) $value); break; case 'default-locale': $locale = Factory::locale(); $locale->readFile((string) $value); Container::setLocale($locale); break; } } // set global options and inheritable name options $options = new Options(); $options->set('style', $xml); foreach ($xml->children() as $child) { switch ($child->getName()) { case 'citation': Container::setCitation(new Citation($child)); break; case 'bibliography': Container::setBibliography(new Bibliography($child)); break; case 'macro': $macroName = ''; foreach ($child->attributes() as $name => $value) { if ($name == 'name') { $macroName = (string) $value; break; } } if ($macroName !== '') { Container::addMacro($macroName, new Macro($child)); } break; case 'locale': Container::getLocale()->addXml($child); break; } } return $this; }
protected function initElement($layout, $context = '<citation><layout></layout></citation>', $language = 'en-US') { Container::clear(); Container::setData(new Data()); $locale = Factory::locale(); $locale->readFile($language); Container::setLocale($locale); if (strpos($context, 'citation') !== false) { Container::getContext()->setName('citation'); Container::setCitation(new Citation(new \SimpleXMLElement($context))); } else { Container::getContext()->setName('bibliography'); Container::setBibliography(new Bibliography(new \SimpleXMLElement($context))); } $xml = new \SimpleXMLElement($layout); $this->object = new Name($xml); }