Archive for Июль, 2006
JavaScript 1.7 is a language update introducing several new features, in particular generators, iterators, array comprehensions, let expressions, and destructuring assignment. It also includes all the features of JavaScript 1.6.
more…
Июль 24th, 2006
With modern browsers supporting XSLT, developers can now use JavaScript to access the power that XSLT provides. JavaScript can enable a web application to load XML data, process it via XSLT into a presentable form and then add it into an existing document. Since the XML data loaded only contains the raw information without any presentation data, it can load quickly even on dialup.
XSLT allows the author to directly manipulate the structure of a document. For example, it permits the rearranging and sorting of elements; it also provides more fine-grained control of the resulting document’s structure.
As of Mozilla 1.2, Gecko enables JavaScript to create XSLT processors. This article covers XSLT/JavaScript bindings in Gecko. They are not available in Netscape 7.0x.
More…
Июль 3rd, 2006
Mozilla supports XSL Transformations (XSLT) 1.0. It also allows JavaScript to perform XSLT transformations and allows running XPATH on a document.
Mozilla requires that you send the XML and XSLT file holding the stylesheet with an XML mimetype (text/xml or application/xml). This is the most common reason why XSLT won’t run in Mozilla but will in Internet Explorer. Mozilla is strict in that way.
Internet Explorer 5.0 and 5.5 supported XSLT’s working draft, which is substantially different than the final 1.0 recommendation. The easiest way to distinguish what version an XSLT file was written against is to look at the namespace. The namespace for the 1.0 recommendation is http://www.w3.org/1999/XSL/Transform, while the working draft’s namespace is http://www.w3.org/TR/WD-xsl. Internet Explorer 6 supports the working draft for backwards compatibility, but Mozilla does not support the working draft, only the final recommendation.
If XSLT requires you to distinguish the browser, you can query the “xsl:vendor” system property. Mozilla’s XSLT engine will report itself as “Transformiix” and Internet Explorer will return “Microsoft.”
<xsl:if test=\"system-property('xsl:vendor') = 'Transformiix'\">
<!-- Mozilla specific markup -->
</xsl:if>
<xsl:if test=\"system-property('xsl:vendor') = 'Microsoft'\">
<!-- Internet Explorer specific markup -->
</xsl:if>
Июль 3rd, 2006
Internet Explorer has a nonstandard feature called XML data islands, which allow you to embed XML inside an HTML document using the nonstandard HTML tag <xml>. Mozilla does not support XML data islands and handles them as unknown HTML tags. You can achieve the same functionality using XHTML; however, because Internet Explorer’s support for XHTML is weak, this is usually not an option.
One cross-browser solution is to use DOM parsers, which parse a string that contains a serialized XML document and generates the document for the parsed XML. Mozilla uses the DOMParser class, which takes the serialized string and creates an XML document out of it. In Internet Explorer, you can achieve the same functionality using ActiveX. A new Microsoft.XMLDOM generates and has a loadXML method that can take in a string and generate a document from it. The following code shows you how:
<xml id=\"xmldataisland\">
<foo>bar</foo>
</xml>
Cross-browser solution:
var xmlString = '<xml id=\"xmldataisland\"><foo>bar</foo></xml>';
var myDocument;
if (document.implementation.createDocument){
// Mozilla, create a new DOMParser
var parser = new DOMParser();
myDocument = parser.parseFromString(xmlString, 'text/xml');
} else if (window.ActiveXObject){
// Internet Explorer, create a new XML document using ActiveX
// and use loadXML as a DOM parser.
myDocument = new ActiveXObject('Microsoft.XMLDOM')
myDocument.async='false';
myDocument.loadXML(xmlString);
}
Июль 2nd, 2006