Function Blocks

Stylus Studio supports standard functions defined by the W3C and any user-defined functions you might have created. This section describes how to work with function blocks in Stylus Studio and covers the following topics:

Standard Function Block Types

Stylus Studio provides graphic support for the following types of XQuery functions:

  • Accessor
  • Aggregate
  • Boolean
  • Date time
  • Error
  • Node
  • Notation
  • Number
  • QName
  • Sequence
  • Sequence generator
  • String

If a standard function does not provide the functionality you need, create a user-defined function. See User-Defined Functions.

Creating a Function Block

The procedure for creating standard and user-defined function blocks varies slightly:

To create a standard function block:
1. Right-click on the mapper canvas.
2. Select New > Function Block from the shortcut menu. Available functions are displayed in submenu categories.
To create a user-defined function block:
1. Right-click on the mapper canvas.
2. Select New > User Functions from the shortcut menu.

Any user-defined functions defined in the XQuery source are displayed in a sublist.

See User-Defined Functions to learn more about creating user-defined functions in Stylus Studio.

Parts of a Function Block

Function blocks are drawn as a purple block with an italic "f" at its center, and connectors, called ports, placed along the block's border. Input ports (none or more based on the function), the Flow port at the top, and the Return port on the right:

Figure 249. Function Block

Input ports

Input ports are on the left side of the function block. The number and definition of input ports varies from function to function. To specify a value for an input port, drag a source document element or attribute to the port and release it.

Flow port

Flow ports, on the top of function blocks, are the same for FLWOR, function, and IF blocks. See Flow port.

Return port

The Return port is on the right side of the function block. You use the Return port to map the function result directly to a target structure element or attribute, or to a FLWOR, IF, condition, or another function block.

User-Defined Functions

You can define your own functions in XQuery, such as the following:


              define function total-price( $i as element) as xs:decimal
               

              {
               

                let $subtotals := for $s in $i return $s/quantity * $s/USPrice
               

                return sum( $subtotals )
               

              }
               

            

This particular user-defined function, which takes an element as its argument and returns a sum of the prices, might be used as follows (shown in italics):


              <Catalog>
               

              	{
               

              		for $book in /books/book
               

              		return
               

              		<Book>
               
			<Price>
               

              				{total-price($book/@bookid)}
               
			</Price>
               

              		</Book>
               

              	}
               

              </Catalog>
               

            

When you create a user-defined function, Stylus Studio adds it to the New > User Functions shortcut menu available when you right-click the mapper canvas.

Figure 250. User-Defined Functions

This makes it easy to reuse a user-defined function on the Mapper tab once it has been defined in the XQuery source.

concat Function Blocks

There are three types of concatenation ( concat) functions for strings:

  • concat() as string allows you to specify a literal value that you might wish to concatenate to some other value in your XQuery.

    Figure 251. concat() as string
  • concat($op1 as string?) as string allows you to specify a variable that you might wish to concatenate to some other value.

    Figure 252. concatn($op1 as string?)
  • concat($op1 as string?, $op2 as string?, ...) as string allows you to concatenate two or more variables.

    Figure 253. concat($op1 as string?, $op2 as string?, ...)
  • Note that only the first two input ports are associated with variables ( $op1 as string? and $op2 as string?). When you map a value to the third input port ( ...), Stylus Studio automatically adds a fourth input port to allow you concatenate a fourth value. This behavior is repeated for each additional string you define.

Energy Companies That Use Stylus Studio

Forget red bull! Many energy companies are using Stylus Studio 2006 for their quick pick me up during the work day. Come see which energy companies are getting the boost they need with Stylus Studio!

Automotive Companies That Use Stylus Studio

Top automotive companies get their wheels spinning with Stylus Studio 2006. Come see which companies put Stylus Studio in their drivers seat today!

XML Operations

Using XML Pipeline it's easy to visually specify a series of XML operations to apply on your XML data, including parsing, validating, converting and transforming, according to the needs of your business application.

XML Differencing

Stylus Studio's integrated XML Differencing tool visually computes and analyzes any changes made to files or folders in a highly configurable, XML-aware fashion. Display text or tree views, with changes displayed in a merged view or side-by-side!

Stylus Most Wanted

 
Free Stylus Studio XML Training:
W3C Member