XSLT 将日期和时间从 PST 转换为 U

问题描述 投票:0回答:1

在我的 XSLT 中,我输出时间戳:

<time_stamp>
    <xsl:value-of select="format-dateTime(wd:Last_Functionally_Updated, '[M01]/[D01]/[Y0001] [H01]:[m01]:[s01]')"/>
</time_stamp>

但是,源字段 是 PST,如何将其转换为 UTC? UTC 比 PST 早 8 小时,例如,太平洋标准时间下午 1 点是 UTC 晚上 9 点

下面是 XML

<?xml version='1.0' encoding='UTF-8'?>
<wd:Report_Data xmlns:wd="urn:com.workday.report/INT0194_Recruitics">
    <wd:Report_Entry>
        <wd:Job_Requisition_group>
            <wd:Is_Evergreen>0</wd:Is_Evergreen>
        </wd:Job_Requisition_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2023-06-26T12:50:11.949-07:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Review">
                <wd:ID wd:type="WID">31350d72f899430fb446b410c1e368cd</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">REVIEW</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2023-06-26T12:50:11.949-07:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Rejected">
                <wd:ID wd:type="WID">9a35fa5882c24620a777de1dbcf34d3c</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">REJECTED</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:candidate>C-0000704156</wd:candidate>
        <wd:Requisition_ID>R-0000051703</wd:Requisition_ID>
    </wd:Report_Entry>
    <wd:Report_Entry>
        <wd:Job_Requisition_group>
            <wd:Is_Evergreen>0</wd:Is_Evergreen>
        </wd:Job_Requisition_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-02-29T13:26:32.874-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Review">
                <wd:ID wd:type="WID">31350d72f899430fb446b410c1e368cd</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">REVIEW</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-02-29T13:26:32.874-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Rejected">
                <wd:ID wd:type="WID">9a35fa5882c24620a777de1dbcf34d3c</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">REJECTED</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:candidate>C-0000704156</wd:candidate>
        <wd:Requisition_ID>R-0000076253</wd:Requisition_ID>
    </wd:Report_Entry>
    <wd:Report_Entry>
        <wd:Job_Requisition_group>
            <wd:Is_Evergreen>0</wd:Is_Evergreen>
        </wd:Job_Requisition_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-11T09:41:35.698-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Review">
                <wd:ID wd:type="WID">31350d72f899430fb446b410c1e368cd</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">REVIEW</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-11T09:41:54.044-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Review">
                <wd:ID wd:type="WID">31350d72f899430fb446b410c1e368cd</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">REVIEW</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-11T09:42:50.630-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Screen">
                <wd:ID wd:type="WID">2d0e4a68825d4d2a8c507af7542d3f15</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">SCREEN</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-11T09:43:19.091-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Screen">
                <wd:ID wd:type="WID">2d0e4a68825d4d2a8c507af7542d3f15</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">SCREEN</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-11T09:43:39.613-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Assessment">
                <wd:ID wd:type="WID">bb01594c858710000e4d46d2b7220034</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">ASSESSMENT</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-11T09:45:00.608-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Interview">
                <wd:ID wd:type="WID">3317e4265cf94b91873b7015881a0e9c</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">INTERVIEW</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-11T09:52:33.923-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Offer (Employment Agreement)">
                <wd:ID wd:type="WID">1d57fbe8504d100015945d2b2704006a</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">EMPLOYMENT_AGREEMENT</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-11T09:56:25.485-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Background Check">
                <wd:ID wd:type="WID">be56571f9f6f45ca82871c8bec853f5e</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">BACKGROUND</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-11T09:56:25.485-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Ready for Hire">
                <wd:ID wd:type="WID">edd55803e2ec49c3a6eb01daadfc9bf9</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">HIRED</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:candidate>C-0001721053</wd:candidate>
        <wd:Requisition_ID>R-0000106433</wd:Requisition_ID>
    </wd:Report_Entry>
    <wd:Report_Entry>
        <wd:Job_Requisition_group>
            <wd:Is_Evergreen>1</wd:Is_Evergreen>
        </wd:Job_Requisition_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-10T12:15:30.187-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Review">
                <wd:ID wd:type="WID">31350d72f899430fb446b410c1e368cd</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">REVIEW</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-10T12:15:49.308-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Interview">
                <wd:ID wd:type="WID">3317e4265cf94b91873b7015881a0e9c</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">INTERVIEW</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-10T12:15:49.308-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Offer">
                <wd:ID wd:type="WID">868a8156682541f2aadc2fe90268b75f</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">OFFER</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:candidate>C-0001721051</wd:candidate>
        <wd:Requisition_ID>R-0000098017</wd:Requisition_ID>
    </wd:Report_Entry>
    <wd:Report_Entry>
        <wd:Job_Requisition_group>
            <wd:Is_Evergreen>1</wd:Is_Evergreen>
        </wd:Job_Requisition_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-12T11:52:49.381-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Review">
                <wd:ID wd:type="WID">31350d72f899430fb446b410c1e368cd</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">REVIEW</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-12T11:52:49.381-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Interview">
                <wd:ID wd:type="WID">3317e4265cf94b91873b7015881a0e9c</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">INTERVIEW</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:candidate>C-0001721060</wd:candidate>
        <wd:Requisition_ID>R-0000103689</wd:Requisition_ID>
    </wd:Report_Entry>
    <wd:Report_Entry>
        <wd:Job_Requisition_group>
            <wd:Is_Evergreen>1</wd:Is_Evergreen>
        </wd:Job_Requisition_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-12T11:52:49.381-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Review">
                <wd:ID wd:type="WID">31350d72f899430fb446b410c1e368cd</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">REVIEW</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-12T11:52:49.381-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Interview">
                <wd:ID wd:type="WID">3317e4265cf94b91873b7015881a0e9c</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">INTERVIEW</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:candidate>C-0001721060</wd:candidate>
        <wd:Requisition_ID>R-0000103689</wd:Requisition_ID>
    </wd:Report_Entry>
    <wd:Report_Entry>
        <wd:Job_Requisition_group>
            <wd:Is_Evergreen>1</wd:Is_Evergreen>
        </wd:Job_Requisition_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-16T09:52:14.424-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Review">
                <wd:ID wd:type="WID">31350d72f899430fb446b410c1e368cd</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">REVIEW</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-16T09:52:14.424-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Rejected">
                <wd:ID wd:type="WID">9a35fa5882c24620a777de1dbcf34d3c</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">REJECTED</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:candidate>C-0001721062</wd:candidate>
        <wd:Requisition_ID>R-0000086280</wd:Requisition_ID>
    </wd:Report_Entry>
    <wd:Report_Entry>
        <wd:Job_Requisition_group>
            <wd:Is_Evergreen>1</wd:Is_Evergreen>
        </wd:Job_Requisition_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-17T22:12:11.799-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Review">
                <wd:ID wd:type="WID">31350d72f899430fb446b410c1e368cd</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">REVIEW</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:candidate>C-0001721063</wd:candidate>
        <wd:Requisition_ID>R-0000085728</wd:Requisition_ID>
    </wd:Report_Entry>
</wd:Report_Data>

下面是我正在使用的 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:wd="urn:com.workday.report/INT0194_Recruitics"
    exclude-result-prefixes="wd">
    
    <xsl:output method="text" omit-xml-declaration="no"/>
    <xsl:variable name="RECORD-DELIMITER">
        <xsl:text>&#xd;&#xa;</xsl:text>
    </xsl:variable>
    <xsl:param name="Dilim">","</xsl:param>
    <xsl:param name="Quote">"</xsl:param>
    <xsl:param name="Comma">,</xsl:param>
    <xsl:variable name="FIELD-DELIMITER">
        <xsl:value-of select="$Dilim"/>
    </xsl:variable>
    <xsl:variable name="STARTING-QUOTE">
        <xsl:value-of select="$Quote"/>
    </xsl:variable>
    
    <xsl:template match="wd:Report_Data">
        <Header>
            <HeaderItem1>"time_stamp"</HeaderItem1>
            <xsl:value-of select="$Comma"/>
            <HeaderItem2>"event"</HeaderItem2>
            <xsl:value-of select="$Comma"/>
            <HeaderItem3>"applyflow_id"</HeaderItem3>
            <xsl:value-of select="$Comma"/>
            <HeaderItem4>"job_id"</HeaderItem4>
        </Header>
        <xsl:value-of select="$RECORD-DELIMITER"/>

        <xsl:for-each-group select="wd:Report_Entry[wd:Job_Requisition_group/wd:Is_Evergreen = 0]/wd:Job_Application_Process_Statuses_group" composite="yes" group-by="../wd:candidate, ../wd:Requisition_ID, ../wd:Job_application_ID, wd:Stage/wd:ID">
            <xsl:for-each select="(current-group() => sort((), function($j) { $j/wd:Last_Functionally_Updated }))[last()]">
                <xsl:value-of select="$STARTING-QUOTE"/>
                    <time_stamp>
                        <xsl:value-of select="format-dateTime(wd:Last_Functionally_Updated, '[M01]/[D01]/[Y0001] [H01]:[m01]:[s01]')"/>
                    </time_stamp>
                <xsl:value-of select="$FIELD-DELIMITER"/>
                     <event>
                         <xsl:value-of select="wd:Stage/@wd:Descriptor"/>
                     </event>
                <xsl:value-of select="$FIELD-DELIMITER"/>
                    <applyflow_id>
                        <xsl:value-of select="../wd:candidate"/>
                    </applyflow_id>  
                <xsl:value-of select="$FIELD-DELIMITER"/>
                    <job_id>
                        <xsl:value-of select="../wd:Requisition_ID"/>
                    </job_id>
                <xsl:value-of select="$STARTING-QUOTE"/>
                <xsl:value-of select="$RECORD-DELIMITER"/>
            </xsl:for-each>
        </xsl:for-each-group>
    </xsl:template>
</xsl:stylesheet>

我几乎使用 使其工作,但它实际上不起作用,因为在 XML 中,某些时间值具有 -07:00 (例如,2023-06-26T12:50:11.949-07:00)并且有些有 -08:00 (例如, 2024-02-29T13:26:32.874-08:00) 所以 PT1H 仅在 -07:00 时有效。也许我应该尝试使用子字符串来删除“-07:00”部分,但不知道如何操作。预先感谢。

xslt xslt-1.0 xslt-2.0 xslt-3.0 xslt-grouping
1个回答
0
投票

要动态处理 XSLT 3.0 中从 PST 到 UTC 的转换,特别是当输入 XML 时间戳具有不同的偏移量(如 -07:00 或 -08:00)时,您可以组合使用 adjustment-dateTime-to-timezone()提取的时区与提供的日期时间的偏移量。

关键步骤是:

使用 substring() 或analyze-string() 从 wd:Last_Functionally_Updated 值中动态提取时区偏移量。

使用 adjustment-dateTime-to-timezone() 将时间戳标准化为 UTC。

以下是实施方法:

更新了 XSLT 代码

<xsl:template match="wd:Report_Data">
    <xsl:for-each select="wd:Report_Entry/wd:Job_Application_Process_Statuses_group">
        <xsl:variable name="raw-dateTime" select="wd:Last_Functionally_Updated" />
        
        <!-- Adjust the dateTime to UTC -->
        <xsl:variable name="utc-dateTime" 
                      select="adjust-dateTime-to-timezone(xs:dateTime($raw-dateTime), xs:dayTimeDuration('PT0H'))" />
        
        <time_stamp>
            <!-- Format the adjusted UTC dateTime -->
            <xsl:value-of select="format-dateTime($utc-dateTime, '[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01]Z')" />
        </time_stamp>
    </xsl:for-each>
</xsl:template>
© www.soinside.com 2019 - 2024. All rights reserved.