xsl-list
[Top] [All Lists]

Re: RE: Creating XPath2 functions:passing a set of nodes, what is the signature construction?

2006-01-25 22:46:44
There's an

   f:sqrt()

function in FXSL.

Its signature:

  <xsl:function name="f:sqrt" as="xs:double">
    <xsl:param name="N"/>
    <xsl:param name="Eps"/>
............................................................
  </xsl:function>

here the first argument is the double to be squared and the second
argument is the desired accuracy (such as 0.0001)

Example of its use:

<xsl:stylesheet version="2.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
 xmlns:f="http://fxsl.sf.net/";
 exclude-result-prefixes="f"


  <xsl:import href="../f/func-sqrt.xsl"/>

  <!-- To be applied on any source xml.
       This also tests the within() function
  -->

  <xsl:output indent="yes" omit-xml-declaration="yes"/>

  <xsl:template match="/*" name="initial">
     sqrt(0.25): <xsl:value-of select="f:sqrt(0.25, 0.00001)"/>
     sqrt(1): <xsl:value-of select="f:sqrt(1, 0.00001)"/>
     sqrt(2): <xsl:value-of select="f:sqrt(2, 0.00001)"/>
     sqrt(4): <xsl:value-of select="f:sqrt(4, 0.00001)"/>
     sqrt(9): <xsl:value-of select="f:sqrt(9, 0.00001)"/>
     sqrt(13): <xsl:value-of select="f:sqrt(13, 0.00001)"/>
     sqrt(16): <xsl:value-of select="f:sqrt(16, 0.00001)"/>
     sqrt(25): <xsl:value-of select="f:sqrt(25, 0.00001)"/>
     sqrt(36): <xsl:value-of select="f:sqrt(36, 0.00001)"/>
     sqrt(49): <xsl:value-of select="f:sqrt(49, 0.00001)"/>
     sqrt(64): <xsl:value-of select="f:sqrt(64, 0.00001)"/>
     sqrt(81): <xsl:value-of select="f:sqrt(81, 0.00001)"/>
     sqrt(100): <xsl:value-of select="f:sqrt(100, 0.00001)"/>
     sqrt(121): <xsl:value-of select="f:sqrt(121, 0.00001)"/>
  </xsl:template>

</xsl:stylesheet>


Result:

Saxon 8.6.1 from Saxonica
Java version 1.5.0_04
Stylesheet compilation time: 500 milliseconds
Processing file:/C:/Program%20Files/Java/jre1.5.0_04/bin/marrowtr.xml
Building tree for
file:/C:/Program%20Files/Java/jre1.5.0_04/bin/marrowtr.xml using class
net.sf.saxon.tinytree.TinyBuilder
Tree built in 0 milliseconds
Tree size: 25 nodes, 31 characters, 10 attributes
Building tree for file:/C:/CVS-DDN/fxsl-xslt2/f/func-sqrt.xsl using
class net.sf.saxon.tinytree.TinyBuilder
Tree built in 0 milliseconds
Tree size: 80 nodes, 270 characters, 44 attributes
Execution time: 125 milliseconds
Memory used: 5076808
NamePool contents: 62 entries in 59 chains. 11 prefixes, 12 URIs
-------------------------------

     sqrt(0.25): 0.5000000795866174
     sqrt(1): 1.0000000464611474
     sqrt(2): 1.4142156862745097
     sqrt(4): 2
     sqrt(9): 3.0000000000393214
     sqrt(13): 3.6055512902583184
     sqrt(16): 4.0000001858445895
     sqrt(25): 5.000000000016778
     sqrt(36): 6.000000002793968
     sqrt(49): 7.000000094930961
     sqrt(64): 8.000001273385879
     sqrt(81): 9.000009415515176
     sqrt(100): 10.000000000107445
     sqrt(121): 11.000000001323027

Cheers,
Dimitre Novatchev

On 1/26/06, cknell(_at_)onebox(_dot_)com <cknell(_at_)onebox(_dot_)com> wrote:
Thanks, I couldn't find that. On closer examination, it seems the standard 
set of XPath2 functions does not include a square root function. I don't feel 
up to writing my own, so I won't procede with the standard deviation function.
--
Charles Knell
cknell(_at_)onebox(_dot_)com - email



-----Original Message-----
From:     Xia Li <xli(_at_)galdosinc(_dot_)com>
Sent:     Wed, 25 Jan 2006 13:46:02 -0800
To:       <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Subject:  RE: [xsl] Creating XPath2 functions:passing a set of nodes, what is 
the signature construction?

You may use occurrence indicator "*" or "+" in <xsl:param>, such as

<xsl:param ... as="xs:double*">

to indicate that a sequence of double is expected.


Lisa


-----Original Message-----
From: cknell(_at_)onebox(_dot_)com [mailto:cknell(_at_)onebox(_dot_)com]
Sent: Wednesday, January 25, 2006 1:26 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Creating XPath2 functions:passing a set of nodes, what is
the signature construction?

I am learning XPath2 using Saxon 8.6. I'd like to create a funtion to
compute the standard deviation of the value of a set of nodes. Is there
some special way to construct the signature of the function when the
argument is a set of nodes as opposed to a single node?

I have written a funtion that takes a single node as an argument of type
xs:double. Is there some special way to state that the function will
take a set of nodes of type xs:double, or do I simply state that the
argument will be of type xs:double?

--
Charles Knell
cknell(_at_)onebox(_dot_)com - email

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--
Cheers,
Dimitre Novatchev
---------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>