Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Cannot access NodeList in JScript

From: Martin Honnen <mahotrash@-----.-->
To: 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/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent