Search code examples
xmlxsltxpathxslt-2.0

xslt passing (accessing) node as a parameter to a function


I have a node like:

    <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>

I would like to pass this

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

to the function

<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>

The problem is than I dont know how to access this node in the function, how xpath should look like.


Solution

  • You need something like

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

    However, I have no idea what $xxxx should be - perhaps a second parameter to the function is needed?