Skip to content

Instantly share code, notes, and snippets.

@r4hulp
Created July 13, 2026 10:24
Show Gist options
  • Select an option

  • Save r4hulp/830a8103756f24fe4b47cea5da948151 to your computer and use it in GitHub Desktop.

Select an option

Save r4hulp/830a8103756f24fe4b47cea5da948151 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ws="urn:com.workday/workersync"
exclude-result-prefixes="ws">
<xsl:output method="text" encoding="UTF-8"/>
<!-- =========================================================
Main template
========================================================= -->
<xsl:template match="/">
<!-- CSV header -->
<xsl:text>Employee_ID,Legal_First_Name,Legal_Last_Name,Location_Country,Language,Work_Email,Home_Email,Job_Profile,Hire_Date,Termination_Date,Active,Worker_Type</xsl:text>
<xsl:text>&#13;&#10;</xsl:text>
<!-- Process each worker -->
<xsl:for-each select="ws:Worker_Sync/ws:Worker">
<!-- Source values -->
<xsl:variable name="employeeId"
select="normalize-space(ws:Summary/ws:Employee_ID)"/>
<xsl:variable name="firstName"
select="normalize-space(ws:Personal/ws:Name_Data/ws:First_Name)"/>
<xsl:variable name="lastName"
select="normalize-space(ws:Personal/ws:Name_Data/ws:Last_Name)"/>
<!-- Country is printed exactly as received -->
<xsl:variable name="country"
select="normalize-space(ws:Personal/ws:Address_Data/ws:Country)"/>
<xsl:variable name="workEmail"
select="normalize-space(ws:Personal/ws:Email_Data/ws:Email_Address)"/>
<!-- Home email remains blank unless a separate source node exists -->
<xsl:variable name="homeEmail" select="''"/>
<xsl:variable name="jobProfile"
select="normalize-space(ws:Position/ws:Job_Profile)"/>
<xsl:variable name="hireDate"
select="normalize-space(ws:Status/ws:Hire_Date)"/>
<xsl:variable name="terminationDate"
select="normalize-space(ws:Status/ws:Termination_Date)"/>
<!-- Worker type is printed exactly as received -->
<xsl:variable name="workerType"
select="normalize-space(ws:Position/ws:Worker_Type)"/>
<!-- Employee ID -->
<xsl:call-template name="csv-field">
<xsl:with-param name="value" select="$employeeId"/>
</xsl:call-template>
<xsl:text>,</xsl:text>
<!-- Legal First Name -->
<xsl:call-template name="csv-field">
<xsl:with-param name="value" select="$firstName"/>
</xsl:call-template>
<xsl:text>,</xsl:text>
<!-- Legal Last Name -->
<xsl:call-template name="csv-field">
<xsl:with-param name="value" select="$lastName"/>
</xsl:call-template>
<xsl:text>,</xsl:text>
<!-- Location Country -->
<xsl:call-template name="csv-field">
<xsl:with-param name="value" select="$country"/>
</xsl:call-template>
<xsl:text>,</xsl:text>
<!-- Language derived from country -->
<xsl:variable name="language">
<xsl:choose>
<xsl:when test="$country = 'US'">ENG</xsl:when>
<xsl:when test="$country = 'NL'">DUT</xsl:when>
<xsl:when test="$country = 'DE'">GER</xsl:when>
<xsl:when test="$country = 'FR'">FRE</xsl:when>
<xsl:otherwise>NA</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:call-template name="csv-field">
<xsl:with-param name="value" select="$language"/>
</xsl:call-template>
<xsl:text>,</xsl:text>
<!-- Work Email -->
<xsl:call-template name="csv-field">
<xsl:with-param name="value" select="$workEmail"/>
</xsl:call-template>
<xsl:text>,</xsl:text>
<!-- Home Email -->
<xsl:call-template name="csv-field">
<xsl:with-param name="value" select="$homeEmail"/>
</xsl:call-template>
<xsl:text>,</xsl:text>
<!-- Job Profile -->
<xsl:call-template name="csv-field">
<xsl:with-param name="value" select="$jobProfile"/>
</xsl:call-template>
<xsl:text>,</xsl:text>
<!-- Hire Date -->
<xsl:variable name="formattedHireDate">
<xsl:call-template name="format-date">
<xsl:with-param name="date" select="$hireDate"/>
</xsl:call-template>
</xsl:variable>
<xsl:call-template name="csv-field">
<xsl:with-param name="value" select="$formattedHireDate"/>
</xsl:call-template>
<xsl:text>,</xsl:text>
<!-- Termination Date -->
<xsl:variable name="formattedTerminationDate">
<xsl:call-template name="format-date">
<xsl:with-param name="date" select="$terminationDate"/>
</xsl:call-template>
</xsl:variable>
<xsl:call-template name="csv-field">
<xsl:with-param name="value" select="$formattedTerminationDate"/>
</xsl:call-template>
<xsl:text>,</xsl:text>
<!-- Active -->
<xsl:choose>
<xsl:when test="$terminationDate = ''">
<xsl:text>true</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>false</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:text>,</xsl:text>
<!-- Worker Type: print exactly as received -->
<xsl:call-template name="csv-field">
<xsl:with-param name="value" select="$workerType"/>
</xsl:call-template>
<!-- End of row -->
<xsl:text>&#13;&#10;</xsl:text>
</xsl:for-each>
</xsl:template>
<!-- =========================================================
Convert YYYY-MM-DD to DDMMYYYY
Missing or malformed values become blank
========================================================= -->
<xsl:template name="format-date">
<xsl:param name="date"/>
<xsl:choose>
<xsl:when test="
string-length(normalize-space($date)) &gt;= 10
and substring($date, 5, 1) = '-'
and substring($date, 8, 1) = '-'
">
<xsl:value-of select="substring($date, 9, 2)"/>
<xsl:value-of select="substring($date, 6, 2)"/>
<xsl:value-of select="substring($date, 1, 4)"/>
</xsl:when>
<xsl:otherwise/>
</xsl:choose>
</xsl:template>
<!-- =========================================================
Output one CSV field
Missing values become ""
========================================================= -->
<xsl:template name="csv-field">
<xsl:param name="value"/>
<xsl:text>"</xsl:text>
<xsl:call-template name="escape-quotes">
<xsl:with-param name="value" select="string($value)"/>
</xsl:call-template>
<xsl:text>"</xsl:text>
</xsl:template>
<!-- =========================================================
Escape quotes for CSV
" becomes ""
========================================================= -->
<xsl:template name="escape-quotes">
<xsl:param name="value"/>
<xsl:choose>
<xsl:when test="contains($value, '&quot;')">
<xsl:value-of select="substring-before($value, '&quot;')"/>
<xsl:text>""</xsl:text>
<xsl:call-template name="escape-quotes">
<xsl:with-param name="value"
select="substring-after($value, '&quot;')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$value"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment