[?1034hdiff -r e8f31e110d17 machine-fs/srv/drupal/sites/all/modules/xmlcontent/xmlcontent.module
--- a/machine-fs/srv/drupal/sites/all/modules/xmlcontent/xmlcontent.module	Sun Sep 02 15:26:50 2007 -0400
+++ b/machine-fs/srv/drupal/sites/all/modules/xmlcontent/xmlcontent.module	Sun Sep 02 18:27:43 2007 -0400
@@ -42,7 +42,7 @@ function xmlcontent_filter($op, $delta =
       $xslt_path = drupal_get_path('module', 'xmlcontent'). '/' . variable_get("xmlcontent_xslt_path_$format", '');
       if (!is_file($xslt_path))
         $xslt_path = variable_get("xmlcontent_xslt_path_$format", '');
-      return _xmlcontent_transform($text, $xslt_path);
+      return _xmlcontent_transform($text, $xslt_path, $format);
 
     case 'settings':
       return _xmlcontent_filter_settings($format);
@@ -185,6 +185,24 @@ function _xmlcontent_filter_settings($fo
     '#default_value' => variable_get("xmlcontent_schema_path_$format", ''),
     '#field_prefix'  => drupal_get_path('module', 'xmlcontent'). '/',
     '#description'  => t('The file path to the XSD/RNG schema to be used for validating this format. <b>Leave blank if you do not need schema validation</b>'),
+  );    
+  $form['xmlcontent']['xinclude'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Xinclude Processing'),
+    '#collapsible' => TRUE,
+    '#collapsed' => FALSE,
+  );
+  $form['xmlcontent']['xinclude']["xmlcontent_xinclude_body_$format"] = array(
+    '#type'    => 'checkbox',
+    '#title'   => t('Process &lt;xi:include ...&gt; on document body'),
+    '#default_value' => variable_get("xmlcontent_xinclude_body_$format", '0'),
+    '#description'  => t('If this option is selected, &lt;xi:include ...&gt; elements in the document body will be processed. Note that Drupal caching is unaware of xinclude processing, so there may be delays in the appearance of updates for included content.<br /><br />Enabling this permits authors of this input format to dynamically incorporate content from external sources, which may not be desirable for some input types. If you enable this, you may wish to give thought to which roles should have the authority to create/edit input formats that have xinclude processing enabled.'),
+  );    
+  $form['xmlcontent']['xinclude']["xmlcontent_xinclude_xsltscript_$format"] = array(
+    '#type'    => 'checkbox',
+    '#title'   => t('Process &lt;xi:include ...&gt; on XSLT script'),
+    '#default_value' => variable_get("xmlcontent_xinclude_xsltscript_$format", '1'),
+    '#description'  => t('If this option is selected, &lt;xi:include ...&gt; elements in the XSLT script will be processed. Note that if something included by the processing script is modified, there may be a delay before the effects are seen due to Drupal caching.'),
   );    
   return $form;
 }
@@ -200,7 +218,7 @@ function _xmlcontent_filter_settings($fo
  *   before invoking it on the XML data document. Examples include namespace settings and
  *   XSL parameters.
  */
-function _xmlcontent_transform($xml, $path_to_xslt, $params = array()) {
+function _xmlcontent_transform($xml, $path_to_xslt, $format, $params = array()) {
   if (!$xml) {
     watchdog('xmlcontent',"Empty XML content", WATCHDOG_WARNING);
     return $xml;
@@ -218,6 +236,21 @@ function _xmlcontent_transform($xml, $pa
   if (!$valid) {
     watchdog('xmlcontent', "Invalid XML Content", WATCHDOG_WARNING);
     return $xml;
+  }
+
+  // Issue: It seems that telling libxml to process xincludes will
+  // apply to both the input document and the XSLT script, which may
+  // not be what we want. If xinclude has been enabled for both, we
+  // could skip the expansion here and defer the expansion to
+  // libxslt. In some cases this might significantly lower Drupal
+  // memory overhead, and it would avoid making two passes over the
+  // input. If there is some way to distinguish the two cases using
+  // the libxml interface that I have failed to consider, then it
+  // should be done that way.
+
+  if (variable_get("xmlcontent_xinclude_body_$format", '0')) {
+    $xi_result = $dom->xinclude();
+    // FIX: do we need to re-validate after xinclude?
   }
   
   // Load the XSLT script
@@ -229,6 +262,11 @@ function _xmlcontent_transform($xml, $pa
     return $xml;
   }
 
+  if (variable_get("xmlcontent_xinclude_xsltscript_$format", '0')) {
+    $xi_result = $xsl->xinclude();
+    // FIX: do we need to re-validate after xinclude?
+  }
+  
   // Create the XSLT processor
   $proc = new XsltProcessor();
   $xsl = $proc->importStylesheet($xsl);  
