xslt-2.0 - 如何从 xslt 中的多个字段中查找和格式化最新日期
问题描述
我已经搜索了有关我的特定场景的信息,但没有找到我要查找的内容。如果我错过了什么,请提前道歉。
我正在寻找有关从三个字段中查找和格式化最新日期的语法帮助。我能够草率地找到最新日期并能够格式化日期,但是将语法放在一起并让它正常工作让我望而却步。我想向这个论坛询问一个干净的代码来执行以下操作:使用 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="
">
<xsl:variable name="linefeed" select="'
'"/>
<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>
解决方案
在 Martin、同事和我自己的反复试验的帮助下,我找到了问题的完整答案。这是我最终使用的,它工作得很好。
<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>
推荐阅读
- udp - 通过 UDP 从 ftp 下载文件但未呈现路径
- reactjs - 存储在 XSTATE 中以便跨组件访问?
- react-native - 使用滚动 Y 插值反应原生视图不透明度
- java - 如何在 Selenium JAVA 和 TestNG 中使用 log4j2x 在日志文件中打印“系统生成的日志”?
- javascript - 在哈希表上添加元素
- typescript - 是否可以有条件回调参数类型?(例如,如果 arg1:字符串,则 arg0:null)
- sql-server - 当数字数据存储在varchar列中时,如何解决查询记录时的性能差异?
- django - 我得到了这个,错误:那个端口已经在使用中。对于姜戈。它要求我输入密码,但我不记得了
- c++ - 稀疏矩阵与密集矩阵乘法 C++ Tensorflow
- sql-server-2008 - 使用 ROW_Number() 函数更新列。但它失败了。任何人都可以提出解决方案吗?