Working with Collections

 

Support for collections is available only in Stylus Studio XML Enterprise Edition and Stylus Studio DataDirect XQuery Edition.

In Stylus Studio, a collection is defined by

  • A name
  • Properties that describe the database type, server location, and username and password required to connect to the server
  • The name of the relational table or view whose data you want to make available in your XQuery

Once you create a collection, you can use the collection name as the argument for the collection() function in your XQuery code. You begin creating collections on the General tab of the Scenario Properties dialog box. See How to Create a Collection for more information.

 

Watch it! You can view a video demonstration of this feature by clicking the television icon or by clicking this link: watch the XQuery Collections video.

A complete list of the videos demonstrating Stylus Studio's features is here: http://www.stylusstudio.com/xml_videos.html.

Collection Names

Collection names are created automatically by Stylus Studio. Initially, Stylus Studio uses a default placeholder name, coll1, coll2, and so on. Once you identify the relational table or view on which you wish you base the collection, Stylus Studio replaces the default name with the name of the table or view ( pubs.dbo.authors, for example).

Note

 

Do not change the collection names provided by Stylus Studio.

Using Collections in XQuery Code

The XQuery collection() function is similar to the document() function, but instead of taking as its argument a URL that identifies a document, the collection() function in Stylus Studio takes a collection name - collection(`pubs.dbo.authors'), for example. The collection name must be surrounded with single quotes, and it must be the same as it appears in the Name field of the Defined collections table on the General tab of the Scenario Properties dialog box.

Note that the collection() function is implementation-specific - different vendors have implemented it in different ways. In some implementations, for example, the collection() function takes as its argument a URL that specifies an XML document.

How Collections are Processed

 

Support for DataDirect XQuery is available only in Stylus Studio XML Enterprise Edition and Stylus Studio DataDirect XQuery Edition.

The Stylus Studio built-in processor and the DataDirect XQuery processor process collections differently:

  • DataDirect XQuery converts the XQuery code to SQL statements and executes the SQL directly on the database server, and returns the results to Stylus Studio.
  • Stylus Studio's built-in processor accesses the database table or view on the server, converts it to XML, and returns the XML to the client. The XQuery is run against the XML on the client.

Because it processes XQuery as SQL on the database server, the DataDirect XQuery processor can provide performance superior to that of other XQuery processors.

How to Create a Collection

To create a collection:
1. On the General tab of the XQuery Scenario Properties dialog box, click the new icon ( ) in the Defined collections list box.

A new collection is added to the list box with a default name ( coll1, for example).

2. Click the URL field.

The URL field becomes active. A browse button ( ) appears on the right side of the field.

3. Click the browse button to define the URL for the collection.

The Open dialog box appears with the URL Builder tab selected.

4. Use the URL Builder to define the URL for the relational table or view for which you wish to define the collection.

See Using the URL Builder if you need help with this step.

Alternative: You can type the URL manually if you know the database URL.

5. Optionally, repeat step 1 through step 4 to define additional collections.
6. Click OK.

You can now reference the collection in the collection() functions in your XQuery code.

 
Free Stylus Studio XML Training: