|
Home >Online Product Documentation >Table of Contents >Example ExampleConsider the books.xml file that is installed with the simpleMappings project installed with Stylus Studio. This is what the books.xml file looks like when displayed using the XML Editor's Grid tab. In this example, we'll use a zipped copy of books.xml, books.zip, as the source for a simple XQuery that will return information for all books with some variant of "begin" in their title. We start by creating a new XQuery, which we save as zip_source.xquery. To start the mapping process, we click the Mapper tab. Next, we can select the source and target documents required for our XQuery. When you click the Add Source Document button, Stylus Studio displays the Open dialog box. You can use the Files of drop-down menu to filter the types of files. As you can see, Stylus Studio supports numerous document types based on the Zip Archive format. We'll choose the books.zip file we created previously. (Of course, you can drag source and target files from your file systems and drop them directly on the source and target document panes.) Once the .zip file is added as a source, we can navigate it just as we would any other XML file: Next, we add catalog.xml from the simpleMappings project as our target document. We'll use a FLWOR expression to iterate over the source XML. Mapping the contents of a zipped XML file is just like mapping plain XML - just expand the tree to locate the node you want to map, drag, and drop. In this case, we drag the book repeating element from the zipped books.xml and drop it on the Book repeating element in the target document. Stylus Studio creates the FLWOR block automatically when mapping one repeating element to another.
Next, we create a contains function to select only those books that have the string "Begin" as part of their title. Right-click the mapper canvas and choose Function Block > Functions on Strings > contains/2 from the short-cut menu. Stylus Studio adds the contains function to the Mapper canvas. To specify the contains function, we map the title element to the first input port on the contains function block ($arg1 as xs:string?). To specify the partial string we want to search for, we double-click the second input port, and enter Finally, we map the title element in the zipped source XML to the Title element in the target XML. When we preview the XQuery, we can see that Stylus Studio was able to read the zipped XML document and provide the titles for all the books that contain some portion of the string "Begin." |