Tutorial: Programming with xsl, part one
Zoo tutorials: [ SQL | Java | Linux | XML ]

A Gentle Introduction to xml

Programming with xsl, part one

Question 1: Setting and using a variable.

We create a variable and do some arithmetic on it.
  1. Observe that the sheet calculates the price of the Blur album plus shipping.
  2. Change the sheet so that it calculates the price of Travis plus shipping plus tax - the 10 means add 10% of the album price. The total should be 17.3
    How to divide: See XPath specification, 3.5 Number Expressions

XML


XSL


Question 2: Using data in the xsl attributes

In the previous example the album we were looking for was given in the template. Here the item we want is in the data.
  1. The item required, 'Blur' is still in the style sheet, this is redundant. Change the template so that it matches $r rather than the literal string 'Blur'.
  2. Replace the output so that it shows the id, the price, the quantity and the total value of the order:
    Album: Blur
      price: 12
      quantity: 3
      total: 36
    

XML


XSL


Question 3: Passing parameters

If we have more than one required item we must use a template to find them. Our variables will not work anymore and we will have to use a parameter.

We want to produce output similar to the above - but to include each of the required items:

Album: Blur
  price: 12
  quantity: 3
  total: 36
=============

Album: Travis
  price: 13
  quantity: 1
  total: 13
=============

XML


XSL