velocity vs. xslt by jason aller and alvin chao

19
Velocity vs. XSLT Velocity vs. XSLT Alvin Chao – James Madison University Alvin Chao – James Madison University Jason Aller – University of California Davis – Jason Aller – University of California Davis – School of Law School of Law

Upload: hannonhill

Post on 15-May-2015

2.584 views

Category:

Technology


3 download

DESCRIPTION

To end the 2013 User Conference on a fun and competitive note, Alvin Chao and Jason Aller, two Cascade Server veterans, face-off to find out once and for all--which is faster? XSLT or Velocity?

TRANSCRIPT

Page 1: Velocity vs. XSLT by Jason Aller and Alvin Chao

Velocity vs. XSLTVelocity vs. XSLTAlvin Chao – James Madison UniversityAlvin Chao – James Madison University

Jason Aller – University of California Davis – School of LawJason Aller – University of California Davis – School of Law

Page 3: Velocity vs. XSLT by Jason Aller and Alvin Chao

Common Elements - XML Common Elements - XML Traversal MethodsTraversal Methods

XSLT XSLT <xsl:apply-templates <xsl:apply-templates select=“/path/to/node[conditional]”/>select=“/path/to/node[conditional]”/>

<xsl:template match=“node”/><xsl:template match=“node”/>

VelocityVelocity$_XPathTool.selectNodes($contentRoot, “/path/to/node”)$_XPathTool.selectNodes($contentRoot, “/path/to/node”)

$_XPathTool.selectSingleNode($contentRoot, $_XPathTool.selectSingleNode($contentRoot, “/path/to/node”)“/path/to/node”)

$contentRoot.getChild(“path”).getChild(“to”).getChild(“no$contentRoot.getChild(“path”).getChild(“to”).getChild(“node”)de”)

$contentRoot.getChildren()$contentRoot.getChildren()

Page 4: Velocity vs. XSLT by Jason Aller and Alvin Chao

Common Elements - Common Elements - Syntax/FunctionalitySyntax/Functionality

VariablesVariables#set ($myVar = “content value”)#set ($myVar = “content value”)<xsl:variable name=“myVar” select=“content value”><xsl:variable name=“myVar” select=“content value”>

LoopsLoops#foreach ($item in $items) Output Content #end#foreach ($item in $items) Output Content #end<xsl:for-each>Output Content</xsl:for-each><xsl:for-each>Output Content</xsl:for-each>

Conditional StatementsConditional Statements#if ($value == “value”) Output Content #end#if ($value == “value”) Output Content #end<xsl:if test=“$value = ‘value’”> Output Content <xsl:if test=“$value = ‘value’”> Output Content </xsl:if></xsl:if>

DatesDates

Page 5: Velocity vs. XSLT by Jason Aller and Alvin Chao

Velocity BenefitsVelocity Benefits

Based on Java – can leverage Java commands Based on Java – can leverage Java commands like .contains, and .replacelike .contains, and .replace

Doesn’t need Xalan JavaScript extension to format Doesn’t need Xalan JavaScript extension to format dates / Date difference calculation easierdates / Date difference calculation easier

Conditional closing tagsConditional closing tags

Extended Math /Array /real variablesExtended Math /Array /real variables

Ability to break out of loops #breakAbility to break out of loops #break

Script like syntax(php, JavaScript familiar)Script like syntax(php, JavaScript familiar)

Page 6: Velocity vs. XSLT by Jason Aller and Alvin Chao

XSLT BenefitsXSLT Benefits

Widespread use outside of Cascade(wealth of Widespread use outside of Cascade(wealth of tutorials and books available)tutorials and books available)

Easier null checkingEasier null checking

Easy recursive callsEasy recursive calls

Not as many $signs and _sNot as many $signs and _s

Render SpeedRender Speed

Testing code outside of Cascade ServerTesting code outside of Cascade Server

Advanced editors outside of Cascade Server - Advanced editors outside of Cascade Server - OxygenXMLOxygenXML

Page 7: Velocity vs. XSLT by Jason Aller and Alvin Chao

Head to Head Head to Head ComparisonComparison

Attribute Velocity XSLT

Offline Development/Testing

Hard to do this, but you can setup some basic offline testing (Eclipse install of Velocity Tools)

Easy to do this may require some external tools (Oxygen XML, XML Spear)

Familiarity of Language

Script language, like JavaScript, php, etc…

XSLT, may be a learning curve

Flow Logical structured language flow from top to bottom

Template based structure, requires knowledge of the data

Including within formats

Now available in Cascade Server 7.6!

Easily done with imports

Location of Xpath Harder to understand if not familiar with XPATH(Chrome XML View plugin)

Those familiar with XML will know Xpath, Tools like Oxygen XML or XML Spear can help with this

Page 8: Velocity vs. XSLT by Jason Aller and Alvin Chao

Battlefield for TimingsBattlefield for Timings(Server specs)(Server specs)

Physical machine = Dell Optiplex 745 2.4ghz Intel Physical machine = Dell Optiplex 745 2.4ghz Intel Core 2 Duo w /4GB RAM running Windows 2008 Core 2 Duo w /4GB RAM running Windows 2008 Server Server

Cascade 7.6Cascade 7.6

JVM Max heap 1024, Min 768JVM Max heap 1024, Min 768

Cascade Total ram = 742MBCascade Total ram = 742MB

Restarted server, ran all 3 Velocity rounds, then Restarted server, ran all 3 Velocity rounds, then retested for cached timing, restarted again and ran retested for cached timing, restarted again and ran all 3 XSLT rounds then retested for cached timingsall 3 XSLT rounds then retested for cached timings

Page 9: Velocity vs. XSLT by Jason Aller and Alvin Chao

Round 1 – Large Tabular Round 1 – Large Tabular DataData

During this round contestants were asked to take a During this round contestants were asked to take a large set of person data and sort this data into four large set of person data and sort this data into four equal length column listings by first name. equal length column listings by first name.

The dataset is an XML block with 1000 entries. The dataset is an XML block with 1000 entries. Columns are created via YUI Grid .css versus tables Columns are created via YUI Grid .css versus tables to produce valid XHTML and not use tables for to produce valid XHTML and not use tables for layout. Data was generated using the Vulcano tool: layout. Data was generated using the Vulcano tool: http://www.datagenerator.org

Data format: ID, Name, email, phone, date, websiteData format: ID, Name, email, phone, date, website

Page 10: Velocity vs. XSLT by Jason Aller and Alvin Chao

Round 1 TimingsRound 1 Timings

Velocity XSLT

Initial Runtime (ms) 3635ms 5957ms

Cached Runtime 2032ms 3873ms

Page 11: Velocity vs. XSLT by Jason Aller and Alvin Chao

Round 2 – Search Speed – Round 2 – Search Speed – Large DataLarge Data

Contestants were asked to search the works of Contestants were asked to search the works of Shakespeare in XML format for the provided search Shakespeare in XML format for the provided search term of pirate.term of pirate.

Tragically for Alvin it was determined that the bard Tragically for Alvin it was determined that the bard never made mention of Ninjas, while Pirates were never made mention of Ninjas, while Pirates were mentioned in a number of plays.mentioned in a number of plays.

Page 12: Velocity vs. XSLT by Jason Aller and Alvin Chao
Page 13: Velocity vs. XSLT by Jason Aller and Alvin Chao

Round 2 - TimingsRound 2 - Timings

Velocity XSLT

Initial Runtime 8409ms 7644ms

Cached Runtime 2135ms 1928ms

Page 14: Velocity vs. XSLT by Jason Aller and Alvin Chao

Final Round (3) – Tumblr Final Round (3) – Tumblr RSS FeedRSS Feed

Contestants were asked to render an external RSS Contestants were asked to render an external RSS feed from a Tumblr account – feed from a Tumblr account – http://velocityversusxslt.tumlbr.com

Page 15: Velocity vs. XSLT by Jason Aller and Alvin Chao
Page 16: Velocity vs. XSLT by Jason Aller and Alvin Chao

Round 3 TimingsRound 3 Timings

Velocity XSLT

Initial Runtime 350ms 401ms

Cached Runtime 215ms 200ms

Page 17: Velocity vs. XSLT by Jason Aller and Alvin Chao

Velocity ResourcesVelocity Resources

Only 2 book on Velocity: Only 2 book on Velocity: Pro Jakarta Velocity - Pro Jakarta Velocity - http://www.amazon.com/Pro-Jakarta-Velocity-Professional-Expert/dp/159059410X/ref=sr_1_1?ie=UTF8&qid=1378926862&sr=8-1&keywords=velocity+jakartaMatering Apache Velocity Matering Apache Velocity http://www.amazon.com/exec/obidos/ASIN/0471457949/

Velocity User’s Guide: Velocity User’s Guide: http://velocity.apache.org/engine/devel/user-guide.html

Velocity Cookbook on github: Velocity Cookbook on github: https://github.com/hannonhill/Velocity-Cookbook

Presentations:Presentations:2010 User’s Conference - 2010 User’s Conference - http://www.hannonhill.com/news/conference/2010/videos/Velocity-vs-XSLT.html

HH Blog posting - HH Blog posting - http://www.hannonhill.com/news/blog/2011/the-eternal-debate-velocity-or-xslt.htmlVelocity Webinar Velocity Webinar http://www.hannonhill.com/products/demos/velocity-functionality-http://www.hannonhill.com/products/demos/velocity-functionality-overview-webinar-video.htmloverview-webinar-video.html

Page 18: Velocity vs. XSLT by Jason Aller and Alvin Chao

XSLT ResourcesXSLT Resources

Hannon Hill XSLT Workbook on github Hannon Hill XSLT Workbook on github https://github.com/hannonhill/XSLT-Workbookhttps://github.com/hannonhill/XSLT-Workbook

XSLT by Doug Tidwell and published by O’ReillyXSLT by Doug Tidwell and published by O’Reilly

XSLT Cookbook, 2nd Edition by Sal Mangano and XSLT Cookbook, 2nd Edition by Sal Mangano and published by O’Reillypublished by O’Reilly

OxygenXML http://www.oxygenxml.com/OxygenXML http://www.oxygenxml.com/

Page 19: Velocity vs. XSLT by Jason Aller and Alvin Chao

And the winner is…And the winner is…

The clear winner is you, because you get to choose The clear winner is you, because you get to choose which language to use by default, but you retain which language to use by default, but you retain the option to switch when doing so makes sense.the option to switch when doing so makes sense.

But, for those who need a victor – go take our poll – But, for those who need a victor – go take our poll – Velocity or XSLT here: Velocity or XSLT here: