Creating an XQuery Scenario

An XQuery scenario is a group of settings that you can associate with an XQuery. Stylus Studio uses scenario settings each time you preview the XQuery result. For example, if you specify an XML source document as a scenario setting, Stylus Studio runs the XQuery against that document when you click the Preview Result button ( ).

You can create multiple scenarios that use the same XQuery, and choose different settings for each. This flexibility can aid the XQuery development process as it enables you to easily test different applications of the XQuery before you put it online.

This section covers the following topics:

Overview of Scenario Features

This section describes the main features of XQuery scenarios. It covers the following topics:

Specifying XML Source Documents

The main benefit of the XQuery scenario feature is that it lets you specify the XML document against which you want to run your XQuery. By default, Stylus Studio uses the first source document you add using the XQuery mapper as the XML source document for the scenario. You can specify the XML source document setting on the General tab of the Scenario Properties dialog box.

i

Figure 294. XQuery General Scenario Properties

For more information

See Source Documents to learn more about the process of selecting and working with XQuery source documents in XQuery mapper.

Selecting an XQuery Processor

You use the Processors tab of the Scenario Properties dialog box to specify the processor you want to use to process your XQuery code.

Figure 295. XQuery Scenario Processor Properties

You can use

  • One of several processors that support XQuery debugging and backmapping, including Stylus Studio's built-in XQuery processor
  • An external processor, configured to send messages to Stylus Studio
  • Mark Logic's XQuery processor, for use with documents stored in the Mark Logic Content Interaction Server
  • A custom processor
Using the Mark Logic Processor

If you want to use the Mark Logic processor:

1. Click Mark Logic.

The Server Settings button becomes active.

2. Click the Server Settings button.

The Mark Logic Server Settings dialog box appears.

Figure 296. Mark Logic Server Settings Dialog Box

3. Enter the host, port, username, and password information for the server on which the Mark Logic Content Interaction Server is running.
4. Click OK.

Setting Values for External Variables

The Parameter Values tab of the Scenario Properties dialog box displays any external variables you have defined in the XQuery source. You can specify the parameter value you want to use for any external variables when you run the scenario. For example, imagine your XQuery code contains the following:

define variable $unit_cost external
               

            

This variable is displayed on the Parameters tab as follows:

Figure 297. XQuery Scenario Parameters

When you run the scenario, you can specify the parameter value you want to use by double-clicking the Expression field and typing a value. Valid values are XPath expressions and must be entered using single or double quotes.

Performance Metrics Reporting

See Enabling the Profiler to learn more about the different ways in which Stylus Studio can provide you with XQuery performance metrics.

How to Create a Scenario

To create a scenario:
1. In the XQuery editor toolbar, click .

Alternative: Select Create Scenario from the scenario drop-down list at the top of the editor window.

Stylus Studio displays the Scenario Properties dialog box.

2. In the Scenario name: field, type the name of the new scenario.
3. In the Source XML URL (optional): field, type the name of the XML file to which you want to apply the XQuery, or click Browse to navigate to an XML file and select it.

Note

 

If the first document you added to the XQuery is an XML document, Stylus Studio uses that document as the XML source for the scenario and displays it in this field.

4. In the Output URL field, optionally type or select the name of the result document you want the XQuery document to generate. If you specify the name of a file that does not exist, Stylus Studio creates it when you preview the XQuery.
5. If you want Stylus Studio to Store paths relative to XQuery document path, ensure that this option is checked.
6. If you check Preview result in an external application, Stylus Studio displays the result Internet Explorer. In addition, Stylus Studio always displays XQuery results in the Preview window.
7. If you want to specify values for XQuery parameters, click the Parameter Values tab. Click the Variable Name field for the parameter - Stylus Studio places the text cursor in the Expression field, allowing you to type a value for the parameter.
8. If you want Stylus Studio to capture performance metrics, enable the XQuery Profiler on the Profiling Options tab. See Profiling XQuery Documents.
9. To define another scenario, click Add and enter the information for that scenario. You can also copy scenarios. See How to Clone a Scenario.
10. Click OK.

If you start to create a scenario and then change your mind, click Delete and then OK.

How to Run a Scenario

To run a scenario:
1. Select a scenario from the scenario drop-down list at the top of the editor window.

Alternative:

a. In the XQuery editor toolbar, click .

Stylus Studio displays the Scenario Properties dialog box.

b. On the General tab, select the scenario you want to run from the Existing Scenarios list.
c. Click OK.
2. Click the Preview Result button ( ).

How to Clone a Scenario

When you clone a scenario, Stylus Studio creates a copy of the scenario except for the scenario name. This allows you to make changes to one scenario and then run both to compare the results.

To clone a scenario:
1. Display the XQuery in the scenario you want to clone.
2. In the XQuery editor toolbar, click to display the Scenario Properties dialog box.
3. In the Scenario Properties dialog box, in the Existing preview scenarios field, click the name of the scenario you want to clone.
4. Click Clone.
5. In the Scenario name field, type the name of the new scenario.
6. Change any other scenario properties you want to change. See How to Create a Scenario.
7. Click OK.

If you change your mind and do not want to create the clone, click Delete and then OK.

 
Free Stylus Studio XML Training: