示例#1
0
function xsl_splitContrib($m)
{
    $SEP = ',';
    $dom = new DOMDocument();
    $root = $dom->createElement('contrib-group');
    $txt = $m[0]->textContent;
    // contribs não tem tags, ok txt!
    //foreach ($m[0]->childNodes as $node) $txt .= $node->nodeValue;
    $lst = explode($SEP, $txt);
    //for($i=count($lst)-1; $i+1; $i--) {
    $ni = count($lst) - 1;
    for ($i = 0; $i <= $ni; $i++) {
        $name = trim($lst[$i]);
        $isCorresp = 0;
        $name = preg_replace('/\\*$/', '', $name, 1, $isCorresp);
        $node = $dom->createElement('contrib');
        // ,$name
        $node->setAttribute('contrib-type', 'author');
        if ($isCorresp) {
            $node->setAttribute('corresp', 'yes');
        }
        if (preg_match('/^(.+?)\\s+(.+?)$/', $name, $m)) {
            $surname = str_replace('-', '‑', $m[1]);
            //'&#8209;' copiado como  "―"
            $given = str_replace('-', '‑', $m[2]);
            $node->appendChild($dom->createElement('surname', $surname));
            //$node->appendChild( $dom->createTextNode(' ') ); // cuidado é NBSP dá pau! enquanto createTextNode('♣') funciona!
            // ver meu comentario em http://stackoverflow.com/a/8867502/287948 (mas resolvido por hora)
            $node->appendChild($dom->createEntityReference('nbsp'));
            $node->appendChild($dom->createElement('given-names', $given));
            // initials
        } else {
            $node->appendChild($dom->createElement('surname', $name));
        }
        $root->appendChild($node);
        if ($i < $ni) {
            // not last
            $root->appendChild($dom->createTextNode("{$SEP} "));
        }
        // menos no last!
    }
    return $root;
}
<?php

$dom = new DOMDocument('1.0');
$ref = $dom->createEntityReference('nbsp');
$dom->appendChild($ref);
echo $dom->saveXML();
示例#3
0
 /**
  *   Adds a simpara and a static entity to an existing method declaration.
  *
  *   Hackish but working.
  *
  *   @param  DOMDocument $doc  The DOMDocument object.
  *   @param  DOMNode     $desc The DOMNode for the method description.
  *   @return boolean true if the method was updated.
  */
 function addStatic(DOMDocument $doc, DOMNode $desc)
 {
     // Check to see if the static entity has already been added.
     if ($desc->hasChildNodes()) {
         /**
          *   BAD HACK: This will not work anymore if the
          *   entity changes.
          */
         // The DOMDocument translates the entities on loading.
         $staticText = 'This method must be called statically.';
         // Get simparas.
         $list = $desc->getElementsByTagName('simpara');
         for ($i = 0; $i < $list->length; ++$i) {
             $node = $list->item($i);
             if ($node->hasChildNodes()) {
                 // Check for the static text.
                 $child = $node->firstChild;
                 do {
                     if ($child instanceof DOMText && trim($child->wholeText) == $staticText) {
                         return false;
                     }
                 } while ($child = $child->nextSibling);
             }
         }
     }
     $simpara = $doc->createElement('simpara');
     $simpara->appendChild($doc->createTextNode("\n     "));
     $simpara->appendChild($doc->createEntityReference('static'));
     $simpara->appendChild($doc->createTextNode("\n    "));
     $desc->appendChild($doc->createTextNode(' '));
     $desc->appendChild($simpara);
     $desc->appendChild($doc->createTextNode("\n   "));
     return true;
 }