我将一个 XML 文件作为输入,其中包含员工数据和映射值,即工作族 ID 和工作族名称。因此,当员工具有匹配的 Job Family Id 时,我们将替换 Worker_Data 中的 Job Family 名称,并且 Worker_Data 中的其余元素相同。所以我使用了 Identity 匹配,然后调用了需要替换值的元素。但它给了我工作族名的空白。
我已经尝试使用下面的 XSLT 代码来创建地图并为 Job Family ID 匹配调用相同的代码。它只是给我空白而已。不清楚我错过了什么。如果你们中的任何人都可以给我一个关于出了什么问题的提示,这对我真的很有帮助。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:map="http://www.w3.org/2005/xpath-functions/map" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wd="urn:com.workday/bsvc" exclude-result-prefixes="xs" version="3.0">
<xsl:mode streamable="no" on-no-match="shallow-skip" use- accumulators="JobFamilyLookup CurrentLookupValue" />
<xsl:output method="xml" />
<xsl:accumulator name="CurrentLookupValue" as="xs:string" initial- value="''" streamable="no">
<xsl:accumulator-rule match="wd:JobFamilyID/text()" select="string()" />
</xsl:accumulator>
<xsl:accumulator name="JobFamilyLookup" as="map(xs:string,xs:string)" initial-value="map{}" streamable="no">
<xsl:accumulator-rule match="wd:JobFamilyName/text()" select="map:put($value, accumulator-
before('CurrentLookupValue'),string(.))" />
</xsl:accumulator>
<xsl:strip-space elements="*" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="wd:Job_Family_ID">
<xsl:copy>
<xsl:value-of select="accumulator-before('JobFamilyLookup') (
normalize-space( wd:Job_Family_ID ) )" />
</xsl:copy>
</xsl:template>
<xsl:template match="wd:JobFamilyGroupDetails">
</xsl:template>
</xsl:stylesheet>
输入:
<?xml version="1.0" encoding="UTF-8"?>
<wd:test xmlns:wd="urn:com.workday/bsvc">
<wd:Worker_Data>
<wd:EmpID>50001</wd:EmpID>
<wd:Job_Title>Global Talent Director</wd:Job_Title>
<wd:Job_Family_ID>TAL_TALENT_ACQUISITION</wd:Job_Family_ID>
</wd:Worker_Data>
<wd:Worker_Data>
<wd:EmpID>50000</wd:EmpID>
<wd:Job_Title>Executive Assistant</wd:Job_Title>
<wd:Job_Family_ID>ADMIN_EXECUTIVE_ASSISTANT</wd:Job_Family_ID>
</wd:Worker_Data>
<wd:JobFamilyGroupDetails>
<wd:JobFamilyDetails>
<wd:JobFamilyID>ADMIN_EXECUTIVE_ASSISTANT</wd:JobFamilyID>
<wd:JobFamilyName>ADMIN - Executive Assistant</wd:JobFamilyName>
</wd:JobFamilyDetails>
<wd:JobFamilyDetails>
<wd:JobFamilyID>TAL_TALENT_ACQUISITION</wd:JobFamilyID>
<wd:JobFamilyName>TAL - Talent Acquisition</wd:JobFamilyName>
</wd:JobFamilyDetails>
</wd:JobFamilyGroupDetails>
</wd:test>
预期输出:
<?xml version="1.0" encoding="UTF-8"?>
<wd:test xmlns:wd="urn:com.workday/bsvc">
<wd:Worker_Data>
<wd:EmpID>50001</wd:EmpID>
<wd:Job_Title>Global Talent Director</wd:Job_Title>
<wd:Job_Family_ID>TAL - Talent Acquisition</wd:Job_Family_ID>
</wd:Worker_Data>
<wd:Worker_Data>
<wd:EmpID>50000</wd:EmpID>
<wd:Job_Title>Executive Assistant</wd:Job_Title>
<wd:Job_Family_ID>ADMIN - Executive Assistant</wd:Job_Family_ID>
</wd:Worker_Data>
</wd:test>