1
下面我有一個初始輸入XML:排除父及子節點時,某些節點符合條件
<?xml version="1.0" encoding="UTF-8"?>
<pi:Payroll_Extract_Employees xmlns:pi="urn:com.workday/picof">
<pi:Employee>
<pi:Summary>
<pi:Employee_ID>00000001</pi:Employee_ID>
</pi:Summary>
<pi:Additional_Information>
<pi:Worker_Type>NSW</pi:Worker_Type>
<pi:Strike_1>11-sept.-2017,2 Hours=9570</pi:Strike_1>
</pi:Additional_Information>
</pi:Employee>
<pi:Employee>
<pi:Summary>
<pi:Employee_ID>00000002</pi:Employee_ID>
</pi:Summary>
<pi:Additional_Information>
<pi:Worker_Type>SW</pi:Worker_Type>
<pi:Strike_1>22-sept.-2017,8 Hours=9570</pi:Strike_1>
</pi:Additional_Information>
</pi:Employee>
</pi:Payroll_Extract_Employees>
和XSLT:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
xmlns:pi="urn:com.workday/picof"
version="2.0">
<xsl:output indent="yes" method="xml"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<pi:Payroll_Extract_Employees>
<xsl:for-each select="//pi:Employee">
<pi:Employee>
<xsl:copy-of select="pi:Summary"/>
<xsl:apply-templates select="pi:Additional_Information/*"/>
</pi:Employee>
</xsl:for-each>
</pi:Payroll_Extract_Employees>
</xsl:template>
<xsl:template match="pi:Additional_Information/*">
<xsl:apply-templates select="ancestor::pi:Payroll_Extract_Employees">
<xsl:with-param name="UnpaidTO" select="current()"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="pi:Payroll_Extract_Employees">
<xsl:param name="UnpaidTO"/>
<pi:Time_Off>
<pi:Code_Name>Unpaid Time Off</pi:Code_Name>
<pi:Time_Off_Type><xsl:value-of select="substring-after($UnpaidTO,'=')"/></pi:Time_Off_Type>
<pi:Time_Off_Date><xsl:value-of select="substring-before($UnpaidTO,',')"/></pi:Time_Off_Date>
<pi:Quantity><xsl:value-of select="substring-before(substring-after($UnpaidTO,','),' ')"/></pi:Quantity>
<pi:Unit_of_Time><xsl:value-of select="substring-after(substring-before($UnpaidTO,'='),' ')"/></pi:Unit_of_Time>
</pi:Time_Off>
</xsl:template>
</xsl:stylesheet>
但問題是,我需要排除所有與工作人員類型相同SW並且僅對所有員工類型爲NSW的員工應用以上xslt代碼。我最終的代碼應該是什麼來實現我的預期結果?
<?xml version="1.0" encoding="UTF-8"?>
<pi:Payroll_Extract_Employees xmlns:pi="urn:com.workday/picof">
<pi:Employee>
<pi:Summary>
<pi:Employee_ID>00000001</pi:Employee_ID>
</pi:Summary>
<pi:Time_Off>
<pi:Code_Name>Unpaid Time Off</pi:Code_Name>
<pi:Time_Off_Type>9570</pi:Time_Off_Type>
<pi:Time_Off_Date>11-sept.-2017</pi:Time_Off_Date>
<pi:Quantity>2</pi:Quantity>
<pi:Unit_of_Time>Hours</pi:Unit_of_Time>
</pi:Time_Off>
</pi:Employee>
</pi:Payroll_Extract_Employees>
預先感謝您!