Re: using xslt/JS inside the page

Lucky <[email protected]>
Newsgroups gmane.comp.mozilla.devel.layout.xslt
Organization Cox Communications
Message-ID <WC2Ae.64819$%Z2.21116@lakeread08>
Nic Ferrier wrote:
> Lucky <[email protected]> writes:
> 
> 
>>Nic Ferrier> you should try using:
>>
>>var xslt = (new DOMParser()).parseFromString('<your>xml</your>','text/xml');
>>
>>and same for the xmlDocument creations.
>>
>>should get you a step closer?
> 
> 
> 
> It does work... I'll post later with the full text of the solution.
> 
> 
> Nic
> 
> 
yes, plus a documentFragment will not allow .innerHTML it inherits from 
Node, and not a full HTMLElement object;

yet, you could see "goodbye!" from result.firstChild.innerHTML ...

/* simple test page */


<html>
   <head>
     <script>


function XML(s) {
   return (new DOMParser()).parseFromString(s,'text/xml');
}
XMLDocument.prototype.__defineGetter__('xml',function() {
   return (new XMLSerializer()).serializeToString(this);
});

var proc = new XSLTProcessor();
var xslt = XML([
   '<?xml version="1.0"?>',
   '<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
version="1.0">',
   '  <xsl:output method="html"/>',
   '  <xsl:template match="/test">',
   '    <p>goodbye!</p>',
   '  </xsl:template>',
   '</xsl:stylesheet>'
].join('\n'));

var xml = XML([
   '<?xml version="1.0"?>',
   '<test>',
   '  <item><title>hello!</title><link>someplace</link></item>',
   '  <item><title>hello to you too!</title><link>otherplace</link></item>',
   '</test>'
].join('\n'));

proc.importStylesheet(xslt);

var result = proc.transformToFragment(xml,document);
alert( result.firstChild.innerHTML );
var result2 = proc.transformToDocument(xml);
alert( result2 );

     </script>
   </head>
</html>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.