I have a combined xml of 2 separate data sources - qualifications and report data. The report data xml section has job profile and certification ref ID. The qualifications xml section has job profile and multiple certification ref IDs associated with it. I am trying to generate a final output xml that should display the job profile ID and the certification ref ID from the report data xml section only when there is a matching job profile and certification ref ID in qualifications XML section. I tried using the xslt 3.0 accumulator - map function but haven't been able to use it as my knowledge is very basic.
Here are the details to the input file and the expected output file. Would appreciate any help around this issue.
INPUT FILE ->
<?xml version="1.0" encoding="utf-8"?>
<root>
<Qualifications>
<wd:Qualification_Equivalence_Rule xmlns:wd="urn:com.workday/bsvc"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<wd:Qualification_Equivalence_Rule_Reference>
<wd:ID wd:type="WID">c3b39ac5d3e2014bb44feeb7a60d7d04</wd:ID>
<wd:ID wd:type="Qualification_Equivalence_Rule">QUALIFICATION_EQUIVALENCE_RULE-3-563</wd:ID>
</wd:Qualification_Equivalence_Rule_Reference>
<wd:Qualification_Equivalence_Rule_Data>
<wd:ID>QUALIFICATION_EQUIVALENCE_RULE-3-563</wd:ID>
<wd:Qualification_Equivalence_Rule_Inactive>0</wd:Qualification_Equivalence_Rule_Inactive>
<wd:Job_Profile_Reference>
<wd:ID wd:type="WID">1117412e16800106d9c1c14c41031092</wd:ID>
<wd:ID wd:type="Job_Profile_ID">48084</wd:ID>
</wd:Job_Profile_Reference>
<wd:Condition_Rule_Data>
<wd:Condition_Rule_ID>CONDITION_RULE-3-1468</wd:Condition_Rule_ID>
<wd:Rule_Description>48084</wd:Rule_Description>
<wd:Condition_Item_Data>
<wd:Order>a</wd:Order>
<wd:And_Or_Operator_Reference>
<wd:ID wd:type="WID">da4e1c34446c11de98360015c5e6daf6</wd:ID>
<wd:ID wd:type="And_Or_Operator_Name">And</wd:ID>
</wd:And_Or_Operator_Reference>
<wd:Relational_Operator_Reference>
<wd:ID wd:type="WID">d5227566446c11de98360015c5e6daf6</wd:ID>
<wd:ID wd:type="Relational_Operator_Name">any in the selection list</wd:ID>
</wd:Relational_Operator_Reference>
<wd:Condition_Entry_Option_Reference>
<wd:ID wd:type="WID">da59516c446c11de98360015c5e6daf6</wd:ID>
<wd:ID wd:type="Condition_Entry_Option_Name">Value specified in this filter</wd:ID>
</wd:Condition_Entry_Option_Reference>
<wd:Source_External_Field_Reference>
<wd:ID wd:type="WID">2da3447d0426100005f7c3e752840110</wd:ID>
</wd:Source_External_Field_Reference>
<wd:Target_Instance_Reference>
<wd:ID wd:type="WID">f67d472cae95013c50ff3dec7a05bf66</wd:ID>
<wd:ID wd:type="Certification_ID">REEGT</wd:ID>
</wd:Target_Instance_Reference>
</wd:Condition_Item_Data>
</wd:Condition_Rule_Data>
</wd:Qualification_Equivalence_Rule_Data>
</wd:Qualification_Equivalence_Rule>
<wd:Qualification_Equivalence_Rule xmlns:wd="urn:com.workday/bsvc"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<wd:Qualification_Equivalence_Rule_Reference>
<wd:ID wd:type="WID">f67d472cae950122e67fdf1a04066965</wd:ID>
<wd:ID wd:type="Qualification_Equivalence_Rule">QUALIFICATION_EQUIVALENCE_RULE-6-357</wd:ID>
</wd:Qualification_Equivalence_Rule_Reference>
<wd:Qualification_Equivalence_Rule_Data>
<wd:ID>QUALIFICATION_EQUIVALENCE_RULE-6-357</wd:ID>
<wd:Qualification_Equivalence_Rule_Inactive>0</wd:Qualification_Equivalence_Rule_Inactive>
<wd:Job_Profile_Reference>
<wd:ID wd:type="WID">1117412e1680011e3e797b4c4103a890</wd:ID>
<wd:ID wd:type="Job_Profile_ID">47063</wd:ID>
</wd:Job_Profile_Reference>
<wd:Condition_Rule_Data>
<wd:Condition_Rule_ID>CONDITION_RULE-6-1043</wd:Condition_Rule_ID>
<wd:Rule_Description>47063</wd:Rule_Description>
<wd:Condition_Item_Data>
<wd:Order>a</wd:Order>
<wd:And_Or_Operator_Reference>
<wd:ID wd:type="WID">da4e1c34446c11de98360015c5e6daf6</wd:ID>
<wd:ID wd:type="And_Or_Operator_Name">And</wd:ID>
</wd:And_Or_Operator_Reference>
<wd:Relational_Operator_Reference>
<wd:ID wd:type="WID">d5227566446c11de98360015c5e6daf6</wd:ID>
<wd:ID wd:type="Relational_Operator_Name">any in the selection list</wd:ID>
</wd:Relational_Operator_Reference>
<wd:Condition_Entry_Option_Reference>
<wd:ID wd:type="WID">da59516c446c11de98360015c5e6daf6</wd:ID>
<wd:ID wd:type="Condition_Entry_Option_Name">Value specified in this filter</wd:ID>
</wd:Condition_Entry_Option_Reference>
<wd:Source_External_Field_Reference>
<wd:ID wd:type="WID">2da3447d0426100005f7c3e752840110</wd:ID>
</wd:Source_External_Field_Reference>
<wd:Target_Instance_Reference>
<wd:ID wd:type="WID">f67d472cae9501225db826ec7a057066</wd:ID>
<wd:ID wd:type="Certification_ID">SLP</wd:ID>
</wd:Target_Instance_Reference>
</wd:Condition_Item_Data>
<wd:Condition_Item_Data>
<wd:Order>b</wd:Order>
<wd:And_Or_Operator_Reference>
<wd:ID wd:type="WID">da4e1c34446c11de98360015c5e6daf6</wd:ID>
<wd:ID wd:type="And_Or_Operator_Name">And</wd:ID>
</wd:And_Or_Operator_Reference>
<wd:Relational_Operator_Reference>
<wd:ID wd:type="WID">d5227566446c11de98360015c5e6daf6</wd:ID>
<wd:ID wd:type="Relational_Operator_Name">any in the selection list</wd:ID>
</wd:Relational_Operator_Reference>
<wd:Condition_Entry_Option_Reference>
<wd:ID wd:type="WID">da59516c446c11de98360015c5e6daf6</wd:ID>
<wd:ID wd:type="Condition_Entry_Option_Name">Value specified in this filter</wd:ID>
</wd:Condition_Entry_Option_Reference>
<wd:Source_External_Field_Reference>
<wd:ID wd:type="WID">2da3447d0426100005f7c3e752840110</wd:ID>
</wd:Source_External_Field_Reference>
<wd:Target_Instance_Reference>
<wd:ID wd:type="WID">f67d472cae95015969f6ffeb7a05f465</wd:ID>
<wd:ID wd:type="Certification_ID">CCC-SLP</wd:ID>
</wd:Target_Instance_Reference>
</wd:Condition_Item_Data>
</wd:Condition_Rule_Data>
</wd:Qualification_Equivalence_Rule_Data>
</wd:Qualification_Equivalence_Rule>
<wd:Qualification_Equivalence_Rule xmlns:wd="urn:com.workday/bsvc"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<wd:Qualification_Equivalence_Rule_Reference>
<wd:ID wd:type="WID">f67d472cae9501e32555411f04061766</wd:ID>
<wd:ID wd:type="Qualification_Equivalence_Rule">QUALIFICATION_EQUIVALENCE_RULE-6-411</wd:ID>
</wd:Qualification_Equivalence_Rule_Reference>
<wd:Qualification_Equivalence_Rule_Data>
<wd:ID>QUALIFICATION_EQUIVALENCE_RULE-6-411</wd:ID>
<wd:Qualification_Equivalence_Rule_Inactive>0</wd:Qualification_Equivalence_Rule_Inactive>
<wd:Job_Profile_Reference>
<wd:ID wd:type="WID">1117412e168001250ea7f14c41031293</wd:ID>
<wd:ID wd:type="Job_Profile_ID">51227</wd:ID>
</wd:Job_Profile_Reference>
<wd:Condition_Rule_Data>
<wd:Condition_Rule_ID>CONDITION_RULE-6-1097</wd:Condition_Rule_ID>
<wd:Rule_Description>51227</wd:Rule_Description>
<wd:Condition_Item_Data>
<wd:Order>a</wd:Order>
<wd:And_Or_Operator_Reference>
<wd:ID wd:type="WID">da4e1c34446c11de98360015c5e6daf6</wd:ID>
<wd:ID wd:type="And_Or_Operator_Name">And</wd:ID>
</wd:And_Or_Operator_Reference>
<wd:Relational_Operator_Reference>
<wd:ID wd:type="WID">d5227566446c11de98360015c5e6daf6</wd:ID>
<wd:ID wd:type="Relational_Operator_Name">any in the selection list</wd:ID>
</wd:Relational_Operator_Reference>
<wd:Condition_Entry_Option_Reference>
<wd:ID wd:type="WID">da59516c446c11de98360015c5e6daf6</wd:ID>
<wd:ID wd:type="Condition_Entry_Option_Name">Value specified in this filter</wd:ID>
</wd:Condition_Entry_Option_Reference>
<wd:Source_External_Field_Reference>
<wd:ID wd:type="WID">2da3447d0426100005f7c3e752840110</wd:ID>
</wd:Source_External_Field_Reference>
<wd:Target_Instance_Reference>
<wd:ID wd:type="WID">f67d472cae95016d99f7feeb7a05f065</wd:ID>
<wd:ID wd:type="Certification_ID">BCBA</wd:ID>
</wd:Target_Instance_Reference>
</wd:Condition_Item_Data>
</wd:Condition_Rule_Data>
</wd:Qualification_Equivalence_Rule_Data>
</wd:Qualification_Equivalence_Rule>
<wd:Qualification_Equivalence_Rule xmlns:wd="urn:com.workday/bsvc"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<wd:Qualification_Equivalence_Rule_Reference>
<wd:ID wd:type="WID">f67d472cae95013dc439f7fc0306ba60</wd:ID>
<wd:ID wd:type="Qualification_Equivalence_Rule">QUALIFICATION_EQUIVALENCE_RULE-6-2</wd:ID>
</wd:Qualification_Equivalence_Rule_Reference>
<wd:Qualification_Equivalence_Rule_Data>
<wd:ID>QUALIFICATION_EQUIVALENCE_RULE-6-2</wd:ID>
<wd:Qualification_Equivalence_Rule_Inactive>0</wd:Qualification_Equivalence_Rule_Inactive>
<wd:Job_Profile_Reference>
<wd:ID wd:type="WID">1117412e168001d24f02c14c41030c92</wd:ID>
<wd:ID wd:type="Job_Profile_ID">48082</wd:ID>
</wd:Job_Profile_Reference>
<wd:Condition_Rule_Data>
<wd:Condition_Rule_ID>CONDITION_RULE-6-f67d472cae9501a42c52f7fc0306bb60</wd:Condition_Rule_ID>
<wd:Rule_Description>48082</wd:Rule_Description>
<wd:Condition_Item_Data>
<wd:Order>a</wd:Order>
<wd:And_Or_Operator_Reference>
<wd:ID wd:type="WID">da4e1c34446c11de98360015c5e6daf6</wd:ID>
<wd:ID wd:type="And_Or_Operator_Name">And</wd:ID>
</wd:And_Or_Operator_Reference>
<wd:Relational_Operator_Reference>
<wd:ID wd:type="WID">d5227566446c11de98360015c5e6daf6</wd:ID>
<wd:ID wd:type="Relational_Operator_Name">any in the selection list</wd:ID>
</wd:Relational_Operator_Reference>
<wd:Condition_Entry_Option_Reference>
<wd:ID wd:type="WID">da59516c446c11de98360015c5e6daf6</wd:ID>
<wd:ID wd:type="Condition_Entry_Option_Name">Value specified in this filter</wd:ID>
</wd:Condition_Entry_Option_Reference>
<wd:Source_External_Field_Reference>
<wd:ID wd:type="WID">2da3447d0426100005f7c3e752840110</wd:ID>
</wd:Source_External_Field_Reference>
<wd:Target_Instance_Reference>
<wd:ID wd:type="WID">f67d472cae9501f92ccd15ec7a053966</wd:ID>
<wd:ID wd:type="Certification_ID">CBAP</wd:ID>
</wd:Target_Instance_Reference>
<wd:Target_Instance_Reference>
<wd:ID wd:type="WID">f67d472cae9501f92ccd15ec7a053967</wd:ID>
<wd:ID wd:type="Certification_ID">PMI-PBA</wd:ID>
</wd:Target_Instance_Reference>
</wd:Condition_Item_Data>
</wd:Condition_Rule_Data>
</wd:Qualification_Equivalence_Rule_Data>
</wd:Qualification_Equivalence_Rule>
</Qualifications>
<wd:Report_Data xmlns:wd="urn:com.workday.report/Worker_Certs">
<wd:Report_Entry>
<wd:Worker wd:Descriptor="Tom Hanks">
<wd:ID wd:type="WID">b0d4df2a9611018f7b47c85f110d8230</wd:ID>
<wd:ID wd:type="Employee_ID">770077</wd:ID>
</wd:Worker>
<wd:Job_Profile wd:Descriptor="48082 - Business Analyst">
<wd:ID wd:type="WID">1117412e168001d24f02c14c41030c92</wd:ID>
<wd:ID wd:type="Job_Profile_ID">48082</wd:ID>
</wd:Job_Profile>
<wd:Certification wd:Descriptor="CBAP - Certified Business Analyst Professional">
<wd:ID wd:type="WID">b0d4df2a96110179f7d634a5310de855</wd:ID>
</wd:Certification>
<wd:Certification_-_Selected_group>
<wd:referenceID>CBAP</wd:referenceID>
</wd:Certification_-_Selected_group>
<wd:Cert_Number>2100</wd:Cert_Number>
<wd:Issuer>IIBA</wd:Issuer>
<wd:Expiration_Date>2023-12-31-08:00</wd:Expiration_Date>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:Worker wd:Descriptor="Russel Crowe">
<wd:ID wd:type="WID">b0d4df2a961101bdb3b6ae7b120dd829</wd:ID>
<wd:ID wd:type="Employee_ID">77088</wd:ID>
</wd:Worker>
<wd:Job_Profile wd:Descriptor="51227 - Board Certified Behav Analyst">
<wd:ID wd:type="WID">1117412e168001250ea7f14c41031293</wd:ID>
<wd:ID wd:type="Job_Profile_ID">51227</wd:ID>
</wd:Job_Profile>
<wd:Certification wd:Descriptor="Board Certified Behavior Analyst - Behavior Analyst Certification Board">
<wd:ID wd:type="WID">e27b2aff960c01a0b7f176c5b201122a</wd:ID>
</wd:Certification>
<wd:Certification_-_Selected_group>
<wd:referenceID>BCBA</wd:referenceID>
</wd:Certification_-_Selected_group>
<wd:Cert_Number>1/11/8595</wd:Cert_Number>
<wd:Issuer>Behavior Analyst Certification Board</wd:Issuer>
<wd:Expiration_Date>2023-05-31-07:00</wd:Expiration_Date>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:Worker wd:Descriptor="Mel Gibson">
<wd:ID wd:type="WID">b0d4df2a961101bdb3b6ae7b120dd830</wd:ID>
<wd:ID wd:type="Employee_ID">77099</wd:ID>
</wd:Worker>
<wd:Job_Profile wd:Descriptor="47063 - Manager Speech / Language Pathology">
<wd:ID wd:type="WID">1117412e168001250ea7f14c41031293</wd:ID>
<wd:ID wd:type="Job_Profile_ID">47063</wd:ID>
</wd:Job_Profile>
<wd:Certification wd:Descriptor="Board Certified Behavior Analyst - Behavior Analyst Certification Board">
<wd:ID wd:type="WID">e27b2aff960c01a0b7f176c5b201122a</wd:ID>
</wd:Certification>
<wd:Certification_-_Selected_group>
<wd:referenceID>SLP</wd:referenceID>
</wd:Certification_-_Selected_group>
<wd:Cert_Number>112233</wd:Cert_Number>
<wd:Issuer>PSLB</wd:Issuer>
<wd:Expiration_Date>20232-12-31-08:00</wd:Expiration_Date>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:Worker wd:Descriptor="Robert Downey Jr.">
<wd:ID wd:type="WID">b0d4df2a961101bdb3b6ae7b120dd830</wd:ID>
<wd:ID wd:type="Employee_ID">88000</wd:ID>
</wd:Worker>
<wd:Job_Profile wd:Descriptor="47063 - Manager Speech / Language Pathology">
<wd:ID wd:type="WID">1117412e168001250ea7f14c41031293</wd:ID>
<wd:ID wd:type="Job_Profile_ID">48084</wd:ID>
</wd:Job_Profile>
<wd:Certification wd:Descriptor="Board Certified Behavior Analyst - Behavior Analyst Certification Board">
<wd:ID wd:type="WID">e27b2aff960c01a0b7f176c5b201122a</wd:ID>
</wd:Certification>
<wd:Certification_-_Selected_group>
<wd:referenceID>EEG</wd:referenceID>
</wd:Certification_-_Selected_group>
<wd:Cert_Number>112244</wd:Cert_Number>
<wd:Issuer>EEG</wd:Issuer>
<wd:Expiration_Date>20232-11-30-08:00</wd:Expiration_Date>
</wd:Report_Entry>
</wd:Report_Data>
</root>
EXPECTED OUTPUT FILE ->
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:map="http://www.w3.org/2005/xpath-functions/map"
xmlns:wd="urn:com.workday/bsvc"
xmlns:wd2="urn:com.workday.report/Worker_Certs">
<Worker_Cert>
<Emp_ID>770077</Emp_ID>
<Job_Profile_ID>48082</Job_Profile_ID>
<Cref>CBAP</Cref>
<Cert_Number>2100</Cert_Number>
<Expiration_Dt>2023-12-31</Expiration_Dt>
<QCert>CBAP</QCert>
</Worker_Cert>
<Worker_Cert>
<Emp_ID>77088</Emp_ID>
<Job_Profile_ID>51227</Job_Profile_ID>
<Cref>BCBA</Cref>
<Cert_Number>1/11/8595</Cert_Number>
<Expiration_Dt>2023-05-31</Expiration_Dt>
<QCert>BCBA</QCert>
</Worker_Cert>
<Worker_Cert>
<Emp_ID>77099</Emp_ID>
<Job_Profile_ID>47063</Job_Profile_ID>
<Cref>SLP</Cref>
<Cert_Number>112233</Cert_Number>
<Expiration_Dt>20232-12-3</Expiration_Dt>
<QCert>SLP</QCert>
</Worker_Cert>
</root>
CodePudding user response:
A key based approach is e.g.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xpath-default-namespace="urn:com.workday/bsvc"
xmlns:wd="urn:com.workday/bsvc"
exclude-result-prefixes="#all"
expand-text="yes"
version="3.0">
<xsl:mode on-no-match="shallow-skip"/>
<xsl:template match="/root">
<xsl:copy copy-namespaces="no">
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:output method="xml" indent="yes"/>
<xsl:key name="ref"
match="Qualification_Equivalence_Rule_Data/Condition_Rule_Data/Condition_Item_Data/Target_Instance_Reference/ID[@wd:type = 'Certification_ID']"
use="ancestor::Qualification_Equivalence_Rule_Data/Job_Profile_Reference/ID[@wd:type = 'Job_Profile_ID'], ."
composite="yes"/>
<xsl:template xpath-default-namespace="urn:com.workday.report/Worker_Certs"
xmlns:wd="urn:com.workday.report/Worker_Certs"
match="Report_Entry[key('ref', (Job_Profile/ID[@wd:type = 'Job_Profile_ID'], Certification_-_Selected_group/referenceID))]">
<Worker_Cert>
<Emp_ID>{Worker/ID[@wd:type = 'Employee_ID']}</Emp_ID>
<Job_Profile_ID>{Job_Profile/ID[@wd:type = 'Job_Profile_ID']}</Job_Profile_ID>
<Cref>{key('ref', (Job_Profile/ID[@wd:type = 'Job_Profile_ID'], Certification_-_Selected_group/referenceID))}</Cref>
</Worker_Cert>
</xsl:template>
</xsl:stylesheet>
Streaming should do with e.g.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:map="http://www.w3.org/2005/xpath-functions/map"
xpath-default-namespace="urn:com.workday/bsvc"
xmlns:wd="urn:com.workday/bsvc"
exclude-result-prefixes="#all"
expand-text="yes"
version="3.0">
<xsl:mode on-no-match="shallow-skip" use-accumulators="#all" streamable="yes"/>
<xsl:accumulator name="jpid" as="xs:string?" initial-value="()" streamable="yes">
<xsl:accumulator-rule match="Qualification_Equivalence_Rule_Data" select="()"/>
<xsl:accumulator-rule match="Qualification_Equivalence_Rule_Data/Job_Profile_Reference/ID[@wd:type = 'Job_Profile_ID']/text()" select="string()"/>
</xsl:accumulator>
<xsl:accumulator name="certs" as="map(xs:string, xs:string)" initial-value="map{}" streamable="yes">
<xsl:accumulator-rule match="Qualification_Equivalence_Rule_Data/Condition_Rule_Data/Condition_Item_Data/Target_Instance_Reference/ID[@wd:type = 'Certification_ID']/text()"
select="let $jpid := accumulator-before('jpid'),
$key := $jpid || '|' || string()
return map:put($value, $key, string())"/>
</xsl:accumulator>
<xsl:template match="/root">
<xsl:copy copy-namespaces="no">
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="Report_Entry" xpath-default-namespace="urn:com.workday.report/Worker_Certs">
<xsl:apply-templates select="copy-of()" mode="grounded"/>
</xsl:template>
<xsl:mode name="grounded" on-no-match="shallow-skip"/>
<xsl:template mode="grounded"
xpath-default-namespace="urn:com.workday.report/Worker_Certs"
xmlns:wd="urn:com.workday.report/Worker_Certs"
match="Report_Entry[map:contains(accumulator-before('certs'), Job_Profile/ID[@wd:type = 'Job_Profile_ID'] || '|' || Certification_-_Selected_group/referenceID)]">
<Worker_Cert>
<Emp_ID>{Worker/ID[@wd:type = 'Employee_ID']}</Emp_ID>
<Job_Profile_ID>{Job_Profile/ID[@wd:type = 'Job_Profile_ID']}</Job_Profile_ID>
<Cref>{accumulator-before('certs')(Job_Profile/ID[@wd:type = 'Job_Profile_ID'] || '|' || Certification_-_Selected_group/referenceID)}</Cref>
</Worker_Cert>
</xsl:template>
</xsl:stylesheet>