cancel
Showing results for 
Search instead for 
Did you mean: 

Need Help in XSLT Code.

Former Member
0 Kudos

Hi,

I have never done XSLT. So experts need your help.

Interface is related to HR - Job Application Data

My Source and Target XML is in Screenshot  : -

also i have uploaded the source and target XML for your reference as attachment .

Kindly help me in writting XSLT or if any one can provide me XSLT for this .

I now this can be easily solve with Java Mapping or even with graphical node functions but i need XSLT only.

Regards

Prabhat Sharma

Accepted Solutions (0)

Answers (5)

Answers (5)

sbhutani1
Contributor
0 Kudos

Here is a quick guide to basic XSLT Tags for your reference....It will be helpful in writing XSLT mapping.

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/000ee4d0-be91-2d10-8aaf-ff8045bdd...

I use Stylus Studio in my project for doing XSLT related stuff....its very useful and have lots of options for mapping. Just feed your source and target structure and do the graphical mapping as per your requirement.

Its available for free with a 15 days trial.

http://www.stylusstudio.com/xml_download.html

peter_wallner2
Active Contributor
0 Kudos

I agree with you Sumit, we are using Oxygen here. Also a good resource for questions on XSLT is: http://www.stackoverflow.com

Best regards,

Peter

peter_wallner2
Active Contributor
0 Kudos

Hello Prabhat Sharma,

You could also work with keys and do a so called "hierarchical grouping" on your source XML(your source and your target are not valid by the way. I attached corrected versions):

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

    version="1.0">

    <xsl:output method="xml" indent="yes"/>

    <xsl:key name="fNamelName" match="Application" use="concat(FName,'|',LName)"/>

    <!-- define which elements are unique -->

    <xsl:template match="Header">

        <xsl:variable name="uniqueTransactions" select="Application[generate-id()=generate-id(key('fNamelName',concat(FName,'|',LName))[1])]"/>

        <Header>

            <xsl:apply-templates select="$uniqueTransactions" mode="group"/>

        </Header>       

    </xsl:template>

    <!-- create the unique groups -->

    <xsl:template match="Application" mode="group">

        <Application>

            <xsl:copy-of select="FName"/>

            <xsl:copy-of select="LName"/>

            <xsl:copy-of select="CID"/>

            <JoiningLocation>

                <xsl:apply-templates select="key('fNamelName', concat(FName,'|',LName))" mode="item"/>

            </JoiningLocation>

        </Application>

    </xsl:template>

    <!-- write the item content into each group; this template is called by the two templates before -->

    <xsl:template match="Application" mode="item">

           <xsl:copy-of select="child::JoiningPreferedCity"/>

    </xsl:template>

</xsl:stylesheet>

Best regards,

Peter

Former Member
0 Kudos

Hello,

Depending upon the first and last name pairs i am splitting the records, so if u want u can enhance below XSLT

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://MappingTechnique">

   <xsl:template match="/">

      <MT>

         <xsl:for-each select="//Application">

            <xsl:sort select="concat(FName,LName)"/>

            <xsl:if test="not(FName = preceding-sibling::Application/FName and LName = preceding-sibling::Application/LName )">

               <Application>

                  <FName>

                     <xsl:value-of select="FName"/>

                  </FName>

                  <LName>

                     <xsl:value-of select="LName"/>

                  </LName>

                  <persons>

                     <xsl:call-template name="process_items">

                        <xsl:with-param name="items" select="concat(FName,LName)"/>

                     </xsl:call-template>

                  </persons>

               </Application>

            </xsl:if>

         </xsl:for-each>

      </MT>

   </xsl:template>

   <xsl:template name="process_items">

      <xsl:param name="items"/>

      <xsl:for-each select="//Application">

         <xsl:if test="($items = concat(FName,LName))">

            <person>

               <xsl:value-of select="JoiningPreferedCity"/>

            </person>

         </xsl:if>

      </xsl:for-each>

   </xsl:template>

</xsl:stylesheet>

Thanks

Amit Srivastava

JaySchwendemann
Active Contributor
0 Kudos

Hi,

have a look at the following commands

<xsl:template match="xPath to the location in your XML, where your key (probably CID) resides">

<xsl:variable name="yourVariable" select="xPath to your preffered key (probably CID)"/>

<xsl:apply-templates select="xPath to the location in your XML, where your key (probably CID) resides[keyname = $yourVariable"/>

HTH

Cheers

Jens

Former Member
0 Kudos

I wonder why you need XSLT if

this can be easily solve with Java Mapping or even with graphical node functions