Presentation on theme: "XSL November 4, Unit 6. Default sorting is based on text However, we can also sort on numbers, more successfully than last class We use the data-type."— Presentation transcript:
XSL November 4, Unit 6
Default sorting is based on text However, we can also sort on numbers, more successfully than last class We use the data-type attribute to specify if we are sorting on text or numbers –Since text is default only need to add this when we want to sort based on a number In this case, price.
on Multiple Tags What if want to sort by price, then by author? –Or perhaps last name, then by first name? We can use two elements to do this Another example: When using multiple elements, the order is important –First sort by last_name, then sort by first_name –First sort by price, then sort by author
In-Class Example Multiple Sorts Including sorting by numbers
If We can add conditional statements to our XSL file “If the item is out of stock, display the item in red” “If the cost is more than 6.95, show me the book details” “If the book is by C.S. Lewis, show me the books”
Using must have the attribute test Test is the expression we are testing –price > 6.95 –author = “C.S. Lewis” –Inventory < 10 must have a closing tag –The contents of the element should be the rules you want to apply For instance, turn the color red
Using Example Author: Price:$ Inventory: Date: *Will only display books which have a price less than $19.00
Using Example Author: Price:$ Inventory: Date: *Will only display books which are out of stock (inventory = 0)
Using Example Author: Price:$ Inventory: Date: *Will only display books that have C.S. Lewis for an author
Using Example Author: Price:$ Inventory: Date: *Will only display books that are NOT written by C.S. Lewis
Using Example Author: Price:$ Inventory: Inventory: Date: *Will display books that are fewer than 5 in stock in the color red and any books with inventory > 5 in black
In Class Example Using
Operators +, -. *, div : standard math operators = equal, can be used with numbers and text != not equal, used with both numbers and text < strictly less than, use < <= less than or equal to, use <= > strictly greater than, use > >= greater than or equal to, use >= or, “price = 9.50 or price = “9.60” and, “price > 9.00 and price < 10.00” mod, mathematical operator, provides the remainder after division. –e.g. 12 mod 5 = 2, 24 mod 7 = 3.
Choose We could use several if statements to cover every possibility –If inventory is greater than or equal to 100, show in black –If inventory is greater than or equal to 50 and less than 100, show in blue –If inventory is greater than or equal to 5 and less than 50, show in green –If inventory is less than 5 show in red Or we could use “xsl: choose”
is combined with and –Provides “if, else if, else” Basic format: ……….. ……….
Using Choose Author: Price: $ Price:$ Inventory: Date: *If the price is greater than $6.95, display the price in red. Otherwise, display the price normally (in black)
Using Choose, cont. Inventory: Inventory: Inventory: Inventory: *If inventory is >= 100, display in navy. If 50<=inventory<100, display in blue. If 5<=inventory<50, display in green. If inventory<5, display in red.
In Class Example of Choose
Back to Templates So far, we’ve only used a single template in our XSL files But it is possible to have multiple templates, and can make the XSL easier to read We will still have the element but now we can add additional template elements
Making a New Template Let’s add a new template which handles the information about the flowers in our bouquet Again, we use the element This time, though, we use match = “flower” to apply a template to the “flower” tag
Using Additional Templates If we have multiple templates how do we use them? We have to use the We can specify which templates to apply by using the select attribute
In Class Example Adding a template for “flower” Adding a template for “price”
Validating XML Can’t really validate XML like we can validate XHTML We don’t have any rules stating what a element can contain, or what it must contain We have no way of knowing whether or not the tags were used properly But, we can easily check for well- formedness
Well-Formedness XML follows very strict rules –e.g. All tags must be closed –Tags must be properly nested So we can check to be sure that our XML is “well-formed” The basic syntax rules for XML can be verified for our document There are well-formedness checkers online –Your browser will usually also tell you when you’ve got an error
Validating other XML Documents If we have the rules for each tag and its attributes, we can completely validate our XML document –We can validate XHTML because the schema is online We’ve had to specify where the “rules” for XHTML are in our doctype declaration at the top of the page If we have a schema for our document, we should be able to validate it. We can validate SVG and MathML
XHTML and HTML XHTML is an XML schema –Set of XML tags, attributes, and rules –Browsers know how to read this XML schema Older versions of HTML were not based on XML –Similar to XHTML but less strict XHTML is identical to HTML 4.01 –HTML 4.01 was last non-XML-based HTML standard developed –Only change between HTML 4.01 and XHTML 1.0 was that the tags and attributes had to conform to XML rules All tags and attributes are identical
XHTML 1.1 This course covers XHTM 1.0 But, there is a newer version, XHTML 1.1 –Needs the MIME type application/xhtml+xml Proper MIME type for XHTML documents But, some browsers don’t recognize this type (IE especially) This is why we use.html and not.xhtml for our file extensions There is no transitional version of XHTML 1.1 –No deprecated tags or attributes XHTML 1.1 requires the use of the xml:lang attribute instead of the lang attribute we covered earlier –Most browsers again do not support this yet XHTML 2.0 will be the next standard