我試圖將一個模板的值傳遞給另一個模板。儘管我在這個論壇中發現了一些例子,但我無法做到。將值從一個模板傳遞到另一個模板
下面是我的XML:
<pi:PayGroup xmlns:pi="urn:com.sample/file">
<pi:Header>
<pi:Version>17</pi:Version>
<pi:Payroll_Company_Name>ABCD</pi:Payroll_Company_Name>
<pi:Pay_Group_ID>0307</pi:Pay_Group_ID>
</pi:Header>
<pi:Employee>
<pi:Summary>
<pi:Employee_ID>12345678</pi:Employee_ID>
<pi:Name>Test Employee</pi:Name>
</pi:Summary>
<pi:Position>
<pi:Business_Title>Lead Learning Specialist</pi:Business_Title>
<pi:Worker_Type>P</pi:Worker_Type>
<pi:Position_Time_Type>Full_time</pi:Position_Time_Type>
<pi:Compensation_Effective_Date>2017-07-01</pi:Compensation_Effective_Date>
<pi:Base_Pay_Currency>EUR</pi:Base_Pay_Currency>
<pi:Base_Pay_Frequency>4-Weekly</pi:Base_Pay_Frequency>
<pi:Organization_One>0307_3075999496</pi:Organization_One>
<pi:Organization_Two>0307</pi:Organization_Two>
<pi:Supervisor_ID>00295975</pi:Supervisor_ID>
<pi:Supervisor_Name>Simba Sang (98765432)</pi:Supervisor_Name>
</pi:Position>
<pi:Earnings>
<pi:Start_Date>2017-02-06</pi:Start_Date>
<pi:Currency>EUR</pi:Currency>
</pi:Earnings>
</pi:Employee>
</pi:PayGroup>
下面是一個在使用很長一段時間的XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:pi="urn:com.workday/picof"
version="2.0">
<xsl:output omit-xml-declaration="yes" method="xml"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- 0... 123456 -->
<xsl:template match="pi:Employee_ID">
<pi:Employee_ID>
<xsl:value-of select="substring(.,3)"/>
</pi:Employee_ID>
</xsl:template>
<xsl:template match="pi:Supervisor_ID">
<pi:Supervisor_ID>
<xsl:value-of select="substring(.,3)"/>
</pi:Supervisor_ID>
</xsl:template>
<xsl:template match="pi:Supervisor_Name">
<pi:Supervisor_Name>
<xsl:value-of select="normalize-space(substring-before(.,'('))"/>
</pi:Supervisor_Name>
</xsl:template>
<xsl:template match="pi:Organization_One">
<pi:Organization_One>
<xsl:value-of select="if(contains(.,'_'))
then(normalize-space(substring-after(.,'_')))
else(.)"/>
</pi:Organization_One>
</xsl:template>
</xsl:stylesheet>
問這裏是/ PI:位置/ PI:Compensation_Effective_Date值應也可以通過/ pi下:Earnings_Deductions/pi:Start_Date標記
pi:Start_Date應該與pi:Compensation_Effective_Date具有相同的值。
所以我修改了XSLT爲包括兩個多個模板匹配一個用於PI:Compensation_Effective_Date和另一個用於/ PI:START_DATE,如下所示:
<xsl:template match="/pi:Compensation_Effective_Date">
<xsl:param name="test"/>
<xsl:apply-templates>
<xsl:with-param name="test" select="."/>
</xsl:apply-templates>
<pi:Compensation_Effective_Date><xsl:value-of select="$test"/></pi:Compensation_Effective_Date>
</xsl:template>
<xsl:template match="pi:Start_Date">
<xsl:param name="test"/>
<pi:Start_Date><xsl:value-of select="$test"/></pi:Start_Date>
</xsl:template>
已在PI一個PARAM值:compensation_effective_date模板並通過該參數爲pi:start_date模板。但是pi:Start_Date總是空白;我怎樣才能在start_date中獲得compensation_effective_Date值?
預期輸出:
<pi:Position>
<pi:Business_Title>...</pi:Business_Title>
<pi:Worker_Type>..</pi:Worker_Type>
<pi:Position_Time_Type>..</pi:Position_Time_Type>
<pi:Compensation_Effective_Date>2017-07-01</pi:Compensation_Effective_Date>
<pi:Base_Pay_Currency>..</pi:Base_Pay_Currency>
<pi:Base_Pay_Frequency>...</pi:Base_Pay_Frequency>
<pi:Organization_One>....</pi:Organization_One>
<pi:Organization_Two>....</pi:Organization_Two>
<pi:Supervisor_ID>....</pi:Supervisor_ID>
<pi:Supervisor_Name>.....</pi:Supervisor_Name>
</pi:Position>
<pi:Earnings>
<pi:Start_Date>2017-07-01</pi:Start_Date>
<pi:Currency>...</pi:Currency>
</pi:Earnings>
我建議您將示例降低到演示問題所需的最小值 - 請參閱:[mcve]。 –