Lab 2 - xml

Embed Size (px)

Citation preview

  • 8/3/2019 Lab 2 - xml

    1/2

    Lab 2

    Part 1 Getting a List of Electric Juicers

    The purpose of this lab is for you to get hands-on experience with using XSL variables and the ifstatement.

    For this lab you are to create an HTML document containing a list of electric juicers. Heres what youroutput should look like:

    This juicer is electric: Champion JuicerThis juicer is electric: Green Power Gold Juice ExtractorThis juicer is electric: Juiceman Jr.This juicer is electric: Omega JuicerThis juicer is electric: Wheateena Wheatgrass Juicer

    That is, for each electric juicer you should output This juicer is electric: followed by the name of thejuicer. Heres how you are to implement this:

    For each juicerGet the name of the juicer and store it into a variableGet the value of the element/attribute which indicates whether it is electric and store it in a variableTest the value of the is electric variable to see if it indicates that the juicer is electric. If it doesindicate that the juicer is electric then

    Output the text This juicer is electric:Output the value of the juicer name variableOutput an HTML break

    Part 2 Interested in Knowing if the Juicers XML document contains these juicers

    This lab will strengthen your understanding and experience with XSL variables. Also, if will give you

    experience with the string function, contains().

    For this lab you are to create a variable which holds a list of all the juicer names (separated by tildas) in theXML document. You are then to determine if this list contains, Champion, Omega, and Ultrex.

    You should output the value of the variable which holds the list of all the juicer names. After that youshould output a line for each juicer that we are interested in. Heres what the output should look like:

    Juicer List: OJ Home Juicer~Champion Juicer~Green Power Gold Juice Extractor~Juiceman Jr.~OmegaJuicer~Wheateena Wheatgrass Juicer- contains Champion- contains Omega- does not contain Ultrex

    Note that there is no tilda after the last juicer in the juicer list. (hint)

    Part 3 Processing Airports in Differing Formats

    There are several different ways to identify airports:

    ICAO code: e.g., BOS is the ICAO code for the Boston airport Lat/Lon: e.g., 74.3N, 123.0W is the lat/lon of the Boston airport

  • 8/3/2019 Lab 2 - xml

    2/2

    In this directory you will find Airports.xml:

    ICAO: bosLatLon: 74.31w, 106.5n

    ICAO: sltICAO: molBogus!LatLon: 43.01w, 116.8n

    The contents of a element is a string with one of the following two forms: ICAO: code orLatLon: valueFor this lab you are to create an HTML document which processes each element. Where thedata is of the form ICAO: code you are to output: ICAO = code, where the data is of the form LatLon:value you are tooutput LatLon = value. Note: you are to convert the code and value data to upper case.

    Heres what the output should look like:

    ICAO = BOSLatLon = 74.31W, 106.5NICAO = SLTICAO = MOLData Error! Data must be formatted as: ICAO: code, or LatLon: valueLatLon = 43.01W, 116.8N

    Part 4 Computing the Average Cost for a Juicer

    For this lab you are to create an HTML document that calculates the average cost for a juicer. Note: tomake things simpler I have modified juicers.xml to contain only the juicer cost in USD.

    Heres what your output should look like:

    Total number of juicers = 6Cost of all juicers = 1696.93The average cost of the juicers = $282.82

    Hint: to format a number to have two digits to the right of the decimal point, along with a dollar sign infront of the number, use the XSL function:

    format-number($avgCost, $#.00)