Showing posts with label Transformation. Show all posts
Showing posts with label Transformation. Show all posts

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:


Friday, April 17

Integrations: Workday XSL Coding Tips

Workday XSL Coding Tips


Using Variables (Declaration) :


<xsl:variable name="NEWLINE" select="'&#xa;'"/>
<xsl:variable name="PIPE" select="'|'"/>   [Use the delimiter that you would like to see in the output. Examples: Comma(,), Tab (    ), Pipe(|), SemiColon(;) ]
               <xsl:variable name="Record1" select="'C'"/>
               <xsl:variable name="Record2" select="'S'"/>

Using your Variable: (for above)


              <xsl:value-of select="$NEWLINE"/> [This takes the cursor to next line]
              <xsl:value-of select="$PIPE"/>  [This prints | ]
      <xsl:value-of select="$Record1"/>     [This prints C]
      <xsl:value-of select="$Record2"/>     [This prints S]


Using Fillers (Declaration):

    <xsl:variable name="Filler_Blank" select="'                                                                                                                            '"/>
            <xsl:variable name="Filler_Zeros" select="'0000000000000000000000'"/>


Using your Fillers and Substring Function: (for above)

             <xsl:value-of select="substring($Filler,1,10)"/>           [This prints 10 spaces, if you say 15 then it will print 15 spaces ]
             <xsl:value-of select="substring($Filler_Zeros,1,4)"/>  [This prints 0000 as you said 4]


Using Plain Text:


<xsl:value-of select="'TEST'"/>

Using Comment:


<!--  Your Comment Here  -->  

Using Choose:


    <xsl:choose>
<xsl:when test=" wd:Gender = 'Male' ">
   <xsl:value-of select="'M'"/>
        </xsl:when>
<xsl:when test=" wd:Gender = 'Female' ">
   <xsl:value-of select="'F'"/>
        </xsl:when>
        <xsl:otherwise>
                  <xsl:value-of select="'U'"/>
        </xsl:otherwise>
    </xsl:choose>

Using For:


<xsl:for-each select="wd:Report_Data/wd:Report_Entry">

          <Your Lines of code here>

        </xsl:for-each>

Using Templates:


    <xsl:template match="/">
        <xsl:call-template name="HeaderRecord"/>
        <xsl:call-template name="DetailRecords"/>
        <xsl:call-template name="TrailerRecord"/>
    </xsl:template>

    <xsl:template name="HeaderRecord">
          <Your Lines of code here>
    </xsl:template>

    <xsl:template name="DetailRecords">
          <Your Lines of code here>
    </xsl:template>

    <xsl:template name="TrailerRecord">
          <Your Lines of code here>
    </xsl:template>


Wednesday, April 15

Integrations: Workday 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="'&#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>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

Tuesday, April 14

Integrations: XML - XSL Tranformation - Free online Formatter

Workday XML - XSL Tranformation

Abbrevations:

XML Stands for eXtensible Markup Language
XSL Stand for eXtensible Stylesheet Language (Styling language for XML)
XSLT stands for XSL Transformations.


If you do not have any xsl transformers installed on your local machine,  I suggest you to use online free formatter to test your xml to xslt conversion and see how your end data looks like after applying your transformation code.

Follow the below three steps, to transform your xml.
  1. XML input - Copy Paste / Attach your generated workday xml code.
  2. XSL input  - Copy Paste / Attach your own custom code in relation to your xml.
  3. Transform XML - Click this to see the result.
Click the below link to format your code.


Just a word of caution: Make sure, you avoid any confidential data in your xml file while using free online formatters