Specifying Attributes in Queries

To specify an attribute name in a query, precede the attribute name with an at sign (@). The XPath processor treats elements and attributes in the same way wherever possible. For example:

//@style
               

            

This query returns the style attributes associated with the magazine, the three books, and the my:book element. That is, it returns all the style attributes in the document. It does not return the elements that contain the attributes.

Following is another query that includes an attribute:

/bookstore/book/@style
               

            

This query returns the three style attributes for the three book elements.

The following query returns the style attribute of the context node:

@style 
               

            

If the context node does not have a style attribute, the result set is empty.

The next query returns the exchange attribute on price elements in the current context:

price/@exchange 
               

            

Following is an example that is not valid because attributes cannot have subelements:

price/@exchange/total 
               

            

Following is a query that finds the style attribute for all book elements in the document:

//book/@style 
               

            

Restrictions

Attributes cannot contain subelements. Consequently, you cannot apply a path operator to an attribute. If you try to, you receive a syntax error.

Attributes are inherently unordered. Consequently, you cannot apply a position number to an attribute. If you try to, you receive a syntax error.

Attributes and Wildcards

You can use an at sign (@) and asterisk (*) together to retrieve a collection of attributes. For example, the following query finds all attributes in the current context:

@* 
               

            

XML Schema Mapping

Stylus Studio includes a visual XML Schema-to-XML Schema mapping tool that allows you to easily implement sophisticated XML data mappings involving multiple data sources and customized data processing using either XSLT or XQuery code.

Convert HTML to XML

Convert HTML-to-XML with a Document Wizard that quickly converts any HTML to standard XML with the click of a button! To get started, just click File, Document Wizards on the Stylus Studio menu.

EDI Mapping

To transform EDI to XML, whether for X12 or EDIFACT, Stylus Studio provides the design tools and run-time support. EDIFACT, X12 and custom EDI formats can be translated, validated and mapped using the EDI Mapping adapter technology described here.

Business Solutions & Outsourcing

Business Solutions & Outsourcing companies know the best solutions. That's why they choose Stylus Studio to enhance their business productivity. See which companies are already using Stylus Studio 2006 to take care of their own business!

Stylus Most Wanted

 
Free Stylus Studio XML Training:
W3C Member