Conditional Processing and Sorting Data

As you saw in Chapter 11, “XSLT—Transforming XML Structure,” an XML document may not be in the precise form that you want to work with. In addition to providing tools to copy or to create new elements and attributes, XSLT provides tools to process data according to criteria that you set. Among the important functionality that XSLT provides is the capability to process elements (or not) based on criteria that you define or to sort data according to criteria that you specify.

Many programming languages have if ... then ... else statements or similar constructs. In XSLT, you can use the xsl:if element for similar purposes. For more complicated choices, conventional programming languages have a switch/case ...

Get Sams Teach Yourself XML in 10 Minutes now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.