|
Home >Online Product Documentation >Table of Contents >Creating a User-Defined Function Creating a User-Defined FunctionYou can create a user-defined function by typing its definition in the XQuery Source tab, but it can be easier to have Stylus Studio create a user-defined function for you. You do this by selecting existing code and refactoring that code as a user-defined function. Any complete block of code can be used for refactoring. Examples include XML fragments and FLWOR expressions. When you create a user-defined function using the refactoring feature, Stylus Studio
l Creates a function declaration for the newly created user-defined function
l Replaces the code you selected with a function call to the user-defined function
To create a user-defined function:
1. In the XQuery Source tab or the Text pane of the XQuery Mapper tab, select the fragment you want to use to create your user-defined function.
Consider the following example, which uses the createFullOrder.xquery that is part of the pipelines example project installed with Stylus Studio.
2. Drag select the code you want to use to create the user-defined function.
3. Right-click to display the short-cut menu and choose Refactor as Function:
Stylus Studio displays the New Function dialog box.
A default name, udFunctionN, where ud stands for "user-defined" and N is a unique number, appears in the Enter the name for the new function field.
4. Click OK to use the default name, or type any valid name you choose and then click OK.
The function declaration and a call to that function are added to your XQuery code. For example:
|