[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: RE: Creating XPath2 functions:passing a set of nod

Subject: Re: RE: Creating XPath2 functions:passing a set of nodes, what is the signature construction?
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Thu, 26 Jan 2006 16:46:44 +1100
xsl create function
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@xxxxxxxxxx <cknell@xxxxxxxxxx> 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@xxxxxxxxxx - email
>
>
>
> -----Original Message-----
> From:     Xia Li <xli@xxxxxxxxxxxxx>
> Sent:     Wed, 25 Jan 2006 13:46:02 -0800
> To:       <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> Subject:  RE:  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@xxxxxxxxxx [mailto:cknell@xxxxxxxxxx]
> Sent: Wednesday, January 25, 2006 1:26 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  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@xxxxxxxxxx - email
>
>


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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.