Velocity vs. XSLT by Jason Aller and Alvin Chao

3,557 views
3,303 views

Published on

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?

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,557
On SlideShare
0
From Embeds
0
Number of Embeds
29
Actions
Shares
0
Downloads
20
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Velocity vs. XSLT by Jason Aller and Alvin Chao

  1. 1. Velocity vs. XSLTVelocity vs. XSLT Alvin 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
  2. 2. The Eternal debate…The Eternal debate… http://www.hannonhill.com /news/blog/2011/the-eternal-debate-velocity-or-xslt.html
  3. 3. Common Elements - XMLCommon Elements - XML Traversal MethodsTraversal Methods XSLTXSLT <xsl:apply-templates select=“/path/to/node[conditional]”/><xsl:apply-templates 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(“node”$contentRoot.getChild(“path”).getChild(“to”).getChild(“node” )) $contentRoot.getChildren()$contentRoot.getChildren()
  4. 4. Common Elements -Common Elements - Syntax/FunctionalitySyntax/Functionality VariablesVariables #set ($myVar = “content value”)#set ($myVar = “content value”) <xsl:variable name=“<xsl:variable name=“myVarmyVar”” select=select=““content valuecontent 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><xsl:if test=“$value = ‘value’”> Output Content </xsl:if> DatesDates
  5. 5. Velocity BenefitsVelocity Benefits Based on Java – can leverage Java commands like .contains,Based on Java – can leverage Java commands like .contains, and .replaceand .replace Doesn’t need Xalan JavaScript extension to format dates /Doesn’t need Xalan JavaScript extension to format dates / Date difference calculation easierDate 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)
  6. 6. XSLT BenefitsXSLT Benefits Widespread use outside of Cascade(wealth of tutorials andWidespread use outside of Cascade(wealth of tutorials and books available)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 - OxygenXMLAdvanced editors outside of Cascade Server - OxygenXML
  7. 7. Head to Head ComparisonHead to Head Comparison 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
  8. 8. Battlefield for TimingsBattlefield for Timings (Server specs)(Server specs) Physical machine = Dell Optiplex 745 2.4ghz Intel Core 2Physical machine = Dell Optiplex 745 2.4ghz Intel Core 2 Duo w /4GB RAM running Windows 2008 ServerDuo w /4GB RAM running Windows 2008 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 retested forRestarted server, ran all 3 Velocity rounds, then retested for cached timing, restarted again and ran all 3 XSLT roundscached timing, restarted again and ran all 3 XSLT rounds then retested for cached timingsthen retested for cached timings
  9. 9. Round 1 – Large Tabular DataRound 1 – Large Tabular Data During this round contestants were asked to take a large setDuring this round contestants were asked to take a large set of person data and sort this data into four equal lengthof person data and sort this data into four equal length column listings by first name.column listings by first name. The dataset is an XML block with 1000 entries. Columns areThe dataset is an XML block with 1000 entries. Columns are created via YUI Grid .css versus tables to produce validcreated via YUI Grid .css versus tables to produce valid XHTML and not use tables for layout. Data was generatedXHTML and not use tables for layout. Data was generated using the Vulcano tool:using the Vulcano tool: http://http://www.datagenerator.orgwww.datagenerator.org Data format: ID, Name, email, phone, date, websiteData format: ID, Name, email, phone, date, website
  10. 10. Round 1 TimingsRound 1 Timings Velocity XSLT Initial Runtime (ms) 3635ms 5957ms Cached Runtime 2032ms 3873ms
  11. 11. Round 2 – Search Speed – LargeRound 2 – Search Speed – Large DataData Contestants were asked to search the works of ShakespeareContestants were asked to search the works of Shakespeare in XML format for the provided search term of pirate.in XML format for the provided search term of pirate. Tragically for Alvin it was determined that the bard neverTragically for Alvin it was determined that the bard never made mention of Ninjas, while Pirates were mentioned in amade mention of Ninjas, while Pirates were mentioned in a number of plays.number of plays.
  12. 12. Round 2 - TimingsRound 2 - Timings Velocity XSLT Initial Runtime 8409ms 7644ms Cached Runtime 2135ms 1928ms
  13. 13. Final Round (3) – Tumblr RSSFinal Round (3) – Tumblr RSS FeedFeed Contestants were asked to render an external RSS feed fromContestants were asked to render an external RSS feed from a Tumblr account –a Tumblr account – http://velocityversusxslt.tumlbr.comhttp://velocityversusxslt.tumlbr.com
  14. 14. Round 3 TimingsRound 3 Timings Velocity XSLT Initial Runtime 350ms 401ms Cached Runtime 215ms 200ms
  15. 15. 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=http://www.amazon.com/Pro-Jakarta-Velocity-Professional-Expert/dp/159059410X/ref=sr_1_1?ie= jakartajakarta Matering Apache VelocityMatering Apache Velocity httphttp://www.amazon.com/exec/obidos/ASIN/0471457949://www.amazon.com/exec/obidos/ASIN/0471457949// Velocity User’s Guide:Velocity User’s Guide: http://velocity.apache.org/engine/devel/user-http://velocity.apache.org/engine/devel/user-guide.htmlguide.html Velocity Cookbook on github:Velocity Cookbook on github: httpshttps://github.com/hannonhill/Velocity-://github.com/hannonhill/Velocity-CookbookCookbook Presentations:Presentations: 2010 User’s Conference -2010 User’s Conference - http://www.hannonhill.com/news/conference/2010/videos/Velocity-vs-http://www.hannonhill.com/news/conference/2010/videos/Velocity-vs-XSLT.htmlXSLT.html HH Blog posting -HH Blog posting - httphttp ://www.hannonhill.com/news/blog/2011/the-eternal-debate-velocity-or-://www.hannonhill.com/news/blog/2011/the-eternal-debate-velocity-or- xslt.htmlxslt.html Velocity Webinar http://www.hannonhill.com/products/demos/velocity-Velocity Webinar http://www.hannonhill.com/products/demos/velocity- functionality-overview-webinar-video.htmlfunctionality-overview-webinar-video.html
  16. 16. XSLT ResourcesXSLT Resources Hannon Hill XSLT Workbook on githubHannon 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 andXSLT Cookbook, 2nd Edition by Sal Mangano and published by O’Reillypublished by O’Reilly OxygenXML http://www.oxygenxml.com/OxygenXML http://www.oxygenxml.com/
  17. 17. And the winner is…And the winner is… The clear winner is you, because you get to choose whichThe clear winner is you, because you get to choose which language to use by default, but you retain the option tolanguage to use by default, but you retain the option to switch when doing so makes sense.switch when doing so makes sense. But, for those who need a victor – go take our poll – VelocityBut, for those who need a victor – go take our poll – Velocity or XSLT here:or XSLT here:

×