You need to enable JavaScript to run this app. XSLT实现同员工相同Effective_Date事件序列递增求助
优惠活动
大模型
产品
解决方案
定价
更多

XSLT实现同员工相同Effective_Date事件序列递增求助

修正后的XSLT代码

核心修改点是序列字段的计算逻辑:统计当前员工下,排在当前事件前、且生效日期相同的事件总数,加1即可得到正确的递增序列,同时调整了日期输出逻辑匹配你期望的格式:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs"
    xmlns:wd="urn:com.workday.report/ERP-HCM-CR_ASSIGNMENTS_REPORT_V4" version="2.0">
    <xsl:output method="text"/>
    <xsl:variable name="linefeed" select="'&#xD;&#xA;'"/>
    <xsl:variable name="pipe" select="'|'"/>
    <xsl:variable name="EffectiveStartDate" select="'01-01-1951'"/>
    <xsl:variable name="EffectiveEndDate" select="'4712-12-31'"/>

    <xsl:param name="quote">"</xsl:param>
    <xsl:template match="/">
        <!--  File Header Record  -->
        <xsl:call-template name="Write-Header-Record0"/>

        <!--  File Detail Layout  -->
        <xsl:for-each select="wd:Report_Data/wd:Report_Entry">
            <xsl:for-each select="wd:Caregiver_Events_group">
                <xsl:call-template name="Write-Detail-Record"/>
            </xsl:for-each>
        </xsl:for-each>
    </xsl:template>

    <xsl:template name="Write-Header-Record0">
        <xsl:text>Unique ID|Assignment Number|Effective Date|Sequence</xsl:text>
        <xsl:value-of select="$linefeed"/>
    </xsl:template>

    <xsl:template name="Write-Detail-Record">
        <xsl:value-of select="../wd:Worker_group/wd:UNIQUE_IDENTIFIER"/>
        <xsl:value-of select="$pipe"/>
        <xsl:value-of select="wd:ASSIGNMENT_NUMBER"/>
        <xsl:value-of select="$pipe"/>
        <!-- 直接输出原始生效日期,匹配期望输出格式,如需格式化可调整此处 -->
        <xsl:value-of select="wd:EFFECTIVE_DATE"/>
        <xsl:value-of select="$pipe"/>
        <!-- 核心序列计算:统计同员工下当前节点前相同生效日期的事件数+1 -->
        <xsl:value-of select="count(preceding-sibling::wd:Caregiver_Events_group[wd:EFFECTIVE_DATE = current()/wd:EFFECTIVE_DATE]) + 1"/>
        <xsl:value-of select="$linefeed"/>
    </xsl:template>
</xsl:stylesheet>

输出验证

上述代码执行后得到的结果和你提供的期望输出完全一致:

Unique ID|Assignment Number|Effective Date|Sequence
2168636|2168636-03012008E01|2008-03-01-08:00|1
2168636|2168636-03012008E01|2019-12-01-08:00|1
2168636|2168636-03012008E01|2019-12-01-08:00|2
2188946|2188946-04272015E01|2015-04-27-07:00|1
2188946|2188946-04272015E01|2019-12-01-08:00|1
2188946|2188946-04272015E01|2019-12-01-08:00|2

内容的提问来源于stack exchange,提问作者abishek rao

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.17 00:57:03