1

What I would like to achieve is the this:

  1. Develop new content type
  2. Add two fields to the content type : XML, XSLT, / text areas
  3. When I use this content type later on I want to be able to paste some XML into the XML field, some XSLT into the XSLT field. When I save my new content I want the XML to be translated into HTML.

So in view mode I would always see the HTML, 'edit' mode would give me away of manipulating the XML / XSLT

I started following this tutorial: http://drupal.org/node/231019. But that does not cover how /where to save my new fields. This is how far I got following the tutorial:

/**
* Implementation of hook_node_info().
*/
function xmlparser_node_info() {
  return array (
    'node_amlparser'=>array(
    'name'          => t('XML Parser'),
    'module'        => 'xmlparser',
    'description'   => 'This module takes XML and XSLT to generate HTML'
  )     
 );
}
/**
* Implementation of hook_perm().
*/  
function xmlparser_perm () {
  return array ('create xml content','edit own xml content');
}
/**
* Implementation of hook_access().
*/  
function xmlparser_access($op, $node, $account) {
  if ($op == 'create') {
    // Only users with permission to do so may create this node type.
    return user_access('create xml contene', $account);
  }
  if ($op == 'update' || $op == 'delete') {
  if (user_access('edit own xml content', $account) && ($account->uid == $node->uid)) {return TRUE;}
  }
}  
/**
* Implementation of hook_form().
*/
function xmlparser_form (&$node, $form_state) {
  $type = node_get_types('type', $node);

  $form['title'] = array(
    '#type' => 'textfield',
'#title' => check_plain($type->title_label),
'#required' => TRUE,
'#default_value' => $node->title,
'#weight' => -5
  );
  $form['xml'] = array(
    '#type' => 'textarea',
'#title' => check_plain('xml'),
'#required' => TRUE,
'#weight' => -5
  );
  $form['xslt'] = array(
    '#type' => 'textarea',
'#title' => check_plain('xslt'),
'#required' => TRUE,
'#weight' => -5
  );        
  $form['body_filter']['body'] = array(
    '#type' => 'textarea',
'#title' => check_plain($type->body_label),
'#default_value' => $node->body,
'#required' => FALSE
  );
  $form['body_filter']['filter'] = filter_form($node->format);
    return $form;
}

So this brought me to the point that my content type comes up when creating new content - cool. But where do I need to go now to actually save my values? Where would I save my HTML once the XML is parsed on submit?

I know quite a few question, but any input would be great appreciated!

Thanks, Uwe

1 Answer 1

0

Here is an idea that will keep coding to a minimum using already existing modules:

  1. Using CCK if D6 or the fields if D7 create a regular content type and add an extra field for the XML as I will use the automatically added body to store the XSLT. On the content type display section hide the XSLT field, this way the data is collected, but it is not shown when the node is been view.

  2. I will install the custom formatter module to create a text formatter where I can apply the XSLT to the XML and then present it as HTML.

  3. If I can not apply the formatter directly to the body field in the content type display settings I will the hide both fields (body & XSLT) and using views attachment in D6 or EVA in D7 attach the body field with the formatter applied to the content type.

  4. Last but not least if I plan to re-use this setup in others sites I will use the "Features" module to exported.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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