I have a xml file which have two elements ’employeeID’ and ‘managerID’. I like to check if managerID does not exist in any value in employeeID then replace the value of managerID with ‘Not Found’.
I have to transform the below xml and replace the value of second element managerID with ‘Not Found’ if the value of managerID does not match with any value in employeeID.
<wd:Report_Data xmlns:wd="urn:com.workday.report/bsvc">
<wd:Report_Entry>
<wd:employeeID>EMPLOYEE1</wd:employeeID>
<wd:managerID>EMPLOYEE5</wd:managerID>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:employeeID>EMPLOYEE2</wd:employeeID>
<wd:managerID>EMPLOYEE6</wd:managerID>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:employeeID>EMPLOYEE6</wd:employeeID>
<wd:managerID>EMPLOYEE17</wd:managerID>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:employeeID>EMPLOYEE17</wd:employeeID>
<wd:managerID>EMPLOYEE3</wd:managerID>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:employeeID>EMPLOYEE3</wd:employeeID>
<wd:managerID>EMPLOYEE2</wd:managerID>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:employeeID>EMPLOYEE4</wd:employeeID>
<wd:managerID>EMPLOYEE22</wd:managerID>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:employeeID>EMPLOYEE8</wd:employeeID>
<wd:managerID>EMPLOYEE2</wd:managerID>
</wd:Report_Entry>
</wd:Report_Data>
My xslt is a below but this is returning ‘Not found’ for everyone. Expected out should be
EMPLOYEE1,Not Found
EMPLOYEE2,EMPLOYEE6
EMPLOYEE6,EMPLOYEE17
EMPLOYEE17,EMPLOYEE3
EMPLOYEE3,EMPLOYEE2
EMPLOYEE4,Not Found
EMPLOYEE8,EMPLOYEE2
<?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:wd="urn:com.workday.report/bsvc"
xmlns:this="urn:this-stylesheet" exclude-result-prefixes="xs" version="2.0">
<xsl:output method="text"/>
<xsl:variable name="Delimiter" select="';'"/>
<xsl:variable name="Newline" select="'
'"/>
<xsl:variable name="allemployeesID">
<xsl:for-each select="/wd:Report_Data/Report_Entry">
<xsl:value-of select="wd:employeeID"/>
</xsl:for-each>
</xsl:variable>
<xsl:template match="/">
<xsl:for-each select="wd:Report_Data/wd:Report_Entry">
<xsl:value-of select="wd:employeeID"/>
<xsl:value-of select="$Delimiter"/>
<xsl:choose>
<xsl:when test="contains($allemployeesID,wd:managerID)">
<xsl:value-of select="wd:managerID"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'Not Found'" />
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="$Newline"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Rohit Tandon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.