Re: using xslt/JS inside the page
Lucky <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.layout.xslt |
|---|---|
| Organization | Cox Communications |
| Message-ID | <2jKze.63190$%Z2.52657@lakeread08> |
Nic Ferrier wrote:
> Here's an HTML document:
>
> <html>
> <head>
> <script>
> var proc = new XSLTProcessor();
> var xslt = document.implementation.createDocument("", "", null);
> xslt.innerHTML = "<?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>";
> proc.importStylesheet(xslt);
>
> var src_doc = document.implementation.createDocument("", "", null);
> src_doc.innerHTML = "<?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>";
> var result = proc.transformToFragment(src_doc, document);
> alert(result);
> alert(result.innerHTML);
> </script>
> </head>
> <body>
> <h1>hello</h1>
> </body>
> </html>
>
>
> result.innerHTML is null and looking at result it looks like it has no
> children, where it should have one: a text node saying "goodbye".
>
> Anybody know why this is?
>
>
> 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?