Mulberry Technologies, Inc. logo

Am I ready for Mulberry's Advanced Document Processing with XSLT 2.0 course?

Mulberry's Fundamentals of XSLT and XPath 3-day course is intended for beginners, but some of our happiest alumni are those who have taken it as a refresher course. Since it focuses on the fundamentals of the XSLT processing model, introduces and explains relevant technical terminology, and presents comprehensive coverage of XPath 1.0 -- all of which can be mysterious to the self-taught or casual XSLT user -- our introductory course offers a strong foundation in XSLT even to programmers who have prior experience.

But many prospective students will not have taken our introduction, and may nevertheless be well prepared for the advanced course. The problem is knowing whether you are in this category, or whether you need a more systematic introductory treatment before you can benefit from (and contribute to) an advanced hands-on treatment.

In order to help you assess whether you are ready for the advanced class, please review the concepts described below (which are covered in the introductory class). Then please take a few minutes to attempt and grade yourself (informally) on the quiz questions offered below. If you can't answer these questions, or if you find the concepts to be novel and disconcerting, please consider taking our Fundamentals of XSLT and XPath before you sign up for the Advanced class.

Core prerequisites for the Advanced XSLT course

All students in our advanced class will be expected to have the following:

A self-assessment quiz

If you answer these questions correctly without cheating, and if you understand (and concur with) the explanations given of the answers here, you are likely ready to take our Advanced Document Proceesing with XSLT 2.0 course. If you do not, you may want to consider our Fundamentals of XSLT and XPath course instead.

Since some of the questions and answers include code, you ay want to print this quiz, mark your answers on the page, and then return and check them against the web page.

Question 1. Translate the following XPath expression into natural language:

title[1]/following-sibling::*

1a. The following siblings of the context node, if the context node is a title.

expand Click here if this is the best answer.

1b. The first title child (of the context node) with a following sibling.

expand Click here if this is the best answer.

1c. Every title child that contains the character "1" and has a following sibling.

expand Click here if this is the best answer.

1d. Child elements (of the context node) following the first title (child element).

expand Click here if this is the best answer.

Question 2.. Here's a little XML document:

<room>
  <table>t99</table>
  <chair type="chippendale">Ch4</chair>
  <chair type="chippendale">Ch33</chair>
  <chair type="chippendale">Ch1</chair>
  <chair type="queeneanne">QA45</chair>
</room>

Which of these results would you expect from processing it with a stylesheet containing (only) these three templates:

<xsl:template match="room">
  <ul>
    <xsl:apply-templates/>
  </ul>
</xsl:template>

<xsl:template match="chair">
  <li>
    <xsl:apply-templates/>
  </li>
</xsl:template>

<xsl:template match="table | chair[@type='queeneanne']"/>

2a.

<ul>
  <li>Ch4</li>
  <li>Ch33</li>
  <li>Ch1</li>
</ul>
expand Click here if this is the best answer.

2b.

<room>
  <ul>
    <table>t99</table>
    <chair>
      <li>Ch4</li>
    </chair>
    <chair>
      <li>Ch33</li>
    </chair>
    <chair>
      <li>Ch1</li>
    </chair>
    <chair type="queeneanne">
      <li>QA45</li>
    </chair>
  </ul>
</room>
expand Click here if this is the best answer.

2c.

<ul>
  <table>t99</table>
  <li>Ch4</li>
  <li>Ch33</li>
  <li>Ch1</li>
  <chair type="queeneanne">QA45</chair>
</ul>
expand Click here if this is the best answer.

2d.

<ul>
  t99
  <li>Ch4</li>
  <li>Ch33</li>
  <li>Ch1</li>
  QA45
</ul>
expand Click here if this is the best answer.

Question 3. What results do you expect to see from applying a stylesheet containing no templates to the same source document?

<room>
  <table>t99</table>
  <chair type="chippendale">Ch4</chair>
  <chair type="chippendale">Ch33</chair>
  <chair type="chippendale">Ch1</chair>
  <chair type="queeneanne">QA45</chair>
</room>

3a.

<room>
  <table>t99</table>
  <chair type="chippendale">Ch4</chair>
  <chair type="chippendale">Ch33</chair>
  <chair type="chippendale">Ch1</chair>
  <chair type="queeneanne">QA45</chair>
</room>
expand Click here if this is the best answer.

3b.

t99Ch4Ch33Ch1QA45
expand Click here if this is the best answer.

3c.

  t99
  Ch4
  Ch33
  Ch1
  QA45
expand Click here if this is the best answer.

3d.

t99 Ch4 Ch33 Ch1 QA45
expand Click here if this is the best answer.

Question 4. Which of these is what XSLT developers call an "identity template"? (And what is it used for?)

4a.

<xsl:template match="* | /">
  <xsl:apply-templates/>
</xsl:template>
expand Click here if this is the best answer.

4b.

<xsl:template match="*">
  <xsl:element name="{name()}">
    <xsl:apply-templates/>
  </xsl:element>
</xsl:template>
expand Click here if this is the best answer.

4c.

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>
expand Click here if this is the best answer.

4d.

<xsl:template name="identity">
  <element name="{name()}">
    <xsl:apply-templates select="@*|node()"/>
  </element>
</xsl:template>
expand Click here if this is the best answer.

Question 5. Which of the following is the best rewrite of this template?

<xsl:template match="div">
  <xsl:choose>
    <xsl:when test="attribute::type='part'">
      <sec>
        <xsl:apply-templates/>
      </sec>
    </xsl:when>
    <xsl:when test="attribute::type='chapter'">
      <subsec>
        <xsl:apply-templates/>
      </subsec>
    </xsl:when>
    <xsl:when test="attribute::type='section'">
      <subsec2>
        <xsl:apply-templates/>
      </subsec2>
    </xsl:when>
    <xsl:otherwise>
      <sec>
        <xsl:apply-templates/>
      </sec>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

5a.

<xsl:template match="div">
  <xsl:choose>
    <xsl:when test="@type=part">
      <sec>
        <xsl:apply-templates/>
      </sec>
    </xsl:when>
    <xsl:when test="@type=chapter">
      <subsec>
        <xsl:apply-templates/>
      </subsec>
    </xsl:when>
    <xsl:when test="@type=section">
      <subsec2>
        <xsl:apply-templates/>
      </subsec2>
    </xsl:when>
    <xsl:otherwise>
      <sec>
        <xsl:apply-templates/>
      </sec>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>
expand Click here if this is the best answer.

5b.

<xsl:template match="div">
  <sec>
    <xsl:apply-templates/>
  </sec>
</xsl:template>

<xsl:template match="div[@type='chapter']">
  <subsec>
    <xsl:apply-templates/>
  </subsec>
</xsl:template>

<xsl:template match="div[@type='section']">
  <subsec2>
    <xsl:apply-templates/>
  </subsec2>
</xsl:template>
expand Click here if this is the best answer.

5c.

<xsl:template match="div[not(@type='chapter'|@type='section')]">
  <sec>
    <xsl:apply-templates/>
  </sec>
</xsl:template>

<xsl:template match="div[@type='chapter']">
  <subsec>
    <xsl:apply-templates/>
  </subsec>
</xsl:template>

<xsl:template match="div[@type='section']">
  <subsec2>
    <xsl:apply-templates/>
  </subsec2>
</xsl:template>
expand Click here if this is the best answer.

5d.

<xsl:template match="div">
  <xsl:when test="@type='chapter'">
    <subsec>
      <xsl:apply-templates/>
    </subsec>
  </xsl:when>
  <xsl:when test="@type='section'">
    <subsec2>
      <xsl:apply-templates/>
    </subsec2>
  </xsl:when>
  <xsl:otherwise>
    <sec>
      <xsl:apply-templates/>
    </sec>
  </xsl:otherwise>
</xsl:template>
expand Click here if this is the best answer.

XSLT 1.0 and XSLT 2.0

Finally, please note that Mulberry's Advanced XSLT class, unlike the 3-day introduction, is a course in XSLT 2.0. If you are restricted to using XSLT 1.0 and need instruction in it beyond the content covered by our introduction, Mulberry offers customized training and consulting on applying XSLT and related technologies. Please let us know what you need.