XML - XSLT Sample codes
Use the below sample code to start with your XSLT journey. I made it as simple as possible for you to understand and get going.
XML Sample:
<?xml version="1.0" encoding="UTF-8"?>
<wd:Report_Data xmlns:wd="urn:com.workday.report/WD_Sample_Report">
<wd:Report_Entry>
<wd:Employee_ID>1234</wd:Employee_ID>
<wd:firstName>Steve</wd:firstName>
<wd:lastName>Morgan</wd:lastName>
<wd:Age>56</wd:Age>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:Employee_ID>1235</wd:Employee_ID>
<wd:firstName>Logan</wd:firstName>
<wd:lastName>McNeil</wd:lastName>
<wd:Age>40</wd:Age>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:Employee_ID>1236</wd:Employee_ID>
<wd:firstName>Joy</wd:firstName>
<wd:lastName>Banks</wd:lastName>
<wd:Age>42</wd:Age>
</wd:Report_Entry>
</wd:Report_Data>
XSLT Sample:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wd="urn:com.workday.report/WD_Sample_Report" version="2.0">
<xsl:output method="text" indent="no"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="NEWLINE" select="'
'"/>
<xsl:variable name="PIPE" select="'|'"/>
<xsl:template match="/">
<!-- Header Record -->
<xsl:text>Employee ID</xsl:text>
<xsl:value-of select="$PIPE"/>
<xsl:text>First Name</xsl:text>
<xsl:value-of select="$PIPE"/>
<xsl:text>Last Name</xsl:text>
<xsl:value-of select="$PIPE"/>
<xsl:text>Age</xsl:text>
<xsl:value-of select="$NEWLINE"/>
<xsl:for-each select="wd:Report_Data/wd:Report_Entry">
<!-- Detail Record -->
<xsl:value-of select="wd:Employee_ID"/>
<xsl:value-of select="$PIPE"/>
<xsl:value-of select="wd:firstName"/>
<xsl:value-of select="$PIPE"/>
<xsl:value-of select="wd:lastName"/>
<xsl:value-of select="$PIPE"/>
<xsl:value-of select="wd:Age"/>
<xsl:value-of select="$NEWLINE"/>
</xsl:for-each>
<!-- Trailer Record -->
<xsl:text>End of Records</xsl:text>
</xsl:template>
</xsl:stylesheet>
Test
Use XLS Transformer to test the above code.
Result:
Employee ID|First Name|Last Name|Age|
1234|Steve|Morgan|56
1235|Logan|McNeil|40
1235|Joy|Banks|42
End of Records