Solenopsis with XSLT

by Patrick Connelly posted on July 22, 2016

There’s a great feature we use all the time in Solenopsis that isn’t as documented as it should be. This is the ability to write an XSLT to apply to your objects at time of pull, push or both.

Use Case

If you have a workflow that sends an email, you’ve seen that part of the workflow file is the senderAddress element. The element determines who the email goes to. This becomes a problem when you have a sender that differs in a sandbox than it does in production. Fortunately Solenopsis has supported variable expansion for a while so you can have the following in your workflow XML and in your properties file and the variable will be filled in when you push

<senderAddress>@{senderAddress}</senderAddress>
senderAddress = myemail@example.com

However whenever you pull down the workflow file the variable expansion will not be there and instead you’ll have your myemail@example.com address

Solenopsis with XSLT

This is where the Solenopsis XSLTs come into play. By creating a folder structure that mimics our source directory we can apply XSLTs to our workflow file

 |
 |--- src
 |     |
 |     \--- workflows
 |            |
 |            \--- Case.workflow
 |
 \--- xslt
       |
       \--- workflows
              |
              \--- Case_pull.xsl

The naming structure for the xsl files is

  • Filename.xsl – This will be applied to both pull and push
  • Filename_pull.xsl – This will only be applied to a pull
  • Filename_push.xsl – This will only be applied to a push

Since we want the push to use the variable expansion we only want to apply our XSLT on pull actions. So we’ll fill out the Case_pull.xsl have the following content

<?xml version="1.0"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sfdc="http://soap.sforce.com/2006/04/metadata">
    <xsl:output method="xml" version="1.0" indent="yes"/>

    <xsl:template match="node()|@*">
        <xsl:text></xsl:text>

        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="sfdc:alerts/sfdc:senderAddress/text()">@{senderAddress}</xsl:template>
</xsl:transform>

And by adding the following to our solenopsis.properties file

sf.xslDir = /path/to/xslt/

And this will apply our XSLTs