Skip to content

Instantly share code, notes, and snippets.

@stefangoor
Last active October 9, 2015 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefangoor/80b269c1f7f1d3502e62 to your computer and use it in GitHub Desktop.
Save stefangoor/80b269c1f7f1d3502e62 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:sf="http://soap.sforce.com/2006/04/metadata" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<!-- remove all the content -->
<xsl:template match="sf:CustomObject/*"/>
<!-- keep only fields, labels and pluralLabels -->
<xsl:template match="sf:CustomObject/sf:fields | sf:CustomObject[descendant::sf:pluralLabel]/sf:label | sf:CustomObject/sf:pluralLabel">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<!-- add plural label if missing -->
<xsl:template match="sf:CustomObject[not(descendant::sf:pluralLabel)]/sf:label">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
<xsl:element name="sf:pluralLabel">
<xsl:text><xsl:value-of select="."/></xsl:text>
</xsl:element>
</xsl:template>
<!-- skip formulas -->
<xsl:template match="sf:CustomObject/sf:fields[sf:formula]"/>
<!-- ignore track trending attribute -->
<xsl:template match="sf:CustomObject/sf:fields/sf:trackTrending"/>
<!-- remove master detail -->
<xsl:template match="sf:CustomObject/sf:fields[sf:type='MasterDetail']/sf:type">
<xsl:element name="length">
<xsl:text>255</xsl:text>
</xsl:element>
<xsl:element name="type">
<xsl:text>Text</xsl:text>
</xsl:element>
</xsl:template>
<xsl:template match="sf:CustomObject/sf:fields[sf:type='MasterDetail']/sf:writeRequiresMasterRead | sf:CustomObject/sf:fields[sf:type='MasterDetail']/sf:reparentableMasterDetail | sf:CustomObject/sf:fields[sf:type='MasterDetail']/sf:relationshipOrder | sf:CustomObject/sf:fields[sf:type='MasterDetail']/sf:relationshipName | sf:CustomObject/sf:fields[sf:type='MasterDetail']/sf:referenceTo"/>
<!-- add visibility attribute -->
<xsl:template match="sf:CustomObject/sf:sharingModel">
<xsl:element name="visibility">
<xsl:text>Public</xsl:text>
</xsl:element>
</xsl:template>
<!-- change picklists to strings -->
<xsl:template match="sf:CustomObject/sf:fields[sf:type='Picklist']/sf:type">
<xsl:element name="length">
<xsl:text>255</xsl:text>
</xsl:element>
<xsl:element name="type">
<xsl:text>Text</xsl:text>
</xsl:element>
</xsl:template>
<xsl:template match="sf:CustomObject/sf:fields/sf:picklist"/>
<!-- change html to strings and remove visible lines attribute -->
<xsl:template match="sf:CustomObject/sf:fields[sf:type='Html' or sf:type='LongTextArea']/sf:type/text()">
<xsl:value-of select="'TextArea'"/>
</xsl:template>
<xsl:template match="sf:CustomObject/sf:fields[sf:type='Html' or sf:type='LongTextArea']/sf:length | sf:CustomObject/sf:fields[sf:type='Html' or sf:type='LongTextArea']/sf:visibleLines"/>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment