Presentation is loading. Please wait.

Presentation is loading. Please wait.

JSTL, XML and XSLT An introduction to JSP Standard Tag Library and XML/XSLT transformation for Web layout.

Similar presentations


Presentation on theme: "JSTL, XML and XSLT An introduction to JSP Standard Tag Library and XML/XSLT transformation for Web layout."— Presentation transcript:

1 JSTL, XML and XSLT An introduction to JSP Standard Tag Library and XML/XSLT transformation for Web layout

2 JSP Standard Tag Library (JSTL) JSTL is a standardized set of Custom Tags with several implementations http://jakarta.apache.org/taglibs/doc/standard -doc/intro.html http://jakarta.apache.org/taglibs/doc/standard -doc/intro.html JSTL is one Tag Library, but it’s functionally is divided into four parts with its own TLD  Core  XML Processing  I18N  Database Access (SQL)

3 JSTL - Prerequisites In all examples a couple of objects are supposed to be available  customers - A collection of Customer objects  intArray - An array of int's  stringArra - An array of Strings  The Customer Object int key String lastName String firstName Date birthDate Address address  The Address Object String line1 String line2 String city String state String country

4 JSTL Core The Core part of JSTL contain tags the core of JSTL such as iteration, conditional processing and expression language support at the top of your JSPs

5 JSTL Core – General tags is used to declare variables and assign values to them  

6 JSTL Core – General tags is used to print values 

7 JSTL Core – Conditional tags Conditional tags are used for execution control  </c:if and - a switch/case structure  

8 JSTL Core – iteration tags Iteration tags are used to loop over some data structure, often a Collection   

9 JSTL Core – iteration tags   

10 JSTL Core – Import tags There are several tags for importing information from http and ftp (and more)  http://developer.mimer.com Will get the content of the URL and print it  Relative path is ok  Will get the content and store it in the variable resultVar

11 JSTL Core – Import tags The can be combined with to import content from dynamic sites  http://developer.mimer.se/support/support_faq.tml 

12 JSTL Core – Working with URLs The and is used together to construct URLs with proper escaping and rewriting   Gives base.jsp?name=Fredrik%20Alund  Possibly with jsessionid appended

13 JSTL XML JSTL contains several tags for working with XML and XSLT  But first an introduction to XML and XSLT

14 XML XML is an abbreviation for EXtensible Markup Language A markup language like HTML Not used to generate layouts but to describe data No tags are defined in XML, just syntax rules for tags XML uses a DTD (Document Type Definition) to formally describe the data

15 XML XML tags are case sensitive All XML elements must have a closing tag  or All XML elements must be properly nested  is not valid All XML documents must have a root/start tag is not valid, but is

16 XML A XML document is well formed if it conforms to the XML syntax rules A XML document is valid if it is well formed and conform to the rules of a DTD

17 XML Example 1 Fredrik Ålund 32 The first line tells what version of XML is used and what encoding to use

18 XML bigger example Fredrik Ålund 32 Annika Ålund 28 Viktor Ålund 0,5

19 XML attributes XML elements can have attributes Fredrik Ålund Services Helena Larsson Services

20 XML CDATA If the value of an element contain binary data or some other illegal characters, CDATA can be used 

21 Why XML? Describe your data Give you a structure of your data Easier integration of systems The same XML document can be transformed to HTML, WML or VoiceXML to support different clients

22 XSL and XSLT XSL is an abbreviation of eXtensible Stylesheet Language XSLT means XSL Transformation XSL consists of two parts  A method for transforming XML documents A XML document can be transformed into a HTML document  A method for formatting XML documents Elements can be sorted and formatted in different ways XSL files are valid XML documents

23 A XSL example A XSL to transform our employee list to html might look like Name Department

24 XSL templates Stylesheets starts with A template matches a part of a XML document and is evaluted  - matches the root  - matches employees

25 XSL loops over all employees will order the elements on the name element (+ ascending, - descending)

26 XSL and filters Filters can be applied to filter out elements Valid filter operations are  = (equal)  =! (not equal)  &LT& (less than)  &GT& (greater than)

27 XSL returns the value of an element or attribute return the value of the name element for the current employee returns the empid attribute of the employee element

28 XSL IF The conditional statement if is available in XSL 

29 XSL chose... some code...... some code....

30 XSL Text  Used to output text. Useful if the text is not valid XML since it can be combined with

31 Instead of using for-each, we can use Make for each element Put <xsl:apply-template where you want the output of the other template

32 In XSL you have to follow XML syntax rules. This makes it hard to construct HTML form elements and HREFs. can be used to ease this A HREF link in XSL Detail

33 A HTML Form text input field 2 text 1 quantity

34 The same XSL with apply-template Id Name Department

35 JSTL and XML, resumed JSTL has support for navigating XML with XPath and to do XSLT processing is used to specify that the XML part is to be used

36 JSTL XML - parsing A XML structure can be parsed into a XML document that can be navigated foo bar  The XML is parsed into variable a  The value of the element d is selected

37 JSTL XSL Transformation header!

38 JSTL XSL Transformation combined with JSTL Core and Custom Tags Combine the Core import with XSLT to read the XSL file from disk Get XML output from a Custom tag (or Java Bean) Do XSL Transformation

39 JSTL XSL Transformation combined with JSTL Core and Custom Tags


Download ppt "JSTL, XML and XSLT An introduction to JSP Standard Tag Library and XML/XSLT transformation for Web layout."

Similar presentations


Ads by Google