Showing posts with label Coding. Show all posts
Showing posts with label Coding. Show all posts

Monday, July 25

XSLT Functions with Examples

 XSLT Functions with Examples


Always remember while you are coding XSL Transformation, your input for your xsl is XML. 
i.e. your XSL code is based on the XML.

Below are most commonly used XSLT coding functions and methods. This is not an exhaustive list though.

How to Declare a variable:

<xsl:variable name="Newline" select="'&#xa;'"/>
<xsl:variable name="Tab" select="'&#9;'"/>
                <xsl:variable name="NumberFormat" select="'0.00'"/>
                <xsl:variable name="DateFormat" select="'[M01]/[D01]/[Y0001]'"/>
                <xsl:variable name="Pipe" select="'|'"/>
                <xsl:variable name="SplChar" select="'$@!%^&*()- '"/>
                <xsl:variable name="FillerZeros" select="'0000000000000000000000'"/>


How to use the variable which was declared: [Use $]

          <xsl:value-of select="$Newline"/>


Simple Text:
    <xsl:text>Test</xsl:text>


Concat Function:

   Example1:    <xsl:value-of select="concat(wd:Email,$Pipe)"/>
   Example2: <xsl:value-of select="concat('Y',$Pipe)"/>


Translate Function: [Use when you want to replace something]

       <xsl:value-of select="translate(wd:phone, '+().- ', '')" />


Sort Usage:

        <xsl:sort select="wd:Location"/>  


String-length Function:

         <xsl:when test="string-length(wd: Zip) = 8">  
Your Values Here
         </xsl:when>


Exists Function:

           <xsl:when test="exists(wd:Primary_Email)">   
Your Values Here
           </xsl:when>


Count Function:

   Example 1:        <xsl:value-of select="count(//wd:Report_Entry)"/>
   Example 2:        <xsl:value-of select= "count (//wd:Report_Entry[wd:Benefits/wd:Coverage='Family']/wd:Dependents)"/>


Format Date Function:

     Example 1:   <xsl:value-of select="format-date(current-date(),'[Y0001]-[M01]-[D01]')"/>
     Example 2:   <xsl:value-of select="format-date(wd:DateOfBirth,'[Y0001][M01][D01]')"/>


Format Number Function:

    <xsl:value-of select="format-number(wd:amount,$numberFormat)"/>


Substring Function:

         <xsl:value-of select="substring(wd:Work_Phone,3,10)"/>


Substring Before Function:

        <xsl:value-of select="substring-before(wd:Division/@wd:Descriptor,':')"/>


If Condition:

    <xsl:if test="wd:Gender = 'M'">
             .
             .            
            Your code here
             .
             .
    </xsl:if>


Choose and When Function:

  <xsl:choose> 
             <xsl:when test="(wd:Worker_Status = 'On Leave')"> 
                     <xsl:value-of select="'L'"/> 
             </xsl:when>
             <xsl:otherwise> 
                     <xsl:value-of select="'A'"/> 
             </xsl:otherwise> 
 </xsl:choose>


'For' Loop Function:

    Example 1:

   <xsl:for-each select="wd:Report_Data/wd:Report_Entry">
             .
             .            
            Your code here
             .
             .
       </xsl:for-each> 

    Example 2: [Using Group-by]

        <xsl:for-each-group select="wd:Report_Data/wd:Report_Entry" group-by="wd:Location">
             .
             .            
            Your code here
             .
             .
       </xsl:for-each> 


Other Text conditions in When Fuction:

Condition 1:
          <xsl:when test="(wd:Class_Item = '001' or wd:Class_Item = '002')">     
Your Values Here
  </xsl:when>

Condition 2:
         <xsl:when test="(wd:Benefits[1]/wd:Enrolment_Date) != ''">
Your Values Here
         </xsl:when> 

Condition 3:
         <xsl:when test="(wd:Class_Item = '002' and wd:Benefit_Changes[1]/wd:SubType ='T')">    
Your Values Here
         </xsl:when>


Template Declaration and Usage:

Calling Templates -

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

Defining Template -

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

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:


Thursday, June 4

Integrations: Workday xml vs Simple xml

Workday xml vs Simple xml

There is a difference between Workday XML and Simple XML. Let us understand with a generated report.

 Here is the sample report for 3 EEs. 


We are selecting 6 fields. Shown below are the field types.

Employee ID    - Text
Worker             - BO (Single Instance)
First Name        - Text
Gender              - BO (Single Instance)
Marital_status  - BO (Single Instance)
Age                     - Numeric

Navigation to generate XML -  (Make sure firstly your report is a RaaS Report)

Go to Your Report >> Related Actions >> Web Services >> View URL's

When you generate your xml's , Notice below:

In Simple XML all fields are just fields, it do not differentiate where as in Workday XML notice that the WID's and reference id type show up for each instance related fields ( Single Instance / Multi - Instance).

We can say that, when you run the report and see the related actions on any of the column values, then that is likely to give you WID and reference id type.

Simple XML:


<wd:Report_Data xmlns:wd="urn:com.workday.report/pb_Advanced_Report">
<wd:Report_Entry>
<wd:Employee_ID>1234</wd:Employee_ID>
<wd:Worker>Aidan Mitzner</wd:Worker>
<wd:FirstName>Aidan</wd:FirstName>
<wd:Gender>Male</wd:Gender>
<wd:Marital_Status>Single (United States of America)</wd:Marital_Status>
<wd:Age>48</wd:Age>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:Employee_ID>1235</wd:Employee_ID>
<wd:Worker>Wesley Kingston</wd:Worker>
<wd:FirstName>Wesley</wd:FirstName>
<wd:Gender>Male</wd:Gender>
<wd:Marital_Status>Single (United States of America)</wd:Marital_Status>
<wd:Age>31</wd:Age>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:Employee_ID>1236</wd:Employee_ID>
<wd:Worker>Xaviere Francois</wd:Worker>
<wd:FirstName>Xaviere</wd:FirstName>
<wd:Gender>Female</wd:Gender>
<wd:Marital_Status>Free Union (France)</wd:Marital_Status>
<wd:Age>42</wd:Age>
</wd:Report_Entry>
</wd:Report_Data>


Workday XML:


<wd:Report_Data xmlns:wd="urn:com.workday.report/pb_Advanced_Report">
<wd:Report_Entry>
<wd:Employee_ID>1234</wd:Employee_ID>
<wd:Worker wd:Descriptor="Aidan Mitzner">
<wd:ID wd:type="WID">12831f1b82954a3a0ad85fb85367</wd:ID>
<wd:ID wd:type="Employee_ID">1234</wd:ID>
</wd:Worker>
<wd:FirstName>Aidan</wd:FirstName>
<wd:Gender wd:Descriptor="Male">
<wd:ID wd:type="WID">d3afbf8074e54970962128e1105a</wd:ID>
<wd:ID wd:type="Gender_Code">Male</wd:ID>
</wd:Gender>
<wd:Marital_Status wd:Descriptor="Single (United States of America)">
<wd:ID wd:type="WID">5e50cb12452487de0caf7f262d4f</wd:ID>
<wd:ID wd:type="Marital_Status_ID">Single_USA</wd:ID>
</wd:Marital_Status>
<wd:Age>48</wd:Age>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:Employee_ID>1235</wd:Employee_ID>
<wd:Worker wd:Descriptor="Wesley Kingston">
<wd:ID wd:type="WID">480fa11010d6501bfc3dad351f1d</wd:ID>
<wd:ID wd:type="Employee_ID">1235</wd:ID>
</wd:Worker>
<wd:FirstName>Wesley</wd:FirstName>
<wd:Gender wd:Descriptor="Male">
<wd:ID wd:type="WID">bf8074e549ffb070962128e1105a</wd:ID>
<wd:ID wd:type="Gender_Code">Male</wd:ID>
</wd:Gender>
<wd:Marital_Status wd:Descriptor="Single (United States of America)">
<wd:ID wd:type="WID">5e50cb12452487de0caf7f262d4f</wd:ID>
<wd:ID wd:type="Marital_Status_ID">Single_USA</wd:ID>
</wd:Marital_Status>
<wd:Age>31</wd:Age>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:Employee_ID>1236</wd:Employee_ID>
<wd:Worker wd:Descriptor="Xaviere Francois">
<wd:ID wd:type="WID">b31600011066de010d5410b714d0</wd:ID>
<wd:ID wd:type="Employee_ID">1236</wd:ID>
</wd:Worker>
<wd:FirstName>Xaviere</wd:FirstName>
<wd:Gender wd:Descriptor="Female">
<wd:ID wd:type="WID">3bec2d0d420283f76f51b928d885</wd:ID>
<wd:ID wd:type="Gender_Code">Female</wd:ID>
</wd:Gender>
<wd:Marital_Status wd:Descriptor="Free Union (France)">
<wd:ID wd:type="WID">f0f5d5eb405b9ffa48755d4d8b41</wd:ID>
<wd:ID wd:type="Marital_Status_ID">Free_Union_France</wd:ID>
<wd:ID wd:type="Marital_Status_Code" wd:parent_type="WID" wd:parent_id="6971ffb4bf0b116fe7651ec789a">UNIFRA</wd:ID>
</wd:Marital_Status>
<wd:Age>42</wd:Age>
</wd:Report_Entry>
</wd:Report_Data>

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