Main Page

XSLT Support in Browsers

If you feel like living dangerously, you can use the
XPathResult.ANY_TYPE
. By specifying this result
type,
evaluate()
returns the most appropriate result type based on the XPath expression. Typically,
this result type is a Boolean value, number value, string value, or an unordered node iterator. To deter-
mine which result type has been returned use the
resultType
property:
var oEvaluator = new XPathEvaluator();
var oResult = oEvaluator.evaluate(“employee/name”, oXmlDom.documentElement, null,
XPathResult.STRING_TYPE, null);
if (oResult != null) {
switch(oResult.resultType) {
case XPath.STRING_TYPE:
//handle string type
break;
case XPath.NUMBER_TYPE:
//handle number type
break;
case XPath.BOOLEAN_TYPE:
//handle boolean type
break;
case XPath.UNORDERED_NODE_ITERATOR_TYPE:
//handle unordered node iterator type
break;
default:
//handle other possible result types
}
}
As you can tell, XPath evaluation in Mozilla is much more complicated than IE, but also much more
powerful. By using the custom
selectNodes()
and
selectSingleNode()
methods, you can perform
XPath evaluation in both browsers using the same code.
XSLT Support in Browsers
A sibling language to XML, eXtensible Stylesheet Language Transformations (XSLT) allows the manipula-
tion and transformation of XML code into almost any other text-based form. Presently, many developers
use XSLT to transform XML into HTML, but this is just one use (see Figure 15-1).
Figure 15-1
XML
XSLT
HTML
Text
Other XML
Formats
471
XML in JavaScript
18_579088 ch15.qxd 3/28/05 11:42 AM Page 471


JavaScript EditorFree JavaScript Editor     Ajax Editor


©