Xml xslt将节点作为参数传递(访问)到函数

Xml xslt将节点作为参数传递(访问)到函数,xml,xslt,xpath,xslt-2.0,Xml,Xslt,Xpath,Xslt 2.0,我有一个节点,如: <ws:Earnings_Deductions> <ws:Operation>ADD</ws:Operation> <ws:Code_Name ws:PriorValue="">Personal allowance 1 (PG) %</ws:Code_Name> <ws:Code ws

我有一个节点,如:

    <ws:Earnings_Deductions>            
        <ws:Operation>ADD</ws:Operation>            
        <ws:Code_Name ws:PriorValue="">Personal allowance 1 (PG) %</ws:Code_Name>            
        <ws:Code ws:PriorValue="">10303252</ws:Code>
        <ws:Earning_or_Deduction ws:PriorValue="">E</ws:Earning_or_Deduction>
        <ws:Start_Date ws:PriorValue="">2017-06-10</ws:Start_Date>
        <ws:First_Day_No_Longer_Applies ws:PriorValue="">2017-06-21</ws:First_Day_No_Longer_Applies>            
        <ws:Amount ws:PriorValue="">47.43</ws:Amount>            
        <ws:Compensation_Effective_Date ws:PriorValue="">2017-06-10</ws:Compensation_Effective_Date>            
        <ws:Prorated_Amount ws:PriorValue="">47.43</ws:Prorated_Amount>            
        <ws:Frequency ws:PriorValue="">13</ws:Frequency>            
        <ws:Currency ws:PriorValue="">EUR</ws:Currency>            
    </ws:Earnings_Deductions>

添加
个人免税额1(PG)%
10303252
E
2017-06-10
2017-06-21            
47.43
2017-06-10            
47.43
13
欧元
我想通过这个考试

<xsl:copy-of select="this:getEffectiveDate(current(), '45wfd')/*" />  

到功能

<xsl:function name="this:getEffectiveDate" as="xs:string">
    <xsl:param name="code" as="element()"/>
    <xsl:param name="param" as="xs:string"/>
    <xsl:choose>
        <xsl:when test="ws:Earnings_Deductions[ws:Code = $param]/ws:Operation='REMOVE'">
            <xsl:value-of select="ws:Earnings_Deductions[ws:Code=$param]/ws:First_Day_No_Longer_Applies" />
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="ws:Earnings_Deductions[ws:Code=$param and ws:Operation !='NONE']/ws:Compensation_Effective_Date" />
        </xsl:otherwise>
    </xsl:choose>
</xsl:function>


问题是,我不知道如何在函数中访问此节点,xpath应该是什么样子。

您需要类似的东西

<xsl:when test="$code/ws:Earnings_Deductions[ws:Code = $xxxx]/ws:Operation='REMOVE'">


但是,我不知道$xxxx应该是什么-也许需要函数的第二个参数?

好吧,如果函数有一个名为
code
的参数,那么要在函数中引用该参数,您可以使用
$code
,就像您在函数体中的某个位置所看到的那样。但是,函数体中没有上下文节点,因此
ws:Earnings\u declarations
没有意义,如果这是另一个元素,则需要将其作为第二个参数传递。如果仍然存在问题,那么考虑将XML输入和XSLT的最小但完整的示例与所需结果一起显示。