The XSLTTool provides a way to read from an XML source while providing XSLT transformation styling.
The following example shows how the TextTool is mapped in the toolbox.xml file:
<tool>
<key>xslttool</key>
<scope>application</scope>
<class>com.dotmarketing.viewtools.XsltTool</class>
</tool>
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 = 'https://www.w3schools.com/xml/cdcatalog.xsl')
$xslttool.transform($xmlUrl, $xsltUrl, 30)
Example 2
#set($xmlUrl = "http://www.w3schools.com/XML/cd_catalog.xml")
#set($xsltUrl = "https://www.w3schools.com/xml/cdcatalog.xsl")
#set($XSLTransDoc =$xslttool.XSLTTransform($xmlUrl, $xsltUrl,30))
$XSLTransDoc.getXmlTransformation()
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"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="CATALOG/CD">
<tr>
<td><xsl:value-of select="TITLE"/></td>
<td><xsl:value-of select="ARTIST"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
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.