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

时间:2017-06-23 13:36:52

标签: 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: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>

我想通过这个

<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应该如何。

1 个答案:

答案 0 :(得分:0)

你需要像

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

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