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 statement or similar construct. In XSLT, you can use the xsl:choose element to make choices when more than two options are involved.

Data stored in an XML document may be ordered according to some arbitrary criteria, perhaps as simple as the sequence in which elements and their content were first entered into the data store. For some purposes, you likely will want to use data in various orders—including alphabetical order, date order, and by value of element content or attribute value. XSLT possesses the xsl:sort element to provide sorting functionality. First, let’s look more closely at conditional processing and how it is supported in XSLT.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset