From:  Martin Honnen <mahotrash@yahoo.de>
Date:  24 Mar 2009 23:46:00 Hong Kong Time
Newsgroup:  news.mozilla.org/mozilla.dev.web-development
Subject:  

Re: XPath evaluation after XSL transformation

NNTP-Posting-Host:  89.244.205.233

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, 
> XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
> 
> My resolver function is :
> function resolver(prefix) {
>     return 'http://www.w3.org/1999/xhtml';
> }
> 
> 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 
text/xml)?
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, 
> XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
> 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="http://www.w3.org/1999/XSL/Transform">
>  doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" 
> 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:

http://home.arcor.de/martin.honnen/javascript/2009/03/test2009032401.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
	http://JavaScript.FAQTs.com/