XML

Workshop

The Workshop is designed to help you anticipate possible questions, review what you've learned, and begin learning how to put your knowledge into practice.

Quiz

1.

In regard to an XSL processor, what is pattern matching?

2.

Which two XSL technologies would you rely on if you only needed to transform an XML document?

3.

How do you define templates in XSLT style sheets?

4.

What is the difference between patterns and expressions?

Quiz Answers

1.

Pattern matching is the process of using patterns to identify nodes in the source document tree that are to be processed according to XSL styles and transformed into a result tree.

2.

XSLT and XPath are the two XSL technologies that you would rely on if you only needed to transform an XML document. XSL-FO enters the picture only if you planned on formatting a document using XSL.

3.

Templates are defined in XSL style sheets using the xsl:template element, which is primarily a container element for patterns, expressions, and transformation logic.

4.

A pattern identifies a branch of an XML tree for transformation purposes. Expressions are similar to patterns in that they also impact which nodes are selected for transformation. However, unlike patterns, expressions are capable of carrying out processing of their own, such as mathematical calculations, text processing, and conditional tests.

Exercises

1.

Add a new element named im to the Contacts XML document that you saw in this chapter. The im element is used to store the instant messaging address of the contact. Because there are several different instant messaging services available, you should provide an attribute to the im element called service that identifies the instant messaging service (that is, Yahoo, AIM, MSN, and so on).

2.

Modify the Contacts DTD so that it supports the new im element and its service attribute.

3.

Modify the contacts.xsl style sheet to create a template for transforming the new im element. If you really want to make it fancy, include a conditional statement in the template to display a different image for the appropriate instant messaging service. Make sure to also modify the style sheet so that the im template is applied along with the other contact templates.