Skip to Content
avatar image
Former Member

XSLT Mapping - Condition

Hello All,

I have a requirement to check the condition and apply the values for a given field in an xml.

I need to check the value of phoneType and replace the value with different value stored in parameter.

Like H is to be replaced with '450' and C with '452'.How to do this.Please help.

<PerPhone>

<PerPhone>

<phoneType>H</phoneType>

<phoneNumber>778-085-2109</phoneNumber> <personIdExternal>154</personIdExternal>

<isPrimary>t</isPrimary>

</PerPhone>

<PerPhone>

<phoneType>C</phoneType>

<phoneNumber>778-085-2109</phoneNumber> <personIdExternal>154</personIdExternal>

<isPrimary>f</isPrimary>

</PerPhone>

</PerPhone>


I tried below.

<xsl:template match="/Employee/PerPhone/PerPhone/phonetype[contains(text(),'H')]">

<xsl:if test="/Employee/PerPhone/PerPhone[contains(phoneType,'H')]">

<xsl:value-of select="$PhoneType_H"/> </xsl:if> </xsl:template> <xsl:template match="/Employee/PerPhone/PerPhone/phonetype[contains(text(),'C')]">

<xsl:if test="/Employee/PerPhone/PerPhone[contains(phoneType,'C')]"> <xsl:value-of select="$PhoneType_C"/>

</xsl:if>

</xsl:template


Reagrds,

Tibin

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Apr 02, 2017 at 10:35 AM

    Hello Tibin,

    Below code will do the same.

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="xml" indent="yes" />
        <xsl:template match="/">
            <PerPhone>
                <xsl:for-each select="//PerPhone/PerPhone">
                    <PerPhone>
                        <xsl:variable name="Var_PhoneType">
                            <xsl:value-of select="phoneType"/>                    
                        </xsl:variable>    
                        <phoneType>
                            <xsl:call-template name="PHONE_TYPE_LOOKUP">
                                <xsl:with-param name="PHONETYPE" select="$Var_PhoneType"/>
                            </xsl:call-template>
                        </phoneType>
                        <phoneNumber>
                            <xsl:value-of select="phoneNumber"/>                               
                        </phoneNumber>
                        <personIdExternal>
                            <xsl:value-of select="personIdExternal"/>
                        </personIdExternal>
                        <isPrimary>
                            <xsl:value-of select="isPrimary"/>
                        </isPrimary>
                    </PerPhone>
                </xsl:for-each>
            </PerPhone>
        </xsl:template>    
    
        <xsl:template name="PHONE_TYPE_LOOKUP">
            <xsl:param name="PHONETYPE"/>
            <xsl:choose>
                <xsl:when test="$PHONETYPE='H'">
                    <xsl:text>450</xsl:text>
                </xsl:when>
            </xsl:choose>        
            <xsl:choose>
                <xsl:when test="$PHONETYPE='C'">
                    <xsl:text>452</xsl:text>
                </xsl:when>
            </xsl:choose>
        </xsl:template>    
    </xsl:stylesheet>

    Regards

    Sriprasad Shivaram Bhat

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 02, 2017 at 02:41 PM

    input-xml.txtHello Sriprasad,

    Thank you for the technical input,

    Basically, I don't want to hardcode the value 450 and 452 in mapping,because those parameter values are coming dynamically, varies in DEV and PRD systems. I am filling the below values for 450 (PhoneType_H)and 452(PhoneType_C), How can I make use of this.Also I have other nodes as well in the XSLT .

    <xsl:param name="PhoneType_H"/>

    <xsl:param name="PhoneType_C"/>

    Attached the xslt and input and output xml I got.Please guide.

    Regards,

    Tibin

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Sriprasad Shivaram Bhat

      Hi Sriprasad,

      I am getting H and C 'internal code' values querying PICKLIST api from successfactors.

      I need to replace H and C values with those Internal code ..In dev for example , 450 and 452 explained in above post.

      Once I get this internal code values I am setting it in HCI content modifier property ( PhoneType_H and PhoneType_C) using groovy script.

      I am doing the same for employee class as below and Is working .Since we have multiple phone type's ( occurrence is 2) , I am unable to refer which occurrence is for H and which is for C in my input xml to replace the value dynamically .I hope you understood my problem.

      <xsl:template match="/Employee/EmpJob/EmpJob/employeeClass/text()">
      		<xsl:value-of select="$EmployeeClass"/>
      	</xsl:template>
      
      
      Reagrds,
      Tibin
  • avatar image
    Former Member
    Apr 05, 2017 at 07:31 PM

    Hi Sriprasad,

    I am getting H and C 'internal code' values querying PICKLIST api from successfactors.

    I need to replace H and C values with those Internal code ..In dev for example , 450 and 452 explained in above post.

    Once I get this internal code values I am setting it in HCI content modifier property ( PhoneType_H and PhoneType_C) using groovy script.

    I am doing the same for employee class as below and Is working .Since we have multiple phone type's ( occurrence is 2) , I am unable to refer which occurrence is for H and which is for C in my input xml to replace the value dynamically .I hope you understood my problem.

    <xsl:template match="/Employee/EmpJob/EmpJob/employeeClass/text()">
    		<xsl:value-of select="$EmployeeClass"/>
    	</xsl:template>
    
    
    Reagrds,
    Tibin
    Add comment
    10|10000 characters needed characters exceeded