xmlxslt-2.0

Merge xml input from an external variable into another xml input using xslt


I need to merge an xml input that I stored in a variable with another xml input message using xslt.

XML Input:

<?xml version="1.0" encoding="utf-8"?>
<aggregatedd>
  <cal:stack xmlns:cal="urn:calabrio">
    <cal:timeoff>
      <cal:person>473937f5-9222-4187-9d30-afe000c44702</cal:person>
      <cal:date>2024-11-01</cal:date>
      <cal:timeofftype>USA_ABS002</cal:timeofftype>
      <cal:hours>4.50</cal:hours>
    </cal:timeoff>
  </cal:stack>
  <wd:TimeOff-Stack xmlns:wd="urn:com.workday.report/CR_INT_Calabrio_Workday_TimeOff_by_Time_Period">
    <wd:TimeOff-Entry>
      <wd:WID>10636</wd:WID>
      <wd:wd-key>20241107USAABS002800</wd:wd-key>
      <wd:Date>2024-11-07</wd:Date>
      <wd:Timeoff>USA_ABS002</wd:Timeoff>
      <wd:Hours>8.00</wd:Hours>
      <wd:EntryID>TIME_OFF_ENTRY-6-1136743</wd:EntryID>
    </wd:TimeOff-Entry>
  </wd:TimeOff-Stack>
  <wd:TimeOff-Stack xmlns:wd="urn:com.workday.report/CR_Calabrio_TO_Eligible_Worker_Report">
    <wd:TimeOff-Entry>
      <wd:WID>10636</wd:WID>
      <wd:wd-key>20241107USAABS002800</wd:wd-key>
      <wd:Date>2024-11-07</wd:Date>
      <wd:Timeoff>USA_ABS002</wd:Timeoff>
      <wd:Hours>8.00</wd:Hours>
      <wd:EntryID>TIME_OFF_ENTRY-6-1136743</wd:EntryID>
    </wd:TimeOff-Entry>
  </wd:TimeOff-Stack>
</aggregatedd>

the external variable contains another xml message

something like XML Input 2(in a extrenal variable):

  <wd:Report_Data xmlns:wd="urn:com.workday.report/CR_Calabrio_TO_Eligible_Worker_Report">
    <wd:Report_Entry>
      <wd:WID>10636</wd:WID>
      <wd:Wiser_ID>10636</wd:Wiser_ID>
      <wd:Person_Id>473937f5-9222-4187-9d30-afe000c44702</wd:Person_Id>
    </wd:Report_Entry>
    <wd:Report_Entry>
      <wd:WID>10636</wd:WID>
      <wd:Wiser_ID>2222</wd:Wiser_ID>
      <wd:Person_Id>11111-22222-4187-9d30-afe000c44702</wd:Person_Id>
    </wd:Report_Entry>
  </wd:Report_Data>

I have looked at similar posts(they needed to merge them under matching groups) and tried this xslt as I simply want to add this into my main aggregator node and use later for further processing. The xslt is failing. I cannot really process this in oxygen as the variable is external(part of my overall studio assembly). XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:wd="urn:com.workday.report/CR_INT_Calabrio_Workday_TimeOff_by_Time_Period
    CR_Calabrio_TO_Eligible_Worker_Report"
    
    xmlns:cal="urn:calabrio"
    exclude-result-prefixes="#all">
    <xsl:output method="xml" indent = "yes"  />
    <xsl:param name="wdwiserreport"/>
    <xsl:variable name="report-doc" select="doc($wdwiserreport)"/>
    
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>
    
    <xsl:template match="aggregatedd">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()[not(self::cal:stack)] |@* | node()[not(self::wd:TimeOff-Stack)]" />
            <xsl:apply-templates select="copy-of($report-doc)" />
        </xsl:copy>
    </xsl:template>
    
    
</xsl:stylesheet>

I have referred to similar questions posted here and tried the xslt I shared above but receiving errors. Please advise how I can use an external variable and merge that into my main xml. Thank you. Appreciate any inputs.

I simply would like to add the variable output to my aggregator node to be further processed Desired Output:

<?xml version="1.0" encoding="utf-8"?>
<aggregatedd>
<wd:Report_Data xmlns:wd="urn:com.workday.report/CR_Calabrio_TO_Eligible_Worker_Report">
        <wd:Report_Entry>
          <wd:WID>10636</wd:WID>
          <wd:Wiser_ID>10636</wd:Wiser_ID>
          <wd:Person_Id>473937f5-9222-4187-9d30-afe000c44702</wd:Person_Id>
        </wd:Report_Entry>
        <wd:Report_Entry>
          <wd:WID>10636</wd:WID>
          <wd:Wiser_ID>2222</wd:Wiser_ID>
          <wd:Person_Id>11111-22222-4187-9d30-afe000c44702</wd:Person_Id>
        </wd:Report_Entry>
      </wd:Report_Data>
<cal:stack xmlns:cal="urn:calabrio">
   <cal:timeoff>
      <cal:person>473937f5-9222-4187-9d30-afe000c44702</cal:person>
      <cal:date>2024-11-01</cal:date>
      <cal:timeofftype>USA_ABS002</cal:timeofftype>
      <cal:hours>4.50</cal:hours>
   </cal:timeoff>
</cal:stack>
   <wd:TimeOff-Stack xmlns:wd="urn:com.workday.report/CR_INT_Calabrio_Workday_TimeOff_by_Time_Period">
      <wd:TimeOff-Entry>
         <wd:WiserID>10636</wd:WiserID>
         <wd:wd-key>20241107USAABS002800</wd:wd-key>
         <wd:Date>2024-11-07</wd:Date>
         <wd:Timeoff>USA_ABS002</wd:Timeoff>
         <wd:Hours>8.00</wd:Hours>
         <wd:EntryID>TIME_OFF_ENTRY-6-1136743</wd:EntryID>
      </wd:TimeOff-Entry>
   </wd:TimeOff-Stack>
   <wd:TimeOff-Stack xmlns:wd="urn:com.workday.report/CR_Calabrio_TO_Eligible_Worker_Report">
<wd:TimeOff-Entry>
<wd:WiserID>10636</wd:WiserID>
<wd:wd-key>20241107USAABS002800</wd:wd-key>
<wd:Date>2024-11-07</wd:Date>
<wd:Timeoff>USA_ABS002</wd:Timeoff>
<wd:Hours>8.00</wd:Hours>
<wd:EntryID>TIME_OFF_ENTRY-6-1136743</wd:EntryID>
</wd:TimeOff-Entry>
</wd:TimeOff-Stack></aggregatedd>

Solution

  • It seems

    <xsl:template match="aggregatedd">
      <xsl:copy>
        <xsl:copy-of select="$report-doc, node()"/>
      </xsl:copy>
    </xsl:template>
    

    would suffice to create the now posted desired result.