Skip to content

Instantly share code, notes, and snippets.

@Stwissel
Last active February 23, 2019 07:51
Show Gist options
  • Save Stwissel/b5ad5fd6de8d6d9ccdab8ec903bab510 to your computer and use it in GitHub Desktop.
Save Stwissel/b5ad5fd6de8d6d9ccdab8ec903bab510 to your computer and use it in GitHub Desktop.
Sample XSLT to generate a package.xml file for Salesforce ANT tool to remove dead fields
<?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"
xmlns="http://soap.sforce.com/2006/04/metadata" exclude-result-prefixes="xs xd" version="2.0">
<xsl:output encoding="UTF-8" indent="yes" method="xml"/>
<xsl:param name="fieldNameColumn" select="'0'"/>
<xsl:param name="statusColumn" select="'5'"/>
<xsl:param name="isDeletable" select="'yes'"/>
<xsl:template match="/">
<Package>
<xsl:apply-templates
select="workbook/sheet[row/cell[@col = $statusColumn and lower-case(text()) = $isDeletable]]"/>
<version>45.0</version>
</Package>
</xsl:template>
<xsl:template match="sheet">
<xsl:variable name="oName" select="replace(@name, ' ', '')"/>
<xsl:element name="types">
<!-- xsl:attribute name="object"><xsl:value-of select="$oName"/></xsl:attribute -->
<xsl:apply-templates
select="row/cell[@col = $statusColumn and lower-case(text()) = $isDeletable]">
<xsl:with-param name="oName" select="$oName"/>
</xsl:apply-templates>
<name>CustomField</name>
</xsl:element>
</xsl:template>
<xsl:template match="cell">
<xsl:param name="oName"/>
<members><xsl:value-of select="$oName"/>.<xsl:value-of select="../cell[@col = $fieldNameColumn]"/></members>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment