Showing posts with label XML. Show all posts
Showing posts with label XML. Show all posts

Thursday, July 28

XSLT - Remove Special Characters Function

Remove Special Characters Function


Which ever characters are allowed, provide it in the select. Anything other than provided characters will be considered as special characters.

<xsl:function name="stripSpecialChars">
    <xsl:param name="string" />
    <xsl:variable name="AllowedSymbols" select ="'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789()*%$#@!~&lt;&gt;,.?[]=- +   /\ '"/>
    <xsl:value-of select="translate($string,translate($string, $AllowedSymbols, ''),' ')"/>
</xsl:function>


<xsl:value-of select="stripSpecialChars($string)"/>


For your information -

&lt;  ---> Less Than Symbol
&gt; ---> Greater Than Symbol

Tuesday, July 26

XSLT - Calculate Week Number based on date

 Calculate Week Number based on date


Template with Parameters:

Defining Template 1- [This template calls another template below]

   <xsl:template name="calculate-week-number">
        <xsl:param name="year"/>
        <xsl:param name="month"/>
        <xsl:param name="day"/>
        
        <xsl:variable name="j-day">
            <xsl:call-template name="calculate-julian-day">
                <xsl:with-param name="year" select="$year"/>
                <xsl:with-param name="month" select="$month"/>
                <xsl:with-param name="day" select="$day"/>
            </xsl:call-template>
        </xsl:variable>
        
        <xsl:variable name="d4" 
            select="($j-day + 31741 - ($j-day mod 7)) 
            mod 146097 mod 36524 mod 1461"/>
        
        <xsl:variable name="L" select="floor($d4 div 1460)"/>
        
        <xsl:variable name="d1" select="(($d4 - $L) mod 365) + $L"/>
        
        <xsl:value-of select="floor($d1 div 7) + 1"/>
        
    </xsl:template>

Defining Template 2 - [Used by above template]

    <xsl:template name="calculate-julian-day">
        <xsl:param name="year"/>
        <xsl:param name="month"/>
        <xsl:param name="day"/>
        
        <xsl:variable name="a" select="floor((14 - $month) div 12)"/>
        <xsl:variable name="y" select="$year + 4800 - $a"/>
        <xsl:variable name="m" select="$month + 12 * $a - 3"/>
        
        <xsl:value-of select="$day + floor((153 * $m + 2) div 5) + $y * 365 + 
            floor($y div 4) - floor($y div 100) + floor($y div 400) - 
            32045"/>
        
    </xsl:template>


Calling Template - [The returned value is stored in the variable WeekNumber]

<xsl:variable name="WeekNumber">            
    <xsl:call-template name="calculate-week-number">
        <xsl:with-param name="day" select="day-from-date($Start_Date)"/>
        <xsl:with-param name="month" select="month-from-date($Start_Date)"/>
        <xsl:with-param name="year" select="year-from-date($Start_Date)"/>
    </xsl:call-template>
</xsl:variable>

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

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