Re: Problem using XSL on FF
"Anthony Jones" <[email protected]> Wed, 23 Jan 2008 12:48:04 -0000
| Newsgroups | gmane.comp.mozilla.devel.xml |
|---|---|
| Message-ID | <[email protected]> |
"Daniel Tadeu" <[email protected]> wrote in message news:716560cc-7427-428f-a67c-d9c9c58e659f@v46g2000hsv.googlegroups.com... > Hi all, > > I'm trying to generate a web page page using XML and XSL, according > the codes below. When I load the XML on IE6 and IE7, it works. When I > load the XML on Firefox (2.0.0.11), the command <xsl:copy-of> doesn't > work. Why it happens? Should I change something on codes? > <xml and xsl moved to end of message> In both FF and IE when a textarea element is encontered during the parsing of HTML the inner content of the textarea is considered to be its value and no further parsing of markup occurs on that content. (See http://www.w3.org/TR/html4/interact/forms.html#h-17.7) In IE the transform is actually performed by an external component which has no knowledge of the HTML DOM used inside IE. It simply generates the output as character stream which is then parsed by IE as if the stream were coming directly from HTTP. Hence the textarea handling is as you would expect. Firefox, OTH, takes the output of the transform directly into the DOM because FF's XSL processor is more tightly integrated and can create DOM elements directly (FF has a single DOM for handling both HTML and XML). So having created the textarea element it performs the copy-of by literally doing a deep copy of the selected element and appending it to the textarea element. Hence the textarea ends up with child nodes. (Note that it is debatable whether this is a bug, IE for example will allow script to create child nodes and append them in a textarea, their contents would also not be displayed by the textarea). The following code works in FF but in IE it captialises the element names. <xsl:template match="/"> <textarea rows="40" cols="80" id="meuxml"> </textarea> <div style="display:none" id="divXml"> <xsl:copy-of select ="xml/chart"/> </div> <script> copyHTML(); function copyHTML() { var txt = document.getElementById('meuxml') var div = document.getElementById('divXml') txt.value = div.innerHTML } </script> </xsl:template> -- Anthony Jones - MVP ASP/ASP.NET > << cars.xml >> > <xml> > <search> > <year>2007</year> > </search> > <chart> > <series> > <values id="car1">3000</values> > <values id="car1">5000</values> > </series> > </chart> > </xml> > > << template.xsl >> > > <?xml version="1.0"?> > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > xmlns:msxsl="urn:schemas-microsoft-com:xslt" extension-element- > prefixes="msxsl" version="1.0"> > > <xsl:template match="/"> > <textarea rows="40" cols="80" id="meuxml"> > <xsl:copy-of select ="xml/chart"/> > </textarea> > <script> > alert(meuxml.value); > </script> > </xsl:template> > </xsl:stylesheet>