Skip to Content
author's profile photo Former Member
Former Member

Need Help in XSLT Code.

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

Target.xml (459 B)
Source.xml (614 B)
Capture.JPG (97.6 kB)
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Posted on Sep 03, 2013 at 08:09 AM

    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


    Target.xml (627 B)
    Source.xml (749 B)
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 03, 2013 at 08:00 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 03, 2013 at 06:44 AM

    I wonder why you need XSLT if

    this can be easily solve with Java Mapping or even with graphical node functions
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 03, 2013 at 06:47 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 03, 2013 at 08:11 AM

    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-ff8045bdd37d?overridelayout=true

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.