<html><head><link rel=StyleSheet href='api-content.css' TYPE='text/css' MEDIA='screen'><title>.Example</title> <script> function navToEntry(entry) { window.location.href='api-' + entry + '.html'; } function navToGroup(group) { var f = parent.frames['toc-container']; if (!f) window.open ('sparse-toc.html#' + group, 'toc_container'); else { if (f.location.href.search('abc') != -1) f.location.href = 'sparse-toc.html#' + group; else f.location.hash = group; } } </script> </head><body bgcolor='white'> <!-- -- HEADS UP! This page was *GENERATED* by APIDOC, -- DO NOT EDIT THIS FILE BY HAND! -- See http://www.mozilla.org/projects/apidoc for information on APIDOC -- The original source file was jsdom-ref.xml --> <h1 class='title'>Sablotron Extensions API Reference</h1> <center><table class='api-entry' width='100%' cellspacing='0'border='1' cellpadding='10'> <tr><td class='entry-heading'> <table class='entry-heading-table' width='100%' cellpadding='5'cellspacing='0'><tr> <td class='entry-title' valign='center'><font size='+5'>Example</font></td> <td class='entry-type' align='center' width='25%'>.General</td> </tr></table> </td></tr> <tr><td class='entry-summary'> <h4 class='entry-subhead'>Summary</h4> An example how to use the DOM in JavaScript extension functions. The function returns a sum of all attributes in a nodeset. </td></tr> <tr><td class='entry-example'> <h4 class='entry-subhead'>Example</h4> <pre>Template: -------------------- <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:func="http://www.exslt.org/functions" xmlns:my="http://gingerall.org/sablot/myfunc" extension-element-prefixes="func" exclude-result-prefixes="my"> <xsl:output method="xml" indent="yes"/> <func:script implements-prefix="my" language="javascript"><![CDATA[ function attrSum(nodeset) { var sum = 0; for (i = 0; i < nodeset.length; i++) { for (j = 0; j < nodeset[i].attributes.length; j++) { sum += Number(nodeset[i].attributes.item(j)); } } return sum; } ]]> <xsl:fallback> <xsl:text>JS extension no supported!</xsl:text> </xsl:fallback> </func:script> <xsl:template match="/root"> <root> <xsl:choose> <xsl:when test="function-available('my:attrSum')"> <xsl:text>The sum of attributes: </xsl:text> <xsl:value-of select="my:attrSum(node)"/> </xsl:when> <xsl:otherwise>Function not available!</xsl:otherwise> </xsl:choose> </root> </xsl:template> </xsl:stylesheet> Data: -------------------- <?xml version="1.0"?> <root> <node a="1" b="2"/> <node c="10"/> <node a="5" b="6" c="7"/> </root> Result: -------------------- <?xml version="1.0" encoding="UTF-8"?> <root>The sum of attributes: 31</root> </pre></td></tr> <tr><td class='entry-seealso'> <h4 class='entry-subhead'>See Also</h4> <table class='seealso-table'> <tr class='seealso-groups'><td>Groups</td> <td>[ <a href='javascript:navToGroup("GROUP_.General")'>.General</a> ]</td></tr> </table> </td></tr> </table></center><br> © 2001-2002 Ginger Alliance<BR><i>revision 02-08-05</i><BR> <center>This page was generated by <a href='http://www.mozilla.org/projects/apidoc' target='other_window'><b>APIDOC</b></a></center> </body></html>