Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
XSLT Stylesheet to report on Validation formulas in Salesforce
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
exclude-result-prefixes="xs xd"
version="2.0">
<xsl:output method="html" omit-xml-declaration="yes" use-character-maps="no-control-characters"/>
<xsl:template match="/">
<html>
<head>
<title>Validation Rules Report</title>
<script src="excel-formula.min.js" />
<style>
body { padding: 10px; }
body, td {font-family: Verdana, Arial, sans-serif; font-size: x-small}
tr {vertical-align: top}
tr.disabled { background-color: #EFEFEF; color: #666666;}
td { border-top: 1px solid gray; border-left: 1px solid gray; margin: 0px; padding: 5px; word-wrap: break-word; word-break:break-all;}
td.ruleName { color: #000066; width: 40% }
td.ruleMessage { border-right: 1px solid gray;}
td.disabled {text-decoration: line-through;}
td.errorDisplay {font-weight: bold; background-color: #FFEEEE;}
td.formula {border-bottom: 2px solid black; border-right: 1px solid gray;}
th {text-align: left; margin: 0px; padding-top: 15px; padding: 3px; }
table { width: 100%; border-spacing: 0;}
</style>
</head>
<body>
<h1>Validation Formula Report</h1>
<ul>
<li>
Objects with validation rules: <xsl:value-of select="count(/Validations/Validation)"/>
</li>
<li>
Total number of validation rules: <xsl:value-of select="count(/Validations/Validation/Rule)"/>
</li>
<li>
Active number of validation rules: <xsl:value-of select="count(/Validations/Validation/Rule[active='true'])"/>
</li>
<li>
Rules next to fields: <xsl:value-of select="count(/Validations/Validation/Rule/errorDisplayField)" />
</li>
</ul>
<xsl:apply-templates />
</body>
</html>
</xsl:template>
<xsl:template match="Validations">
<table>
<thead>
<th>Name</th>
<th>Message</th>
</thead>
<tbody>
<xsl:apply-templates />
</tbody>
</table>
</xsl:template>
<xsl:template match="Validation">
<tr>
<th colspan="2">
<xsl:value-of select="@objectName"/> (<xsl:value-of select="count(Rule)"/>)
</th>
</tr>
<xsl:apply-templates />
</xsl:template>
<xsl:template match="Rule">
<tr>
<xsl:apply-templates select="fullName" />
<td class="ruleMessage">
<xsl:value-of select="errorMessage" />
</td>
</tr>
<tr>
<td colspan="2" class="formula">
<xsl:variable name="apos">'</xsl:variable>
<xsl:variable name="repl">"</xsl:variable>
<script language="JavaScript">
document.write(excelFormulaUtilities.formatFormulaHTML('<xsl:value-of select="translate(replace(errorConditionFormula,$apos,$repl),' &#x9;&#xa;', '')" />'));
</script>
</td>
</tr>
</xsl:template>
<xsl:template match="fullName">
<td class="ruleName">
<xsl:value-of select="."/>
</td>
</xsl:template>
<xsl:template match="fullName[../errorDisplayField]">
<td class="ruleName errorDisplay">
<xsl:value-of select="."/>
(<xsl:value-of select="../errorDisplayField" />)
</td>
</xsl:template>
<xsl:template match="Rule[active='false']">
<tr class="disabled">
<td class="ruleName disabled">
<xsl:value-of select="fullName"/>
</td>
<td class="ruleMessage">
<xsl:value-of select="errorMessage" />
</td>
</tr>
<tr class="disabled">
<td colspan="2" class="formula">
<xsl:value-of select="errorConditionFormula" />
</td>
</tr>
</xsl:template>
<xsl:character-map
name="no-control-characters">
<xsl:output-character character="&#127;" string=" "/>
<xsl:output-character character="&#128;" string=" "/>
<xsl:output-character character="&#129;" string=" "/>
<xsl:output-character character="&#130;" string=" "/>
<xsl:output-character character="&#131;" string=" "/>
<xsl:output-character character="&#132;" string=" "/>
<xsl:output-character character="&#133;" string=" "/>
<xsl:output-character character="&#134;" string=" "/>
<xsl:output-character character="&#135;" string=" "/>
<xsl:output-character character="&#136;" string=" "/>
<xsl:output-character character="&#137;" string=" "/>
<xsl:output-character character="&#138;" string=" "/>
<xsl:output-character character="&#139;" string=" "/>
<xsl:output-character character="&#140;" string=" "/>
<xsl:output-character character="&#141;" string=" "/>
<xsl:output-character character="&#142;" string=" "/>
<xsl:output-character character="&#143;" string=" "/>
<xsl:output-character character="&#144;" string=" "/>
<xsl:output-character character="&#145;" string=" "/>
<xsl:output-character character="&#146;" string=" "/>
<xsl:output-character character="&#147;" string=" "/>
<xsl:output-character character="&#148;" string=" "/>
<xsl:output-character character="&#149;" string=" "/>
<xsl:output-character character="&#150;" string=" "/>
<xsl:output-character character="&#151;" string=" "/>
<xsl:output-character character="&#152;" string=" "/>
<xsl:output-character character="&#153;" string=" "/>
<xsl:output-character character="&#154;" string=" "/>
<xsl:output-character character="&#155;" string=" "/>
<xsl:output-character character="&#156;" string=" "/>
<xsl:output-character character="&#157;" string=" "/>
<xsl:output-character character="&#158;" string=" "/>
<xsl:output-character character="&#159;" string=" "/>
</xsl:character-map>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
exclude-result-prefixes="xs xd"
version="2.0">
<xsl:output method="html" omit-xml-declaration="yes" use-character-maps="no-control-characters"/>
<xsl:template match="/">
<html>
<head>
<title>Validation Rules Report</title>
</head>
<style>
body { padding: 10px; }
body, td {font-family: Verdana, Arial, sans-serif; font-size: x-small}
tr {vertical-align: top}
tr.disabled { background-color: #EFEFEF; color: #666666;}
td { border-top: 1px solid gray; border-left: 1px solid gray; margin: 0px; padding: 5px; word-wrap: break-word; word-break:break-all;}
td.ruleName { color: #000066; width: 40% }
td.ruleMessage { border-right: 1px solid gray;}
td.disabled {text-decoration: line-through;}
td.errorDisplay {font-weight: bold; background-color: #FFEEEE;}
td.formula {border-bottom: 2px solid black; border-right: 1px solid gray;}
th {text-align: left; margin: 0px; padding-top: 15px; padding: 3px; }
table { width: 100%; border-spacing: 0;}
</style>
<body>
<h1>Validation Formula Report</h1>
<ul>
<li>
Objects with validation rules: <xsl:value-of select="count(/Validations/Validation)"/>
</li>
<li>
Total number of validation rules: <xsl:value-of select="count(/Validations/Validation/Rule)"/>
</li>
<li>
Active number of validation rules: <xsl:value-of select="count(/Validations/Validation/Rule[active='true'])"/>
</li>
<li>
Rules next to fields: <xsl:value-of select="count(/Validations/Validation/Rule/errorDisplayField)" />
</li>
</ul>
<xsl:apply-templates />
</body>
</html>
</xsl:template>
<xsl:template match="Validations">
<table>
<thead>
<th>Name</th>
<th>Message</th>
</thead>
<tbody>
<xsl:apply-templates />
</tbody>
</table>
</xsl:template>
<xsl:template match="Validation">
<tr>
<th colspan="2">
<xsl:value-of select="@objectName"/> (<xsl:value-of select="count(Rule)"/>)
</th>
</tr>
<xsl:apply-templates />
</xsl:template>
<xsl:template match="Rule">
<tr>
<xsl:apply-templates select="fullName" />
<td class="ruleMessage">
<xsl:value-of select="errorMessage" />
</td>
</tr>
<tr>
<td colspan="2" class="formula">
<xsl:value-of select="errorConditionFormula" />
</td>
</tr>
</xsl:template>
<xsl:template match="fullName">
<td class="ruleName">
<xsl:value-of select="."/>
</td>
</xsl:template>
<xsl:template match="fullName[../errorDisplayField]">
<td class="ruleName errorDisplay">
<xsl:value-of select="."/>
(<xsl:value-of select="../errorDisplayField" />)
</td>
</xsl:template>
<xsl:template match="Rule[active='false']">
<tr class="disabled">
<td class="ruleName disabled">
<xsl:value-of select="fullName"/>
</td>
<td class="ruleMessage">
<xsl:value-of select="errorMessage"/>
</td>
</tr>
<tr class="disabled">
<td colspan="2" class="formula">
<xsl:value-of select="errorConditionFormula" />
</td>
</tr>
</xsl:template>
<xsl:character-map
name="no-control-characters">
<xsl:output-character character="&#127;" string=" "/>
<xsl:output-character character="&#128;" string=" "/>
<xsl:output-character character="&#129;" string=" "/>
<xsl:output-character character="&#130;" string=" "/>
<xsl:output-character character="&#131;" string=" "/>
<xsl:output-character character="&#132;" string=" "/>
<xsl:output-character character="&#133;" string=" "/>
<xsl:output-character character="&#134;" string=" "/>
<xsl:output-character character="&#135;" string=" "/>
<xsl:output-character character="&#136;" string=" "/>
<xsl:output-character character="&#137;" string=" "/>
<xsl:output-character character="&#138;" string=" "/>
<xsl:output-character character="&#139;" string=" "/>
<xsl:output-character character="&#140;" string=" "/>
<xsl:output-character character="&#141;" string=" "/>
<xsl:output-character character="&#142;" string=" "/>
<xsl:output-character character="&#143;" string=" "/>
<xsl:output-character character="&#144;" string=" "/>
<xsl:output-character character="&#145;" string=" "/>
<xsl:output-character character="&#146;" string=" "/>
<xsl:output-character character="&#147;" string=" "/>
<xsl:output-character character="&#148;" string=" "/>
<xsl:output-character character="&#149;" string=" "/>
<xsl:output-character character="&#150;" string=" "/>
<xsl:output-character character="&#151;" string=" "/>
<xsl:output-character character="&#152;" string=" "/>
<xsl:output-character character="&#153;" string=" "/>
<xsl:output-character character="&#154;" string=" "/>
<xsl:output-character character="&#155;" string=" "/>
<xsl:output-character character="&#156;" string=" "/>
<xsl:output-character character="&#157;" string=" "/>
<xsl:output-character character="&#158;" string=" "/>
<xsl:output-character character="&#159;" string=" "/>
</xsl:character-map>
</xsl:stylesheet>
@Stwissel

This comment has been minimized.

Copy link
Owner Author

commented Feb 8, 2019

The interactive version of the stylesheet needs the Excel formula formatter JS file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.