From:  Martin Honnen <>
Date:  24 Mar 2009 23:46:00 Hong Kong Time

Re: XPath evaluation after XSL transformation


Matthieu Corageoud wrote:
> Hello everybody,
> I have a problem while using XPath evaluation after XSL transformation.
> Here is the description of what I am trying to do :
> - I retrieve a XML file with an XHR request.
> - Then I transformed the result using a XSL file and append it to the 
> document with following lines :
> var fragment = processor.transformToFragment(xhrxml.responseXML, document);
> document.getElementById('results').appendChild(fragment);
> - Then I would like to record some events on nodes which have just been 
> added.
> document.evaluate('//xhtml:tbody//xhtml:a', document, resolver, 
> My resolver function is :
> function resolver(prefix) {
>     return '';
> }
> But the above line does not return any node, whereas it works without 
> problem on Safari or Chrome.

What is |document| above, a HTML document with MIME type text/html, or 
an XHTML (application/xhtml+xml) or XML document (application/xml or 
Does using a prefix like 'xhtml:a' work on other elements in that 
document (e.g. elements that don't come from an XSLT transformation)?

> It seems that nodes which have been added to the document after 
> transformation do not have the good namespace. If I remove prefix in 
> query :
> document.evaluate('//tbody//a', document, resolver, 
> It works under firefox but no more in Safari or Chrome.
> Here is a sample of my XML file :
> And my XSL file has following header :
>  xmlns:xsl="">
>  doctype-system="" 
> indent="yes" />

Can you show us whether the stylesheet creates elements in no namespace 
or in the XHTML namespace?

Here is a working sample, it is an XHTML document served as 
application/xhtml+xml that loads some XML and transforms to XHTML:

Works the same (all three inserted XHTML li elements are found) with 
Firefox 3, Opera 9.6, Safari 3.2, all on Windows.


	Martin Honnen