Wednesday, July 29

Integrations: XML to XSL Coding - Sample 2

XML to XSL Sample Coding - Having reference ID's


Here is another sample coding of xml to xsl. This highlights as how to handle some fields having reference ID related information especially you see this in Workday XML vs Simple XML.

Notice the highlighted Workday XML code for the field Gender. If you compare with other fields like Age or Employee_ID , this field (Gender) is showing up additional information like wd:type and so on. Understand that this is nothing but the object related information. Read this to understand more about reference ID's Reference ID's Explained

Workday 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:Gender wd:Descriptor="Male">
<wd:ID wd:type="WID">98juht8074e54970962128e1105a</wd:ID>
<wd:ID wd:type="Gender_Code">Male</wd:ID>
</wd:Gender>
    <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:Gender wd:Descriptor="Female">
<wd:ID wd:type="WID">d3afbf8074e549709sdf362128e1</wd:ID>
<wd:ID wd:type="Gender_Code">Female</wd:ID>
</wd:Gender>
    <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:Gender wd:Descriptor="Male">
<wd:ID wd:type="WID">e35sef8074e54970962128e1105a</wd:ID>
<wd:ID wd:type="Gender_Code">Male</wd:ID>
</wd:Gender>
    <wd:Age>42</wd:Age>
  </wd:Report_Entry>
</wd:Report_Data>

Use the Below highlighted code to access the information which is of type BO.

XSL 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="'&#xa;'"/>
<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>Gender</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:Gender/@wd:Descriptor"/>
        <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|Gender|Age 1234|Steve|Morgan|Male|56 1235|Logan|McNeil|Female|40 1236|Joy|Banks|Male|42 End of Records

Additional Reads:


No comments:

Post a Comment