XSL Unit 6 November 2. XSL –eXtensible Stylesheet Language –Basically a stylesheet for XML documents XSL has three parts: –XSLT –XPath –XSL-FO

  • Published on

  • View

  • Download

Embed Size (px)


<ul><li> Slide 1 </li> <li> XSL Unit 6 November 2 </li> <li> Slide 2 </li> <li> XSL eXtensible Stylesheet Language Basically a stylesheet for XML documents XSL has three parts: XSLT XPath XSL-FO </li> <li> Slide 3 </li> <li> XSLT The most important bit of XSL XSLT allows us to transform an XML document into another XML document For instance, transform an XML document into an XHTML document XSLT relies on using XPath Were going to use it, but not cover it Dont have to go into detail in order to create simple, effective XSL documents </li> <li> Slide 4 </li> <li> XSLT Basics The whole idea behind XSLT is template matching Whats a template? Lets say we have a list of students like what weve done in class: Marky Mark 2001-22222 </li> <li> Slide 5 </li> <li> Templates, cont. We know what one student looks like All students follow the same format: Student: first name last name student number Every single one of the students in our XML document are described in exactly the same manner We can use a template to identify and use the parts of each student </li> <li> Slide 6 </li> <li> Marky Mark 200122222 Selma Blair 200133333 Templates, cont. </li> <li> Slide 7 </li> <li> Creating a New XSL Stylesheet Created with a text editor Saved with file extension .xsl Just like with HTML, we have to put some bits at the top of our XSL file Again, you do not have to have these memorized completely I will provide a blank version online when/if needed </li> <li> Slide 8 </li> <li> Creating an XSL Stylesheet, cont. Or You can use either xls:stylesheet or xls:transform, they are identical </li> <li> Slide 9 </li> <li> Linking the XSL file to the XML file The top of our XML file should read something like this: This is nearly identical to how we link HTML pages to CSS files Again, an empty file will be provided for you if needed But! You do need to know how to link to an XSL file </li> <li> Slide 10 </li> <li> xsl:template xsl:template is an XSL element We are going to use it to apply rules when the template match is found match = / means that well apply the template to the entire XML document This is the next line of our XSL file </li> <li> Slide 11 </li> <li> XSL File, so far . </li> <li> Slide 12 </li> <li> Beginning the Transformation to HTML What do we need for an html file? Maybe a tag? This is what well add next to our XSL file </li> <li> Slide 13 </li> <li> Beginning HTML XML Example . </li> <li> Slide 14 </li> <li> In-Class Example Adding some HTML </li> <li> Slide 15 </li> <li> How do we add data? gives us the value of a certain bit of our xml file Which bit? Well use the select property and the information about our tag This long value for select is based on the structure of our XML document is our root element is contained within is the data were interested in Just like paths for URLs </li> <li> Slide 16 </li> <li> In class Example Adding some data to our html Using more html tags </li> <li> Slide 17 </li> <li> More than Student? We can get the data for a single student, but what about our list of 3 students? Or 300 for that matter? We dont want to cut and paste for every student What if the number of students changes? We can use the element to loop through each of our students Can use it to look through any sets of data nodes (think items with (+) marks) </li> <li> Slide 18 </li> <li> Using requires the use of the select attribute But what to use? Depends on the repeat of the data In the case of having a list of students select = studentList/student Basically you can read this as for each student, apply these rules below </li> <li> Slide 19 </li> <li> In Class Example Adding for-each to loop through the students in the XML document Reversing last and first name Changing the format of the data </li> <li> Slide 20 </li> <li> Sorting the Data We can sort the data in our XML files For instance, we can alphabetize our student list Even if its not alphabetical in the XML file, the HTML output will have the items in alphabetical order We are going to use the element </li> <li> Slide 21 </li> <li> Using We can specify what we are sorting on First name? Last name? Default is to sort ascending (A, BZ) But we can reverse it by using the order property: </li> <li> Slide 22 </li> <li> In Class Example Sorting the student list ascending and descending Using both first and last name Another XML file with products </li> <li> Slide 23 </li> <li> Questions? </li> </ul>


View more >