Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: Cannot access NodeList in JScript [Thread Next] Re: Cannot access NodeList in JScriptTo: NULL Date: 10/7/2004 4:43:00 PM
Patrick Buxton wrote:
> Is there any way I can write the stylesheet so that it will work both
> ways???
J(ava)Script is rather flexible to use object detection to find out what
is possible e.g. the following stylesheet uses JScript and object
detection to find out which properties are available so that it works
with .NET as well as with MSXML:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:ex="http://example.com/2004/10/07/ex">
<xsl:output method="html" encoding="UTF-8" />
<msxsl:script language="JScript" implements-prefix="ex"><![CDATA[
function countNodes (nodeListOrNodeIterator) {
if (typeof nodeListOrNodeIterator.length != 'undefined') {
return nodeListOrNodeIterator.length;
}
else if (typeof nodeListOrNodeIterator.Count != 'undefined') {
return nodeListOrNodeIterator.Count;
}
}
]]>
</msxsl:script>
<xsl:template match="/">
<html>
<head>
<title>XSLT scripting against MSXML and .NET</title>
</head>
<body>
<p>Number of elements in document:
<xsl:value-of select="ex:countNodes(//*)" />
</p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
I am aware that the example script function does nothing that XPath
couldn't do without script but the function serves only to show how to
use JScript object detection to distinguish which object model is
available to script.
--
Martin Honnen
http://JavaScript.FAQTs.com/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
