From: Dave F. <dav...@gm...> - 2011-04-16 05:46:38
|
Aw, son of a gun! So, with the item() parameter, I can use typeswitch to delegate to various sub-functions as I see fit. Basically, what I need is a base function that handles the grunt work, which I already have. With an ID (integer) parameter I can construct a string that points to an XML file via an XMLDB URL. Allister's suggestion makes the most sense since I can construct a sort of "degenerate" function that all variances will call upon. As such, I have my solution. Tomorrow will be glorious! On Sat, Apr 16, 2011 at 12:13 AM, Alister Pillow <gsp...@gm...>wrote: > Hi Dave, > Yes - it's a language issue: > [Definition: Function signatures. This component defines the set of > functions that are available to be called from within an expression. Each > function is uniquely identified by its expanded QName and its arity (number > of parameters).] > > So Dimitry's suggestion (to edit the source) is possible, but it would be > breaking the rules. > > An alternative is to define one function that takes any parameter, and use > the typeswitch expression to deal with them. > declare function local:my-function ($param as item()) { > typeswitch($param) > case $a as xs:integer return $a + 1 > case $a as xs:string return upper-case($a) > default return "unknown" > }; > > I hope that is useful. > > Alister. > > > On 16/04/2011, at 2:03 PM, Dave Finton wrote: > > > I'd like to define a function (or two) where they can be called one of > the following ways: > > > > dave-module:my-function ($my-string as xs:string) > > dave-module:my-function ($my-integer as xs:integer) > > > > The problem is that eXist (or perhaps it's the XQuery language in > general) doesn't like this, as it seems unless I define functions based on > the *number* of parameters as opposed to the *type*, I get an error. No > matter how I try, the interpreter seems to want one over the other. My > question: Is there a way to not have to do any obvious workarounds to get > this to work? Right now all I can do is to define the functions as follows, > which does work: > > > > dave-module:my-function-s ($my-string as xs:string) > > dave-module:my-function ($my-integer as xs:integer) > > > > (note the "-s" at the end of the function name to denote the fact that it > is expecting a string) > > > > I'm using eXist 1.5 trunk (I forget the revision number off the top of my > head). My apologies if this is a neophyte question, but after a day of > rummaging through the documentation, I'm kind of at a loss. > > -- > > David Finton > > > ------------------------------------------------------------------------------ > > Benefiting from Server Virtualization: Beyond Initial Workload > > Consolidation -- Increasing the use of server virtualization is a top > > priority.Virtualization can reduce costs, simplify management, and > improve > > application availability and disaster protection. Learn more about > boosting > > the value of server virtualization. > http://p.sf.net/sfu/vmware-sfdev2dev_______________________________________________ > > Exist-open mailing list > > Exi...@li... > > https://lists.sourceforge.net/lists/listinfo/exist-open > > -- David Finton |