我试图将一个模板的值传递给另一个模板。尽管我在这个论坛中发现了一些例子,但我无法做到。将值从一个模板传递到另一个模板
下面是我的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]。 –