XSLTTool - Documentation topics on: velocity tools,xml,xslt,xslttool,.


Class: com.dotmarketing.viewtools.XSLTTool

Name: $xslttool - (way to refer to the tool in the Velocity context)

Toolbox Configuration Example


Both methods in the XSLTTool take 3 parameters: URL to the XML, URL to the XSLT, and a cache ttl. The ttl is passed as the number minutes that the page will cache before refreshing the read of content from the xml source page.

Example 1

#set($xmlUrl = 'http://www.w3schools.com/XML/cd_catalog.xml')
#set($xsltUrl = '/demos/integration/demo-stylesheet.xsl')
$xslttool.transform($xmlUrl, $xsltUrl, 30)

Example 2

#set($xmlUrl = "http://www.w3schools.com/XML/cd_catalog.xml")
#set($xsltUrl = "/demos/integration/demo-stylesheet.xsl")
#set($XSLTransDoc =$xslttool.XSLTTransform($xmlUrl, $xsltUrl,30))

Here is an example of the xsl stylesheet code referenced in both of the examples above:

<?xml version="1.0"?>

<xsl:stylesheet version="1.0"

<xsl:template match="/">
    <h2>My CD Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
      <xsl:for-each select="CATALOG/CD">
          <td><xsl:value-of select="TITLE"/></td>
          <td><xsl:value-of select="ARTIST"/></td>


Note: The "value-of select=" requires a field title that is case sensitive. Make sure the field in your stylesheet matches the case of the name of the field in your xml feed.

Here is an example of the executed XSLT Transformation using Example 1 and the stylesheet code from above: