Specifying XSLT Patterns and Expressions

In a stylesheet's xsl:template, xsl:apply-templates, xsl:for-each, and xsl:value-of instructions, you specify patterns or expressions as the values for the match or select attributes. These patterns are XPath expressions. You specify patterns or expressions to

  • Define which nodes a template rule matches.
  • Select lists of source nodes to process.
  • Extract source node contents to generate result nodes.

Depending on the context, an XSLT pattern or expression can mean one of the following:

  • Does this template match the current node?
  • Given the current node, select all matching source nodes.
  • Given the current node, select the first matching source node.
  • Given the current node, do any source nodes match?

Patterns or expressions can match or select any type of node. The XSLT processor can match a pattern to a node based on the existence of the node, the name of the node, or the value of the node. You can combine patterns and expressions with Boolean operators. For detailed information about patterns and expressions, see Chapter 9Writing XPath Expressions.

Examples of Patterns and Expressions

Following are examples of patterns and expressions you can specify in stylesheet instructions:


              xsl:template match = "book/price" 
               

            

Matches any price element that is a child of a book element.


              xsl:template match = "book//award" 
               

            

Matches any award element that is a descendant of a book element.


              xsl:template match = "book [price]" 
               

            

Matches any book element that has a child that is a price element.


              xsl:template match = "book [@price]" 
               

            

Matches any book element that has a price attribute.


              xsl:template match = "book [price=14]" 
               

            

Matches any book element that has a child that is a price element whose value is 14.


              xsl:template match = "book [@price=14]"
               

            

Matches any book element that has a price attribute whose value is 14.


              xsl:apply-templates select = "book"
               

            

Selects all book elements that are children of the current element.


              xsl:apply-templates select = "book/price"
               

            

Selects all price elements that are children of book elements that are children of the current element.


              xsl:apply-templates select = "//book"
               

            

Selects all book elements in the source document.


              xsl:apply-templates select = ".//book"
               

            

Selects all book elements that are descendants of the current element.

MSXML - Microsoft XML Tools

MSXML tools in Stylus Studio feature integrated XML validation, XSLT transformation and XSLT debugging using the Microsoft's COM-based XML processing components: MSXML 3.0, MSXML 4.0 and MSXML 6.0

Learn XSLT and XQuery Profiling

Stylus Studio's Profiler can help you evaluate the performance of your XQuery and XSLT. Automatically generated, customizable, easy-to-read HTML reports provide insight into performance bottlenecks.

ADO to XML

The Stylus Studio ADO to XML data coversion wizard simplifies extracting of relational data into any XML format.

Building DataDirect XML Converter Applications with Stylus Studio

DataDirect XML Converters are Java and .NET components that enable access to any data (flat files, EDI) from your application code. Learn how to deploy XML applications today.

Stylus Most Wanted

 
Free Stylus Studio XML Training:
W3C Member