Sophie

Sophie

distrib > Mandriva > 2010.0 > x86_64 > media > main-release > by-pkgid > 71fef6b9bbd764d1491dbe60964943fb > files > 17

lib64sablotron-devel-1.0.3-7mdv2010.0.x86_64.rpm

<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:
--------------------
&lt;?xml version="1.0"?&gt;
&lt;xsl:stylesheet version="1.0"
&nbsp;&nbsp;&nbsp;xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
&nbsp;&nbsp;&nbsp;xmlns:func="http://www.exslt.org/functions"
&nbsp;&nbsp;&nbsp;xmlns:my="http://gingerall.org/sablot/myfunc"
&nbsp;&nbsp;&nbsp;extension-element-prefixes="func"
&nbsp;&nbsp;&nbsp;exclude-result-prefixes="my"&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&lt;xsl:output method="xml" indent="yes"/&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&lt;func:script implements-prefix="my" language="javascript"&gt;&lt;![CDATA[
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;function attrSum(nodeset) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var sum = 0;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (i = 0; i &lt; nodeset.length; i++) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (j = 0; j &lt; nodeset[i].attributes.length; j++) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum += Number(nodeset[i].attributes.item(j));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return sum;
&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;]]&gt;
&nbsp;&nbsp;&nbsp;&lt;xsl:fallback&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xsl:text&gt;JS extension no supported!&lt;/xsl:text&gt;
&nbsp;&nbsp;&nbsp;&lt;/xsl:fallback&gt;
&nbsp;&nbsp;&nbsp;&lt;/func:script&gt;


&nbsp;&nbsp;&nbsp;&lt;xsl:template match="/root"&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;root&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xsl:choose&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xsl:when test="function-available('my:attrSum')"&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xsl:text&gt;The sum of attributes: &lt;/xsl:text&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xsl:value-of select="my:attrSum(node)"/&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/xsl:when&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xsl:otherwise&gt;Function not available!&lt;/xsl:otherwise&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/xsl:choose&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/root&gt;
&nbsp;&nbsp;&nbsp;&lt;/xsl:template&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/xsl:stylesheet&gt;

Data:
--------------------
&lt;?xml version="1.0"?&gt;
&lt;root&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&lt;node a="1" b="2"/&gt;
&nbsp;&nbsp;&nbsp;&lt;node c="10"/&gt;
&nbsp;&nbsp;&nbsp;&lt;node a="5" b="6" c="7"/&gt;

&lt;/root&gt;

Result:
--------------------
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;root&gt;The sum of attributes: 31&lt;/root&gt;

</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>
&copy; 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>