Reputation: 3
my accumulator map when queried always returns just the last element only regardless of a match. The desired behaviour of my xslt is for the cal:timeoff nodes, it needs to match up person id element with my map that refers the person id and wiser id elements within report data node and return the wiser id.
Input XML
<?xml version="1.0" encoding="utf-8"?>
<AggregatedData xmlns:wkd="urn:Workday_timeoff_Extract" xmlns:cal="urn:calabrio"
xmlns:wd="urn:com.workday.report/CR_Calabrio_TO_Eligible_Worker_Report">
<wd:Report_Data>
<wd:Report_Entry>
<wd:Person_Id>473937f5922241879d30afe000c44702</wd:Person_Id>
<wd:Wiser_ID>10636</wd:Wiser_ID>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:Person_Id/>
<wd:Wiser_ID>EE1111</wd:Wiser_ID>
</wd:Report_Entry>
</wd:Report_Data>
<cal:stack>
<cal:timeoff>
<cal:person>473937f5922241879d30afe000c44702</cal:person>
<cal:key>20241101USAABS002450</cal:key>
<cal:date>2024-11-01</cal:date>
<cal:timeofftype>USA_ABS002</cal:timeofftype>
<cal:hours>4.50</cal:hours>
</cal:timeoff>
</cal:stack>
<wkd:TimeOff-Stack>
<wkd:TimeOff-Entry>
<wkd:WiserID>10636</wkd:WiserID>
<wkd:wd-key>20241107USAABS002800</wkd:wd-key>
<wkd:Date>2024-11-07</wkd:Date>
<wkd:Timeoff>USA_ABS002</wkd:Timeoff>
<wkd:Hours>8.00</wkd:Hours>
<wkd:EntryID>TIME_OFF_ENTRY-6-1136743</wkd:EntryID>
</wkd:TimeOff-Entry>
</wkd:TimeOff-Stack>
</AggregatedData>
My Xslt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:wkd="urn:Workday_timeoff_Extract"
xmlns:map="http://www.w3.org/2005/xpath-functions/map"
xmlns:cal="urn:calabrio"
xmlns:wd="urn:com.workday.report/CR_Calabrio_TO_Eligible_Worker_Report"
exclude-result-prefixes="#all">
<xsl:output method="xml" indent = "yes" />
<xsl:mode streamable="no" on-no-match="shallow-copy" use-accumulators="calpersonids idmap"/>
<xsl:accumulator name="calpersonids" as="xs:string" initial-value="''" streamable="no">
<xsl:accumulator-rule match="wd:Person_Id/text()" select="normalize-space()"/>
</xsl:accumulator>
<xsl:accumulator name="idmap" as="map(xs:string,xs:string)" initial-value="map{}" streamable="no">
<xsl:accumulator-rule match="wd:Wiser_ID/text()" select="map:put($value, accumulator-before('calpersonids'),normalize-space())"/>
</xsl:accumulator>
<xsl:template match="AggregatedData">
<xsl:apply-templates select="copy-of(cal:stack/cal:timeoff)"/>
</xsl:template>
<xsl:template match="cal:timeoff">
<cal:timeoff>
<cal:wiserid><xsl:value-of select="accumulator-before('idmap')(cal:person)"/></cal:wiserid>
<cal:personid><xsl:value-of select="cal:person"/></cal:personid>
<cal:key><xsl:value-of select="cal:key"/></cal:key>
<cal:date><xsl:value-of select="cal:date"/></cal:date>
<cal:timeofftype><xsl:value-of select="cal:timeofftype"/></cal:timeofftype>
<cal:hours><xsl:value-of select="cal:hours"/></cal:hours>
</cal:timeoff>
</xsl:template>
</xsl:stylesheet>
Current Output
<?xml version="1.0" encoding="UTF-8"?>
<cal:timeoff xmlns:cal="urn:calabrio">
<cal:wiserid>EE1111</cal:wiserid>
<cal:personid>473937f5922241879d30afe000c44702</cal:personid>
<cal:key>20241101USAABS002450</cal:key>
<cal:date>2024-11-01</cal:date>
<cal:timeofftype>USA_ABS002</cal:timeofftype>
<cal:hours>4.50</cal:hours>
</cal:timeoff>
Desired output
<?xml version="1.0" encoding="UTF-8"?>
<cal:timeoff xmlns:cal="urn:calabrio">
<cal:wiserid>10636</cal:wiserid>
<cal:key>20241101USAABS002450</cal:key>
<cal:date>2024-11-01</cal:date>
<cal:timeofftype>USA_ABS002</cal:timeofftype>
<cal:hours>4.50</cal:hours>
</cal:timeoff>
Please advise what is wrong with my xslt. The approach has worked for me in the past but just not working with this one. Thanks in advance.
Upvotes: 0
Views: 19
Reputation: 3
I figured that my input xml must always have the person id element populated and not be empty. So I trimmed by input xml itself to only return output when person id exists . This helped by xslt work!
Basically my xml input now looks something like this, always has person id with a value
<?xml version="1.0" encoding="utf-8"?>
<AggregatedData xmlns:wkd="urn:Workday_timeoff_Extract" xmlns:cal="urn:calabrio"
xmlns:wd="urn:com.workday.report/CR_Calabrio_TO_Eligible_Worker_Report">
<wd:Report_Data>
<wd:Report_Entry>
<wd:Person_Id>473937f5922241879d30afe000c44702</wd:Person_Id>
<wd:Wiser_ID>10636</wd:Wiser_ID>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:Person_Id>47393711111</wd:Person_Id>
<wd:Wiser_ID>EE1111</wd:Wiser_ID>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:Person_Id>2222222</wd:Person_Id>
<wd:Wiser_ID>EE1111</wd:Wiser_ID>
</wd:Report_Entry>
</wd:Report_Data>
<cal:stack>
<cal:timeoff>
<cal:person>473937f5922241879d30afe000c44702</cal:person>
<cal:key>20241101USAABS002450</cal:key>
<cal:date>2024-11-01</cal:date>
<cal:timeofftype>USA_ABS002</cal:timeofftype>
<cal:hours>4.50</cal:hours>
</cal:timeoff>
</cal:stack>
<wkd:TimeOff-Stack>
<wkd:TimeOff-Entry>
<wkd:WiserID>10636</wkd:WiserID>
<wkd:wd-key>20241107USAABS002800</wkd:wd-key>
<wkd:Date>2024-11-07</wkd:Date>
<wkd:Timeoff>USA_ABS002</wkd:Timeoff>
<wkd:Hours>8.00</wkd:Hours>
<wkd:EntryID>TIME_OFF_ENTRY-6-1136743</wkd:EntryID>
</wkd:TimeOff-Entry>
</wkd:TimeOff-Stack>
</AggregatedData>
Upvotes: 0