xpath functions in xslt mapping

 

Description

This weblog explains the usage and syntax of various xpath functions like translate(),concat(),Subsrting(),sum(),count() string() in xslt mapping with an example...

Here I would like explain the syntax and number of parameters accepted by each xpath funtion.

substring()

This Function is used to extract some portions of the string from the original string.It takes a specified number of characters out of a string

syntax: substring("PRASAD BABU",1,6)

translate()

The translate function takes the string in the value argument,replaces all occurrecnes of a string specified in the string1 argument with substitue characters specified in string2 argument and returns the modified string.

syntax: translate("prasad babu","abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")

string()

The string function converts the input to a string.

syntax: string("prasad babu")

concat()

The concat function takes all the individual arguments,concatenates them together in order,and returns the resultstant string

syntax: concat("prasad","babu")

sum()

The sum function converts PCDATA text to a numeric value

syntax: sum(p2:marks/score)

count()

This function is used to count the nodes

syntax: count(p2:marks/subjects)

Target Message Type

image

Source Message Type

image

------------------------------------------------------------------------------------------------------------------------------------

<xsl:transform version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:sap="http://www.sap.com/sapxsl"
  xmlns:p2="http://idoc_to_file_ep.com">

<xsl:template match="/">
<p2:MT_STUD>
<Records>
       <Student_ID>
            <Name>
                 <xsl:value-of select="concat(concat (p2:MT_STUD_SORC/Records/Student_ID/Fname,' '),p2:MT_STUD_SORC/Records/Student_ID/Lname)"/>
            </Name>
            <Year_Birth>
                <xsl:value-of select="substring(p2:MT_STUD_SORC/Records/Student_ID/DOB,1,4)"/>
                               </Year_Birth>
                               <Month_Birth>
                               <xsl:value-of select="substring(p2:MT_STUD_SORC/Records/Student_ID/DOB,5,2)"/>
                               </Month_Birth>
                               <Date_Birth>
                               <xsl:value-of select="substring(p2:MT_STUD_SORC/Records/Student_ID/DOB,7,8)"/>
                               </Date_Birth>

                               <Marks>

                                      <Science>
                                      <xsl:value-of select="p2:MT_STUD_SORC/Records/Student_ID/Marks/Science"/>
                                      </Science>

                                      <Maths>
                                      <xsl:value-of select="p2:MT_STUD_SORC/Records/Student_ID/Marks/Maths"/>
                                      </Maths>

                                      <Language>
                                      <xsl:value-of select="p2:MT_STUD_SORC/Records/Student_ID/Marks/Language"/>
                                      </Language>

                                       <Total_Marks>
                                       <xsl:value-of select="sum(p2:MT_STUD_SORC/Records/Student_ID/Marks/Sciense)"/>
                                       </Total_Marks>

                             </Marks>
                        </Student_ID>

                      <No_Students>
                      <xsl:value-of select="count(p2:MT_STUD_SORC/Records/Student_ID)"/>
                      </No_Students>
        </Records>
       </p2:MT_STUD>
  </xsl:template>
</xsl:transform>

 

------------------------------------------------------------------------------------------------------------------------------------

SAP XI Training

SAP XI Interview Questions

SAP XI/PI Tutorials

SAP Developer Network SAP Weblogs: SAP Process Integration (PI)