1

I have a Drupal 6 website that needs to populate a page with data from an XML feed. We are considering using XSLT to transform the data into an appropriate format, however in searching the internet for ideas I haven't come up with much.

So far I've found CCK XSLT, which doesn't seem to have much documentation behind it, and Services, which seems to interact only with an XML-RPC server (we would simply be pulling a feed itself, not interacting with a server).

Is there a good way to go about doing this?

(Also, I don't have enough rep to create an XSLT tag. If some kind user would like to retag for me, I'd appreciate it)

  • Do you need to use XSLT to store the data in the node, or store the XML in the node and use XSLT for the output only? – mpdonadio Jun 14 '12 at 16:25
  • At this point I'm not sure. I have a link to an XML feed that I need to display. How it gets displayed is up in the air. – the_e Jun 14 '12 at 18:45
1

The easiest (though probably not the best), is to do something like:

// http://api.drupal.org/api/drupal/modules--system--system.api.php/function/hook_permission/7

function mymodule_permission ()
{
    return array(
        "view mypage" => array(
            "title" => t("View My Page"), 
            "description" => t("View My Page"),
        ),
    );
}

// http://api.drupal.org/api/drupal/modules--system--system.api.php/function/hook_menu/7

function mymodule_menu ()
{
    $items = array();

    $items["mymodule_mypage"] = array(
        "title" => "My Page",
        "page callback" => "_mymodule_generate",
        "access arguments" => array("view mypage"),
        "type" => MENU_CALLBACK,
    );

    return $items;
}

function _mymodule_generate ()
{
    $path = drupal_get_path('module', 'mymodule');

    drupal_add_css("{$path}/mymodule.css", array(
        "type" => "file",
    ));

    $xsl = new DOMDocument();
    $xsl->load("{$path}/mymodule.xsl");

    $xslt = new XSLTProcessor();
    $xslt->importStyleSheet($xsl);

    $xml = new DOMDocument();
    $xml->load("{$path}/mymodule.xml");

    return (string) $xslt->transformToXML($xml);
}

This is stripped down code I have taken from a custom module I have for displaying a resume maintained in XML format.

  • Looks nice. Would this dynamically grab the XML feed each time, or pull it in once into a new node? – the_e Jun 21 '12 at 17:53
  • This does it each time. If you are interested in new nodes, then there is a different approach I can write up. – mpdonadio Jun 21 '12 at 18:01
  • I think at present dynamic should be sufficient. I appreciate it! – the_e Jun 25 '12 at 2:41
  • Just finished the implementation...working great...thanks!! – the_e Jun 26 '12 at 3:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.