Daniel Harrison
Daniel Harrison

Reputation: 81

XSLTProcessor::transformToXml() ID * already defined

I'll preface this by saying I'm not server admin, but a developer trying to figure out what went wrong.

Our server, which hosts quite a few websites, was upgraded today by the company which manages it (while performing other work). The upgrade ended up breaking a lot of our sites (around 30+) which are now throwing XSLT errors.

Most of the sites are built on symphony CMS (not symfony) which uses XSLT templating to generate the (X)HTML.

Before the update we managed to output multiple IDs on the same page with the same value (eg, id='abc', I know, not valid - ignore that for now). The point was it was working without causing errors.

After the upgrade the sites are all throwing errors now when multiple id values are encountered. eg:

ID abc already defined

One of the updates, which I'm convinced is causing the error, was to the libxslt, libxml and libexslt version. Before we were using:

libxslt Version => 1.1.26 
libxslt compiled against libxml Version => 2.7.8 
libexslt Version => 1.1.26

Since the upgrade:

libxslt Version => 1.1.28  
libxslt compiled against libxml Version => 2.9.1   
libexslt Version => 1.1.28  

My hunch is that it's now treating the XHTML as XML as opposed to HTML, which it did previously, and the XMl doesn't allow multiple ID values.

My question is, has anyone seen this before or know what might be causing it, and what's the appropriate steps to either revert it or force it to ignore multiple id values?

There is no real option at this stage to roll back the changes (so the server admin people say) or to fix the websites (as it would take too long).

Any ideas appreciated.


EDIT NOV 24 2014: Looks like it's an issue in libxml v2.9.1, and not a libxslt issue like I originally thought. I presume downgrading the version of libxml to < v2.9.1 and recompile will work if you have that option to available to you.

I have also logged a bug report to xml[at]gnome.org

Upvotes: 1

Views: 1106

Answers (2)

Simon
Simon

Reputation: 762

I have also recently had this issue when upgrading using EasyApache in cPanel. Unfortunately I have a large codebase that fails due to this issue.

The only working solution I have found so far is to downgrade the libxml version, I am hoping that a compatibility flag may come available that allows legacy code to function as before.

Upvotes: 1

John
John

Reputation: 13759

XHTML is the super-strict version of HTML and that is why I use it, there are none of these "oh you've got horrible code but I'll totally let it slide" games. When you have two or more id attributes with the exact same value there are going to be serious issues with scripting. Unlike Gecko (Firefox) which will refuse to load the page and show you an error multiple matching id attribute/value pairs will create quiet errors, the worst kind of error.

If you're not loading things via JavaScript then simply viewing the source and looking at the id attributes (find all/highlight) and checking the values is one thing. If you're loading XML (you can't load XHTML via AJAX, only XML in to XHTML via AJAX) in to the application then find where you start messing with responseXML and use my script to detect duplicate ids.

if (xmlhttp.responseXML)
{
 if (ajax_id_duplication_prevention(xmlhttp.responseXML))
 {
  //no duplicate ids detected.
 }
}

The script...

function ajax_id_duplication_prevention(xml)
{
 var re = true;

 if (id_(xml.firstChild.id)) {re = false;}
 else if (typeof document.createTreeWalker=='function')
 {
  var idz = [];
  try
  {
   var walker = document.createTreeWalker(xml,NodeFilter.SHOW_ELEMENT,null,false);

   while (walker.nextNode())
   {
    if (walker.currentNode.id==undefined && walker.currentNode.nodeName=='parsererror') {error_handler(arguments.callee.toString().match(/function ([^\(]+)/)[1],JSON.stringify(arguments),2,'Error: a parser error was detected.\n\nThis may or may not afflict the content being loaded.\n\nIf the content does not load correctly reload the entire page.');}
    else if (walker.currentNode.id==undefined) {alert('walker.currentNode.nodeName = '+walker.currentNode.nodeName+'\n\n'+document.serializeToString(xml));}
    else if (walker.currentNode.id!='')
    {
     var n = id_(walker.currentNode.id);
     if (n)
     {
      var l = id_('liquid');
      for (var i=0; i<l.childNodes.length; i++)
      {
       var c = l.childNodes[i];

       if (n.compareDocumentPosition(c)==10)
       {
        element_del(c);
        /*Do AJAX report to DB table: id error log*/
        break;
       }
      }

      break;
     }
     else if (in_array(walker.currentNode.id,idz))
     {
      error_handler(arguments.callee.toString().match(/function ([^\(]+)/)[1],JSON.stringify(arguments),2,'Error: can not import XML, the id \''+walker.currentNode.id+'\' was detected twice in the layer being imported.\n\nDuplicated ID\'s break expected functionality and are illegal.\n\nWhile the XML content was not imported it is still possible that the related request was successful.');
      re = false;
      break;
     }
     else {idz.push(walker.currentNode.id);}
    }
   }
  }
  catch (err) {}/*IE9*/
 }

 return re;
}

Upvotes: 0

Related Questions