Mapping Source and Target Document Nodes

You map a source document node to a target structure node using drag and drop to create a link between the two nodes. Stylus Studio composes XQuery code based on these maps.

This section covers the following topics:

Preserving Mapper Layout

As you add function blocks to the XQuery mapper, Stylus Studio places them in the center of the mapper canvas. You can change the default placement of function blocks by dragging and drag and dropping them where you like. Stylus Studio preserves the placement you select within and across sessions (as you toggle between the mapper and the XQuery Source tab, for example).

As you use the splitter in the XQuery mapper to widen the source and target document panes, the size of the mapper canvas is reduced. The Fit in Mapper Canvas button ( ), located at the top of the XQuery mapper, redraws the diagram in whatever space is currently available to the mapper canvas. This feature is also available from the mapper short-cut menu (right-click anywhere on the mapper canvas to display the short-cut menu).

Left and Right Mouse Buttons Explained

You can use either the left or the right mouse button to perform the drag and drop operation used to create source-target mappings in XQuery.

If you use the left mouse button to perform the drag operation, the link always maps the source node to the target node, one-to-one, without making any changes to the target structure.

If you use the right mouse button, Stylus Studio displays a shortcut menu that provides you with alternatives for modifying the target structure.

Using this menu, you can easily perform many operations. For example, you can

How to Map Nodes

To map nodes:
1. Using either the left or right mouse button, drag the source document element or attribute to the appropriate node on the target structure.
2. When the pointer is on the appropriate target element, release the mouse button to complete the link.

Link Lines Explained

Stylus Studio draws lines for the maps you create from source document nodes to target structure nodes. Different line styles are used to convey information about the XQuery represented by the node mapping. There are three line styles:

The sample files used to illustrate these styles are books.xml and catalog.xml, from the Stylus Studio examples\simpleMappings directory.

Thin line

A thin line indicates that the XQuery code generated by Stylus Studio copies content from the source node to the target node. Such a line is created when you map one element or attribute to another using the left mouse button, or any of the following choices on the map shortcut menu:

In addition, the structure required to navigate to the node is also generated if it does not already exist in the XQuery. For example, consider the map between the title element in books.xml and the Title element in catalog.xml:

This map results in Stylus Studio composing the following XQuery code:

<Catalog> 
	<Book> 
		<Title> 
			{/books/book/title/text()} 
		</Title> 
	</Book> 
</Catalog> 

The content is expressed as {/books/book/title/text(), and this statement is preceded by the structure needed to locate the title element content.

Dashed line

A dashed line indicates that only structure code is being generated. Such a line is created when you use a FLWOR or IF block. For example, consider the map between the book and Book repeating elements:

A map involving a FLWOR block results in the following code:

<Catalog> 
	{ 
		for $book in /books/book 
		return 
		<Book> 
			<Title/> 
		</Book> 
	} 
</Catalog> 

Notice that the FOR loop returns only structure (shown in italics), not content. To add content, we could also map the title element to the Title element, which results in the following:

<Catalog> 
	{ 
		for $book in /books/book 
		return 
		<Book> 
			<Title> 
				{$book/title/text()} 
			</Title> 
		</Book> 
	} 
</Catalog> 

Of course, the FLWOR block can be used to define much more complex expressions, involving maps from source document nodes to its WHERE and ORDER BY ports, for example.

Thick line

A thick line indicates that the XQuery code generated by Stylus Studio replicates the complete structure and content of the source document node in the target. Such a map is created when you use the Copy Node choice on the link shortcut menu. Consider the following map - the bookid attribute on the source was copied to the target as a child of the Book repeating element:

For this type of map, Stylus Studio creates the XQuery code required to duplicate the source structure and content in the target, as shown in the following sample:

<Catalog> 
	<Book> 
		{/books/book/@bookid}</Book> 
</Catalog> 

Notice that the bookid attribute is displayed in gray in the target structure pane. This indicates that you cannot edit it.

Removing Source-Target Map

To remove a map from a source document node to a target element node:
1. Select the line that represents the map you want to delete.
 
Free Stylus Studio XML Training: