0

** I have XML file as below **

<mdti:Input xmlns:mdti="urn:com.workday/multiDocumentTransform/Input">
    <mdti:Files xmlns:mdti="urn:com.workday/multiDocumentTransform/Input">
        <mdti:EventFiles>
          <mdti:File mdti:filename="first.xml" mdti:contentType="text/xml">
            <wd:Report_Data xmlns:wd="urn:com.workday/bsvc">
                <wd:Report_Entry>
                    <wd:key>1234</wd:key>
                    <wd:comp>ABC</wd:comp>
                    <wd:asof>2021-03-24T04:59:32.179-07:00</wd:asof>
                    <wd:emplid>33333333</wd:emplid>
                    <wd:worker_type>EMP</wd:worker_type>
                    <wd:emp_type>Regular</wd:emp_type>
                    <wd:orig_hire_dt>2021-11-27</wd:orig_hire_dt>
                    <wd:rehire_dt>2019-04-01</wd:rehire_dt>
                    <wd:home_host_class>M</wd:home_host_class>
                    <wd:service_dt>2014-11-27</wd:service_dt>
                </wd:Report_Entry>
            </wd:Report_Data>
        </mdti:File>
        <mdti:File mdti:filename="second.xml" mdti:contentType="text/xml">
            <wd:Report_Data xmlns:wd="urn:com.workday/bsvc">
                <wd:Report_Entry>
                    <wd:key>1234</wd:key>
                    <wd:supervisor_lname>xyz</wd:supervisor_lname>
                    <wd:hr_status>A</wd:hr_status>
                    <wd:hr_status_descr>Active</wd:hr_status_descr>
                    <wd:empl_status>A</wd:empl_status>
                    <wd:empl_status_descr>Active</wd:empl_status_descr>
                    <wd:ben_status>A</wd:ben_status>
                    <wd:home_address_change_dt>2019-07-30</wd:home_address_change_dt>
                    <wd:location>444</wd:location>
                    <wd:location_descr>Ind</wd:location_descr>
                </wd:Report_Entry>
            </wd:Report_Data>
        </mdti:File>
    </mdti:EventFiles>
</mdti:Files>
</mdti:Input>

** I need output as below where <wd:key> is common in both nodes(first.xml and second.xml). I have to join two nodes and get few fields from first.xml and other from second.xml**

<data>
  <key>1234</key>
  <emplid>33333333</emplid>
  <emp_type>Regular</emp_type>
  <supervisor_lname>xyz</supervisor_lname>
  <hr_status>A</hr_status>
  <location>444</location>
</data>

XSLT I have used is as below . I am using KEY concept but output is not as expected. Let me know if something is not correct with the code

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:mdti="urn:com.workday/multiDocumentTransform/Input"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:wd="urn:com.workday/bsvc"
    exclude-result-prefixes="#all">
    
    <xsl:variable name="val" select="mdti:Input/mdti:Files/mdti:EventFiles/mdti:File/wd:Report_Data/wd:Report_Entry/wd:key[mdti:filename='first.xml']" />
     
   
    <!-- identity transform -->
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
    
    <xsl:template match="wd:key">
        <xsl:copy>
            <xsl:apply-templates/>
            <column name="wd:key">
                <xsl:value-of select="$val" />
            </column>
        </xsl:copy>
    </xsl:template>
    
</xsl:stylesheet>



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:mdti="urn:com.workday/multiDocumentTransform/Input"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:wd="urn:com.workday/bsvc"
    exclude-result-prefixes="#all">
    
    <xsl:key name="share" match="mdti:Input/mdti:Files/mdti:EventFiles/mdti:File/wd:Report_Data/wd:Report_Entry" use="mdti:Input/mdti:Files/mdti:EventFiles/mdti:File/wd:Report_Data/wd:Report_Entry/wd:key"/> 
   
    <xsl:template match="/">        
        <ok><xsl:value-of select="123"/></ok>        
        <ok2>            
            <xsl:copy-of select="key('share', wd:key)/wd:hr_status"/>            
        </ok2>
    </xsl:template>    
</xsl:stylesheet>
Pravin
  • 3
  • 3
  • Use a **key**: https://www.w3.org/TR/1999/REC-xslt-19991116/#key – michael.hor257k Mar 25 '21 at 11:35
  • Can you help me with the code please. It has file name in it (mdti:filename="first.xml" ) – Pravin Mar 25 '21 at 11:49
  • No, I will not write your code for you. But there are many code examples using a key on these pages. – michael.hor257k Mar 25 '21 at 11:56
  • I understand. I am not sure how to use it in case we have file name as one of the XML attribute. I my case I have to use key against filename and not node – Pravin Mar 25 '21 at 12:32
  • That file name is just the value of an attribute of an element so where do you struggle to select an element based on an attribute condition? – Martin Honnen Mar 25 '21 at 12:34
  • I have added my XSLT which I am using. To let you know I am very new to XSLT . – Pravin Mar 25 '21 at 12:40
  • You have not defined a key and you are not using it. – michael.hor257k Mar 25 '21 at 12:42
  • I have added new xslt.. I something wrong in it as I am not getting any expected data – Pravin Mar 25 '21 at 13:22
  • 1
    If your aim is to produce that `data` element with values from two different parts of course start with a working sample producing it with the data from one part. Once you have, add a key and use it to follow the cross-reference. So far your attempts seen to be unrelated to the output you have shown as the wanted result. – Martin Honnen Mar 25 '21 at 13:38

0 Answers0