如何在xslt中的多个字段中查找和格式化最新日期

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

我已经搜索了我的具体情况的信息,但没有找到我正在寻找的东西。如果我错过了某些东西,请在前面道歉。

我正在寻找有关语法的帮助,以便从一组三个字段中查找和格式化最新日期。我能够轻松地找到最新的日期并且能够格式化日期,但是将语法全部放在一起并使其正常工作是我的目标。我想要在这个论坛上找到一个干净的代码来执行以下操作:使用xslt 2.0查找,返回并格式化这三个字段中的最新日期 - 格式为'20070724': - ws:Pay_Rate_Type_Change_Effective_Date -ws:Time_Type_Change_Effective_Date -ws:Job_Code_Change_Effective_Date

任何帮助非常感谢!

谢谢,詹恩

<?xml version="1.0" encoding="UTF-8"?>
<ws:Worker_Sync xmlns:ws="urn:com.workday/workersync"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<ws:Worker>
    <ws:Summary>
        <ws:Employee_ID>123456</ws:Employee_ID>
    </ws:Summary>
    <ws:Additional_Information>
        <ws:Time_Type_Change_Effective_Date>2005-05-24</ws:Time_Type_Change_Effective_Date>
        <ws:Pay_Rate_Type_Change_Effective_Date>2006-06-24</ws:Pay_Rate_Type_Change_Effective_Date>
        <ws:Job_Code_Change_Effective_Date>2007-07-24</ws:Job_Code_Change_Effective_Date>
    </ws:Additional_Information>
</ws:Worker>    
</ws:Worker_Sync>


<?xml version='1.0'?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ws="urn:com.workday/workersync" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xtt="urn:com.workday/xtt" xmlns:etv="urn:com.workday/etv"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wd="urn:com.workday.report">
<!-- set encoding of output - need to create a properly formatted XML document that Workday's internal document transformation engine will convert to a text file -->
<xsl:output method="xml" encoding="UTF-8"/>

<xsl:template match="/">
    <File xtt:separator="&#xd;&#xa;">
        <xsl:variable name="linefeed" select="'&#xa;'"/>
        <xsl:variable name="currentDate">
            <xsl:value-of select="format-date(current-date(), '[Y0001][M01][D01]')"/>
        </xsl:variable>
        <xsl:apply-templates select="ws:Worker_Sync/ws:Worker"/>
    </File>
</xsl:template>
<xsl:template match="/ws:Worker_Sync/ws:Worker">
    <Record xtt:separator="|">
        <EmployeeAssignedID>
            <xsl:value-of select="ws:Summary/ws:Employee_ID"/>
        </EmployeeAssignedID>            
        <RecordChangeEffectiveDate/>         <!--FT/PT, Hrly/Slry, Jobcode change effdt-->
        <!--Here is where I have to add code to say:
        Find, return and format the latest date out of these three fields in xml file - format of '20070724' :
        -ws:Pay_Rate_Type_Change_Effective_Date
        -ws:Time_Type_Change_Effective_Date
        -ws:Job_Code_Change_Effective_Date    -->   
    </Record>
</xsl:template>
</xsl:stylesheet>
xslt-2.0
1个回答
0
投票

在马丁,同事和我自己的反复试验的帮助下,我找到了问题的完整答案。这是我最终使用的,它完美地运作。

<RecordChangeEffectiveDate>            
 <xsl:value-of select="format-date(max((xs:date(ws:Additional_Information/ws:Pay_Rate_Type_Change_Effective_Date), xs:date(ws:Additional_Information/ws:Time_Type_Change_Effective_Date), xs:date(ws:Additional_Information/ws:Job_Code_Change_Effective_Date) )), '[Y0001][M01][D01]') "/>
</RecordChangeEffectiveDate>
© www.soinside.com 2019 - 2024. All rights reserved.