Download presentation
Presentation is loading. Please wait.
Published byMax Leverett Modified over 9 years ago
1
Advanced XSL Learn how to use advanced XSLT techniques, EXSLT, and Xalan extensions to solve complicated problems. 2008 Cascade Server User’s ConferenceAmy Liu & Brett Goodwin
2
Agenda XSL & XSLT XSLT Warmup Muenchian Method EXSLT Xalan Extensions Velocity Script Formats 09/22/2008Amy Liu & Brett Goodwin
3
XSL & XSLT XSL (eXtensible Stylesheet Language) consists of three parts: – XSLT a language for transforming XML documents – XPath a language for navigating in XML documents – XSL:FO a language for formatting XML documents 09/22/2008Amy Liu & Brett Goodwin
4
http://www.w3schools.com/xsl/xsl_w3celementref.asp XSLT Warmup 09/22/2008Amy Liu & Brett Goodwin
5
Using { } in place of index / index 09/22/2008Amy Liu & Brett Goodwin
6
Problem #1: Categorical Grouping… Example Scenario: You have categorized a set of pages within Cascade Server by utilizing Custom Metadata checkboxes. Now, you would like to create a listing of all the categories along with the list of pages that belong to each category in alphabetical order for display on a “Campus Resources” page. 09/22/2008Amy Liu & Brett Goodwin [01grouping.xml]
7
1 st Attempt: Easy-&-High-Maintenance Method Campus Resources Alumni Current Students Prospective Students Visitors 09/22/2008Amy Liu & Brett Goodwin [02grouping-attempt.xsl]
8
Muenchian Method! Campus Resources 09/22/2008Amy Liu & Brett Goodwin [03muenchian.xsl]
9
Problem #2: Truncating Content… Example Scenario: Your users are now familiar with Cascade and have created several blog posts within the system. You would like to set up some sort of landing page that features the latest blog posts. 09/22/2008Amy Liu & Brett Goodwin [04recent-blogs.xml]
10
1 st Option: List 3 Latest Posts + Full Content 09/22/2008Amy Liu & Brett Goodwin [05full-listing.xsl]
11
2 nd Option: Truncate using Character Count... More... 09/22/2008Amy Liu & Brett Goodwin [06truncate-charcount.xsl]
12
3 rd Option: Truncate after Whole Words … More... … … … … … 09/22/2008Amy Liu & Brett Goodwin [07truncate-wordcount.xsl] 7 Templates 382 Lines 15,167 Characters 7 Templates 382 Lines 15,167 Characters
13
EXSLT Although XSLT lacks features like loops and mutable variables, it is considered Turing-complete, meaning that given sufficient memory, XSLT can perform any calculation that can be performed by a modern computer program. However, this theoretical ability is often impractical.Turing-complete EXSLT is a community initiative to provide extensions to XSLT 1.0 and to partition them into functional groups that can be implemented on an á la carte basis. The EXSLT effort is an open one; anyone who wishes to contribute may do so. http://www.exslt.org/http://www.exslt.org/ Many of the functions in EXSLT are simply shortcuts to equivalent behaviors that can be achieved using XSLT templates. For these functions, the EXSLT authors have provided XSLT templates that may be imported into existing style sheets. This approach offers the most portability, as all XSLT 1.0-compliant processors are able to correctly interpret the template and provide the functionality. 09/22/2008Amy Liu & Brett Goodwin
14
3 rd Option: Truncate using str:tokenize()... More... 09/22/2008Amy Liu & Brett Goodwin [08exslt-tokenizer.xsl] <xsl:stylesheet version=“1.0” xmlns:xsl=“http://www.w3.org/1999/XSL/Transform” xmlns:str=“http://exslt.org/strings” extension-element-prefixes=“str” > Be sure to specify the extension namespace URI & use the extension-element-prefix!
15
Problem #3: Formatting Date & Time… Example Scenario: Now that you have successfully truncated your blog posts, the next item to tackle is to format and display the date/time that is associated with each post. As you probably know, all date values within Cascade are represented in UNIX timestamp format (i.e., 1221165000000 ). 09/22/2008Amy Liu & Brett Goodwin [04recent-blogs.xml]
16
Problem #3: Formatting Date & Time… If you were to attempt this calculation using only native XSLT 1.0, it will probably take about 304 lines or 10,345 characters. The EXSLT Dates-and-Times functions don’t have anything readily available for use with UNIX timestamps. Any other options? 09/22/2008Amy Liu & Brett Goodwin
17
That’s right! Xalan Extensions Xalan is the XSLT processor that Cascade Server utilizes. For those situations where you would like to augment the functionality of XSLT with calls to a procedural language, Xalan-Java supports the creation and use of extension elements and extension functions. The Xalan XSLT processor can invoke almost any method in almost any Java™ class in the classpath. Doing so can improve performance, provide features like trigonometric functions that aren't available in XSLT, perform file I/O, talk to databases and network servers, or implement algorithms that are easy to write in the Java language but hard to write in XSLT. Typically, you'll resort to using Xalan extensions when you can't accomplish what you need using the existing XSLT or EXSL functions and need to write your own custom functions in Javascript or Java. 09/22/2008Amy Liu & Brett Goodwin
18
Xalan Date Converter ,... function convertMonth(date) { var months = new Array(13); months[0] = "January"; months[1] = "February"; months[2] = "March"; months[3] = "April"; months[4] = "May"; months[5] = "June"; months[6] = "July"; months[7] = "August"; months[8] = "September"; months[9] = "October"; months[10] = "November"; months[11] = "December"; var d = new Date(date); // Splits date into components var month = months[d.getMonth()]; return month; } convertDay(date) {…} convertDate(date) {…} convertYear(date) {…} convertTime(date) {…} 09/22/2008Amy Liu & Brett Goodwin [09xalan-convertdate.xsl]
19
Velocity! The Non-XSLT Bonus Velocity is a Java-based template engine that Cascade Server will support starting with version 5.7 It can be used to generate web pages, SQL, PostScript and other output from templates Velocity Template Language (VTL) should have a lower learning curve than XSLT for developers who are already familiar with traditional programming languages Utilizing VTL Formats, in some cases, can simplify the transformation code within Cascade http://velocity.apache.org/engine/devel/user-guide.html 09/22/2008Amy Liu & Brett Goodwin
20
Context Menu Comparison XSLT Format VTL Format #foreach ($child in $contentRoot.children) $child.getChild(“name”).text #end 09/22/2008Amy Liu & Brett Goodwin
21
09/22/2008Amy Liu & Brett Goodwin
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.